예제 #1
0
파일: server.py 프로젝트: yonivy/WCSS
	def getalerts(self):

		""" Get all the alerts """

		a = alerts.get_alerts()
		
		return json.dumps(a)
예제 #2
0
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)
예제 #3
0
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)
예제 #4
0
def load_alerts(location):
    alerts = get_alerts(location)
    return alerts