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
target/
config.yml

View File

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

View File

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