예제 #1
0
    def amtool_suppress(self, mess, author="errbot", comment="", weeks=0, days=0, hours=0, minutes=0, criteria=[]):
        """Puts exact suppress match on alert"""
        helper = AmtoolHelper(
            alertmanager_address=self.config['server_address'])

        start_period = datetime.now(pytz.timezone(self.config['time_zone']))
        if weeks+days+hours+minutes == 0:
            hours = 1
        end_period = start_period + timedelta(minutes=minutes, hours=hours,
                                              days=days, weeks=weeks)
        self.log.info("Suppressing {0}->{1}".format(start_period, end_period))
        fingerprint = criteria.pop(0)
        self.log.info("Getting alert by fingerprint {0}".format(fingerprint))
        alert = helper.get_alert(fingerprint)
        matchers = helper.get_matchers_by_alert(alert, include_terms=criteria)
        self.log.info("Matchers {0}".format(matchers))
        result = helper.post_silence(
            matchers=matchers,
            starts_at=start_period.isoformat(),
            ends_at=end_period.isoformat(),
            created_by=author,
            comment=comment
        )
        self.send_card(title="Alert suppressed until {0}".format(end_period),
                    body="Alert created by {0} with description '{1}'. To cancel  !amtool silence expire {2}".format(author, comment, result.silence_id),
                    #                       thumbnail='https://raw.githubusercontent.com/errbotio/errbot/master/docs/_static/errbot.png',
                    #                       image='https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png',
                    # link=result["generatorURL"],
                    fields=helper.convert_matchers_to_tuples(matchers),
                    color='blue',
                    in_reply_to=mess)
예제 #2
0
 def amtool_alert_describe(self, mess, fingerprint):
     """Returns specific silence details"""
     helper = AmtoolHelper(
         alertmanager_address=self.config['server_address'])
     result = helper.get_alert(fingerprint)
     self.send_card(title=result["annotations"]["title"],
                    body=result["annotations"]["description"],
                    #                       thumbnail='https://raw.githubusercontent.com/errbotio/errbot/master/docs/_static/errbot.png',
                    #                       image='https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png',
                    link=result["generatorURL"],
                    fields=result["labels"].items(),
                    color='blue',
                    in_reply_to=mess)
예제 #3
0
    def test_post_silence_suppress(self):
        amtoolhelper = AmtoolHelper(alertmanager_address=ALERTMANAGER_HOST)
        start_period = datetime.now(pytz.timezone('Europe/Kiev'))
        end_period = start_period + timedelta(minutes=1)

        alert = amtoolhelper.get_alert('ee5d73c3f0a498f1')
        matchers = amtoolhelper.get_matchers_by_alert(alert, ["name", "role"])

        silence = amtoolhelper.post_silence(matchers=matchers,
                                            starts_at=start_period.isoformat(),
                                            ends_at=end_period.isoformat(),
                                            created_by="Someone",
                                            comment="test silence")
        self.assertIsNotNone(silence)
예제 #4
0
    def test_post_silence_selective(self):
        amtoolhelper = AmtoolHelper(alertmanager_address=ALERTMANAGER_HOST)
        start_period = datetime.now(pytz.timezone('Europe/Kiev'))
        end_period = start_period + timedelta(minutes=1)

        alert = amtoolhelper.get_alert('af2442fa7f7ee655')
        matchers = amtoolhelper.get_matchers_by_terms(
            terms=["~StrategyDown2", "instance=i-049a6b9bbbb6fb76b"])

        silence = amtoolhelper.post_silence(matchers=matchers,
                                            starts_at=start_period.isoformat(),
                                            ends_at=end_period.isoformat(),
                                            created_by="Someone",
                                            comment="test silence")
        self.assertIsNotNone(silence)
예제 #5
0
 def test_get_alert(self):
     amtoolhelper = AmtoolHelper(alertmanager_address=ALERTMANAGER_HOST)
     alert = amtoolhelper.get_alert('af2442fa7f7ee655')
     self.assertIsNotNone(alert)