def getalerts(self): """ Get all the alerts """ a = alerts.get_alerts() return json.dumps(a)
def run(): args = get_args_from_cli() alerts = get_alerts(args.config[0]) while True: start_time = time.time() seen_alert_targets = set() for alert in alerts: target = alert.target try: records = get_records( GRAPHITE_URL, requests.get, GraphiteDataRecord, target, from_=alert.from_, ) except requests.exceptions.RequestException as exc: notification = 'Could not get target: {}'.format(target) print notification notifier_proxy.notify( target, Level.CRITICAL, notification, notification, ) records = [] for record in records: name = alert.name target = record.target if (name, target) not in seen_alert_targets: print 'Checking', (name, target) update_notifiers(alert, record) seen_alert_targets.add((name, target)) else: print 'Seen', (name, target) time_diff = time.time() - start_time sleep_for = 60 - time_diff if sleep_for > 0: sleep_for = 60 - time_diff print 'Sleeping for {0} seconds at'.format( sleep_for), datetime.datetime.utcnow() time.sleep(60 - time_diff)
def run(): args = get_args_from_cli() alerts = get_alerts(args.config[0]) while True: start_time = time.time() seen_alert_targets = set() for alert in alerts: target = alert.target try: records = get_records( GRAPHITE_URL, requests.get, GraphiteDataRecord, target, from_=alert.from_, ) except requests.exceptions.RequestException as exc: notification = 'Could not get target: {}'.format(target) print notification notifier_proxy.notify( target, Level.CRITICAL, notification, notification, ) records = [] for record in records: name = alert.name target = record.target if (name, target) not in seen_alert_targets: print 'Checking', (name, target) update_notifiers(alert, record) seen_alert_targets.add((name, target)) else: print 'Seen', (name, target) time_diff = time.time() - start_time sleep_for = 60 - time_diff if sleep_for > 0: sleep_for = 60 - time_diff print 'Sleeping for {0} seconds at'.format(sleep_for), datetime.datetime.utcnow() time.sleep(60 - time_diff)
def load_alerts(location): alerts = get_alerts(location) return alerts