Creating agent that schedules the monitoring task.

This commit is contained in:
Mitsuo Takaki
2016-04-28 01:51:59 -07:00
parent 0a69e48905
commit 2f3106da60
5 changed files with 36 additions and 2 deletions

5
README.md Normal file
View File

@@ -0,0 +1,5 @@
# Status
cachet-url-monitor
========================
Python plugin for [cachet](cachethq.io) that monitors an URL, verifying it's response status and latency.

View File

@@ -12,6 +12,8 @@ class Configuration(object):
"""
def __init__(self, config_file):
#TODO(mtakaki|2016-04-26): Needs validation if the config is correct.
#TODO(mtakaki|2016-04-28): Accept overriding settings using environment
# variables so we have a more docker-friendly approach.
self.config_file = config_file
self.data = load(file(self.config_file, 'r'))
self.expectations = [Expectaction.create(expectation) for expectation

View File

@@ -1,10 +1,33 @@
#!/usr/bin/env python
from threading import Timer
import configuration
from configuration import Configuration
import logging
import schedule
import sys
import time
class Agent(object):
def __init__(self, configuration):
self.configuration = configuration
def execute(self):
self.configuration.evaluate()
self.configuration.push_status_and_metrics()
def start(self):
schedule.every(self.configuration.data['frequency']).seconds.do(self.execute)
if __name__ == "__main__":
if len(sys.argv) <= 1:
logging.fatal('Missing configuration file argument')
sys.exit(1)
configuration = Configuration(sys.argv[1])
agent = Agent(configuration)
agent.start()
logging.info('Starting monitor agent...')
while True:
schedule.run_pending()
time.sleep(configuration.data['frequency'])

View File

@@ -2,3 +2,4 @@ PyYAML==3.11
ipython==4.2.0
pudb==2016.1
requests==2.9.1
schedule==0.3.2

3
requirements.txt Normal file
View File

@@ -0,0 +1,3 @@
PyYAML==3.11
requests==2.9.1
schedule==0.3.2