initial commit poc

This commit is contained in:
IamTheFij 2018-02-14 15:37:15 -08:00
parent acbf8fa6ef
commit 2b5856ee30
5 changed files with 65 additions and 0 deletions

6
Makefile Normal file
View File

@ -0,0 +1,6 @@
env:
virtualenv -p python3 env
./env/bin/pip install -r requirements.txt
run: env
./env/bin/python -m minitor.main

0
minitor/__init__.py Normal file
View File

39
minitor/main.py Normal file
View File

@ -0,0 +1,39 @@
from subprocess import CalledProcessError
from subprocess import check_call
import yamlenv
# TODO: validate on start
def get_config(path):
"""Loads config from a YAML file with env interpolation"""
with open(path, 'r') as yaml:
contents = yaml.read()
return yamlenv.load(contents)
def check_monitor(monitor):
cmd = monitor.get('command', [])
if cmd:
check_call(cmd, shell=isinstance(cmd, str))
def alert_for_monitor(monitor, alerts):
for alert_name in monitor.get('alerts', []):
cmd = alerts.get(alert_name, {}).get('command', [])
if cmd:
check_call(cmd, shell=isinstance(cmd, str))
def main():
# TODO: get config file off command line
config = get_config('./sample-config.yml')
alerts = config.get('alerts', {})
for monitor in config.get('monitors', []):
try:
check_monitor(monitor)
except CalledProcessError:
alert_for_monitor(monitor, alerts)
if __name__ == '__main__':
main()

1
requirements.txt Normal file
View File

@ -0,0 +1 @@
yamlenv

19
sample-config.yml Normal file
View File

@ -0,0 +1,19 @@
monitors:
- name: View
command: [ 'curl', 'https://localhost:5000' ]
# environment:
# PATH: ${PATH}
alerts: [ email, sms ]
# other settings from other health check apps like interval and back off
alerts:
email:
command: echo 'Send an email'
sms:
command: echo 'Send an SMS'
federation:
- location: https://host1.com
client_key: keyfromhost1
server_key: keyhost1uses
alerts: [ sms ]