示例#1
0
 def __init__(self, configuration):
     self.configuration = configuration
     self.alert_reporter = MailAlertReporter(email_from=self.configuration.email_from,
                                             smtp_server=self.configuration.smtp_server,
                                             smtp_port=self.configuration.smtp_port,
                                             email_username=self.configuration.smtp_username,
                                             email_password=self.configuration.smtp_password)
示例#2
0
class AlertCheckerCoordinator:
    """Entry point to the alert checking module."""

    def __init__(self, configuration):
        self.configuration = configuration
        self.alert_reporter = MailAlertReporter(email_from=self.configuration.email_from,
                                                smtp_server=self.configuration.smtp_server,
                                                smtp_port=self.configuration.smtp_port,
                                                email_username=self.configuration.smtp_username,
                                                email_password=self.configuration.smtp_password)

    def check(self):
        """Check if there is something to report"""
        # Get all the dashboards to use for checking
        scanner = DashboardScanner(self.configuration.grafana_url, self.configuration.grafana_token)
        dashboard_data_list = scanner.obtain_dashboards()
        print dashboard_data_list
        for d in dashboard_data_list:
            try:
                print "Dashboard: " + d['title']
                # {u'slug': u'typrod-storage', u'tags': [], u'isStarred': False, u'id': 4, u'title': u'TyProd Storage'}
                dashboard = Dashboard(self.configuration.grafana_url, self.configuration.ddb_url, self.configuration.grafana_token, d['title'], d['uri'], d['tags'])
                alert_checkers = dashboard.obtain_alert_checkers()

                # For each set of alert checkers, evaluate them
                for alert_checker in alert_checkers:
                    alert_checker.check()
                    reported_alerts = alert_checker.calculate_reported_alerts()
                    # for each set of reported alerts, report whatever is best
                    self.alert_reporter.report(reported_alerts)
            except NotMonitoreableDashboard as e:
                print "Dashboard {title} cannot be monitored. Reason: {reason}".format(title=d['title'], reason=e.message)
                continue
示例#3
0
class AlertCheckerCoordinator:
    """Entry point to the alert checking module."""

    def __init__(self, configuration):
        self.configuration = configuration
        self.alert_reporter = MailAlertReporter(email_from=self.configuration.email_from,
                                                smtp_server=self.configuration.smtp_server,
                                                smtp_port=self.configuration.smtp_port,
                                                email_username=self.configuration.smtp_username,
                                                email_password=self.configuration.smtp_password)

    def check(self):
        """Check if there is something to report"""
        # Get all the dashboards to use for checking
        scanner = DashboardScanner(self.configuration.grafana_url, self.configuration.grafana_token)
        dashboard_data_list = scanner.obtain_dashboards()
        print dashboard_data_list
        for d in dashboard_data_list:
            try:
                print "Dashboard: " + d['title']
                # {u'slug': u'typrod-storage', u'tags': [], u'isStarred': False, u'id': 4, u'title': u'TyProd Storage'}
                dashboard = Dashboard(self.configuration.grafana_url, self.configuration.grafana_token, d['title'], d['slug'], d['tags'])
                alert_checkers = dashboard.obtain_alert_checkers()
                print alert_checkers

                # For each set of alert checkers, evaluate them
                for alert_checker in alert_checkers:
                    alert_checker.check()
                    reported_alerts = alert_checker.calculate_reported_alerts()
                    # for each set of reported alerts, report whatever is best
                    self.alert_reporter.report(reported_alerts)
            except NotMonitoreableDashboard as e:
                print "Dashboard {title} cannot be monitored. Reason: {reason}".format(title=d['title'], reason=e.message)
                continue
示例#4
0
 def __init__(self, configuration):
     self.configuration = configuration
     self.alert_reporter = MailAlertReporter(email_from=self.configuration.email_from,
                                             smtp_server=self.configuration.smtp_server,
                                             smtp_port=self.configuration.smtp_port,
                                             email_username=self.configuration.smtp_username,
                                             email_password=self.configuration.smtp_password)