mirror of
https://github.com/mtan93/cachet-url-monitor.git
synced 2026-03-08 05:31:58 +00:00
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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user