def run(self):
        """
        Validate required params and starts up the webapp that listen to hooks from NewRelic.
        """
        if not self._api_url:
            raise Exception('NewRelic API url not found.')
        if not self._api_key:
            raise Exception('NewRelic API key not found.')
        if not self._host or not self._port or not self._url:
            raise Exception('NewRelic webhook app config (host:%s, port:%s, url:%s)' %
                            (self._host, self._port, self._url))
        self._log.info('LegacyNewRelicHookSensor up. host %s, port %s, url %s', self._host,
                       self._port, self._url)

        @self._app.route(self._url, methods=['POST'])
        def handle_nrhook():

            # hooks are sent for alerts and deployments. Only care about alerts so ignoring
            # deployments. Body expected to be of the form -
            #
            # alert : {...}
            #      OR
            # deployment : {...}
            #
            # JSON inside form encoded data, seriously?
            data = request.form
            alert_body = data.get('alert', None)

            if not alert_body:
                self._log.info('Request doesn\'t contain "alert" attribute, ignoring...')
                return 'IGNORED'

            try:
                alert_body = json.loads(alert_body)
            except Exception:
                self._log.exception((alert_body) % 'Failed to parse request body: %s')
                return 'IGNORED'

            if alert_body.get('severity', None) not in ['critical', 'downtime']:
                self._log.debug('Ignoring alert %s as it is not severe enough.', alert_body)
                return 'ACCEPTED'

            hook_headers = self._get_headers_as_dict(request.headers)
            hook_handler = self._get_hook_handler(alert_body, hook_headers)

            # all handling based off 'docs' found in this documentation -
            # https://docs.newrelic.com/docs/alerts/alert-policies/examples/webhook-examples

            try:
                if hook_handler:
                    hook_handler(alert_body, hook_headers)
            except Exception:
                self._log.exception('Failed to handle nr hook %s.', alert_body)

            return 'ACCEPTED'

        self._app.run(host=self._host, port=self._port)
dataset/ETHPy150Open StackStorm/st2contrib/packs/newrelic/sensors/new_relic_legacy_app_sensor.py/LegacyNewRelicHookSensor.run/swapped operands of `%`