Add run loop and interval

This commit is contained in:
IamTheFij 2018-02-14 17:54:42 -08:00
parent 2b5856ee30
commit 636ad103a3
3 changed files with 12 additions and 6 deletions

1
.gitignore vendored
View File

@ -58,3 +58,4 @@ docs/_build/
# PyBuilder # PyBuilder
target/ target/
config.yml

View File

@ -1,5 +1,6 @@
from subprocess import CalledProcessError from subprocess import CalledProcessError
from subprocess import check_call from subprocess import check_call
from time import sleep
import yamlenv import yamlenv
@ -27,13 +28,15 @@ def alert_for_monitor(monitor, alerts):
def main(): def main():
# TODO: get config file off command line # TODO: get config file off command line
config = get_config('./sample-config.yml') config = get_config('config.yml')
alerts = config.get('alerts', {}) alerts = config.get('alerts', {})
for monitor in config.get('monitors', []): while True:
try: for monitor in config.get('monitors', []):
check_monitor(monitor) try:
except CalledProcessError: check_monitor(monitor)
alert_for_monitor(monitor, alerts) except CalledProcessError:
alert_for_monitor(monitor, alerts)
sleep(config.get('interval', 1))
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -1,3 +1,5 @@
interval: 5
monitors: monitors:
- name: View - name: View
command: [ 'curl', 'https://localhost:5000' ] command: [ 'curl', 'https://localhost:5000' ]