Beispiel #1
0
    def amtool_alert_query(self, mess, inhibited=False, silenced=False,
        active=False, unprocessed=False, receiver="", matchers=[]):
        """
          Queries alert in amtool command style
          --inhibited          Show inhibited alerts
          --silenced           Show silenced alerts
          --active             Show active alerts
          --unprocessed        Show unprocessed alerts
          --receiver=RECEIVER  Show alerts matching receiver (Supports regex syntax)

        Args:
          [<matcher-groups>]  Query filter
        """
        if not (inhibited or silenced or active or unprocessed):
            inhibited = True
            silenced = True
            active = True
            unprocessed = True
        self.log.info("matchers {0}".format(matchers))
        helper = AmtoolHelper(
            alertmanager_address=self.config['server_address'])
        filter = helper.get_filters_by_terms(matchers)
        result = helper.get_alerts(
            active=active,
            silenced=silenced,
            inhibited=inhibited,
            unprocessed=unprocessed,
            filter=filter,
            receiver=receiver
        )
        return result
Beispiel #2
0
 def amtool_brief(self, mess, args):
     """Returns brief on alerts"""
     helper = AmtoolHelper(
         alertmanager_address=self.config['server_address'])
     result = helper.get_alerts()
     return result
Beispiel #3
0
 def amtool_alerts(self, mess, args):
     """Returns current alerts list"""
     helper = AmtoolHelper(
         alertmanager_address=self.config['server_address'])
     result = helper.get_alerts()
     return result
Beispiel #4
0
 def test_get_alerts_with_filter(self):
     amtoolhelper = AmtoolHelper(alertmanager_address=ALERTMANAGER_HOST)
     filter = amtoolhelper.get_filters_by_terms(["env=live"])
     alerts = amtoolhelper.get_alerts(filter=filter)
     self.assertIsNotNone(alerts)
Beispiel #5
0
 def test_get_alerts(self):
     amtoolhelper = AmtoolHelper(alertmanager_address=ALERTMANAGER_HOST)
     alerts = amtoolhelper.get_alerts()
     self.assertIsNotNone(alerts)