コード例 #1
0
    def pre_receive(self, alert):
        if any(regex.match(alert.origin) for regex in ORIGIN_BLACKLIST_REGEX):
            LOG.warning("[POLICY] Alert origin '%s' has been blacklisted", alert.origin)
            raise RejectException("[POLICY] Alert origin '%s' has been blacklisted" % alert.origin)

        if not any(regex.match(alert.environment) for regex in ALLOWED_ENVIRONMENT_REGEX):
            LOG.warning("[POLICY] Alert environment does not match one of %s", ', '.join(ALLOWED_ENVIRONMENTS))
            raise RejectException("[POLICY] Alert environment does not match one of %s" % ', '.join(ALLOWED_ENVIRONMENTS))

        if not alert.service:
            LOG.warning("[POLICY] Alert must define a service")
            raise RejectException("[POLICY] Alert must define a service")

        return alert
コード例 #2
0
    def incoming(self, query_string, payload):
        alert_severity = os.environ.get('STATUSCAKE_DEFAULT_ALERT_SEVERITY',
                                        'major')

        # If the statuscake username and apikey are provided
        # We can validate that the webhook call is valid
        statuscake_username = os.environ.get('STATUSCAKE_USERNAME')
        statuscake_apikey = os.environ.get('STATUSCAKE_APIKEY')

        if statuscake_username and statuscake_apikey:
            decoded_token = statuscake_username + statuscake_apikey
            statuscake_token = hashlib.md5(decoded_token.encode()).hexdigest()
            if statuscake_token != payload['Token']:
                raise RejectException("Provided Token couldn't be verified")

        if payload['Status'] == 'UP':
            severity = 'normal'
        else:
            severity = alert_severity

        return Alert(resource=payload['Name'],
                     event='AppDown',
                     environment='Production',
                     severity=severity,
                     service=['StatusCake'],
                     group='Application',
                     value=payload['StatusCode'],
                     text="%s is down" % payload['URL'],
                     tags=payload['Tags'].split(','),
                     origin='statuscake',
                     raw_data=str(payload))
コード例 #3
0
    def pre_receive(self, alert, **kwargs):

        ORIGIN_BLACKLIST = self.get_config('ORIGIN_BLACKLIST', default=[], type=list, **kwargs)
        ALLOWED_ENVIRONMENTS = self.get_config('ALLOWED_ENVIRONMENTS', default=[], type=list, **kwargs)

        ORIGIN_BLACKLIST_REGEX = [re.compile(x) for x in ORIGIN_BLACKLIST]
        ALLOWED_ENVIRONMENT_REGEX = [re.compile(x) for x in ALLOWED_ENVIRONMENTS]

        if any(regex.match(alert.origin) for regex in ORIGIN_BLACKLIST_REGEX):
            LOG.warning("[POLICY] Alert origin '%s' has been blacklisted", alert.origin)
            raise RejectException("[POLICY] Alert origin '%s' has been blacklisted" % alert.origin)

        if not any(regex.match(alert.environment) for regex in ALLOWED_ENVIRONMENT_REGEX):
            LOG.warning('[POLICY] Alert environment does not match one of %s', ', '.join(ALLOWED_ENVIRONMENTS))
            raise RejectException('[POLICY] Alert environment does not match one of %s' %
                                  ', '.join(ALLOWED_ENVIRONMENTS))

        if not alert.service:
            LOG.warning('[POLICY] Alert must define a service')
            raise RejectException('[POLICY] Alert must define a service')

        return alert