Fixing push status that has been broken since moving to a client (#80)

* Fixing push status that has been broken since moving to a client

* Adding unit test to cover the bug
This commit is contained in:
mtakaki
2020-01-28 01:42:49 -08:00
committed by GitHub
parent 79a9a7f8d6
commit df2d094dc6
6 changed files with 99 additions and 66 deletions

View File

@@ -7,6 +7,7 @@ import time
import schedule
from yaml import load, SafeLoader
from cachet_url_monitor.client import CachetClient
from cachet_url_monitor.configuration import Configuration
cachet_mandatory_fields = ['api_url', 'token']
@@ -105,14 +106,14 @@ def build_agent(configuration, logger):
def validate_config():
if 'endpoints' not in config_file.keys():
if 'endpoints' not in config_data.keys():
fatal_error('Endpoints is a mandatory field')
if config_file['endpoints'] is None:
if config_data['endpoints'] is None:
fatal_error('Endpoints array can not be empty')
for key in cachet_mandatory_fields:
if key not in config_file['cachet']:
if key not in config_data['cachet']:
fatal_error('Missing cachet mandatory fields')
@@ -132,14 +133,16 @@ if __name__ == "__main__":
sys.exit(1)
try:
config_file = load(open(sys.argv[1], 'r'), SafeLoader)
config_data = load(open(sys.argv[1], 'r'), SafeLoader)
except FileNotFoundError:
logging.getLogger('cachet_url_monitor.scheduler').fatal(f'File not found: {sys.argv[1]}')
sys.exit(1)
validate_config()
for endpoint_index in range(len(config_file['endpoints'])):
configuration = Configuration(config_file, endpoint_index)
for endpoint_index in range(len(config_data['endpoints'])):
token = os.environ.get('CACHET_TOKEN') or config_data['cachet']['token']
api_url = os.environ.get('CACHET_API_URL') or config_data['cachet']['api_url']
configuration = Configuration(config_data, endpoint_index, CachetClient(api_url, token), token)
NewThread(Scheduler(configuration,
build_agent(configuration, logging.getLogger('cachet_url_monitor.scheduler')))).start()