Esempio n. 1
0
 def __call__(self, req):
     req_id = context.generate_request_id()
     req.environ[ENV_REQUEST_ID] = req_id
     response = req.get_response(self.application)
     if HTTP_RESP_HEADER_REQUEST_ID not in response.headers:
         response.headers.add(HTTP_RESP_HEADER_REQUEST_ID, req_id)
     return response
Esempio n. 2
0
 def __call__(self, req):
     req_id = context.generate_request_id()
     req.environ[ENV_REQUEST_ID] = req_id
     response = req.get_response(self.application)
     if HTTP_RESP_HEADER_REQUEST_ID not in response.headers:
         response.headers.add(HTTP_RESP_HEADER_REQUEST_ID, req_id)
     return response
Esempio n. 3
0
    def notify(action,
               alarm_id,
               alarm_name,
               previous,
               current,
               reason,
               reason_data,
               headers=None):
        headers = headers or {}
        if not headers.get('x-openstack-request-id'):
            headers['x-openstack-request-id'] = context.generate_request_id()

        LOG.info(
            _("Notifying alarm %(alarm_name)s %(alarm_id)s from "
              "%(previous)s to %(current)s with action %(action)s because "
              "%(reason)s. request-id: %(request_id)s ") %
            ({
                'alarm_name': alarm_name,
                'alarm_id': alarm_id,
                'previous': previous,
                'current': current,
                'action': action,
                'reason': reason,
                'request_id': headers['x-openstack-request-id']
            }))
        body = {
            'alarm_name': alarm_name,
            'alarm_id': alarm_id,
            'previous': previous,
            'current': current,
            'reason': reason,
            'reason_data': reason_data
        }
        headers['content-type'] = 'application/json'
        kwargs = {'data': jsonutils.dumps(body), 'headers': headers}

        if action.scheme == 'https':
            default_verify = int(cfg.CONF.alarm.rest_notifier_ssl_verify)
            options = urlparse.parse_qs(action.query)
            verify = bool(
                int(
                    options.get('ceilometer-alarm-ssl-verify',
                                [default_verify])[-1]))
            kwargs['verify'] = verify

            cert = cfg.CONF.alarm.rest_notifier_certificate_file
            key = cfg.CONF.alarm.rest_notifier_certificate_key
            if cert:
                kwargs['cert'] = (cert, key) if key else cert

        # FIXME(rhonjo): Retries are automatically done by urllib3 in requests
        # library. However, there's no interval between retries in urllib3
        # implementation. It will be better to put some interval between
        # retries (future work).
        max_retries = cfg.CONF.alarm.rest_notifier_max_retries
        session = requests.Session()
        session.mount(action.geturl(),
                      requests.adapters.HTTPAdapter(max_retries=max_retries))
        eventlet.spawn_n(session.post, action.geturl(), **kwargs)
Esempio n. 4
0
    def notify(action, alarm_id, previous, current, reason, reason_data,
               headers=None):
        headers = headers or {}
        if not headers.get('x-openstack-request-id'):
            headers['x-openstack-request-id'] = context.generate_request_id()

        LOG.info(_(
            "Notifying alarm %(alarm_id)s from %(previous)s "
            "to %(current)s with action %(action)s because "
            "%(reason)s. request-id: %(request_id)s") %
            ({'alarm_id': alarm_id, 'previous': previous,
              'current': current, 'action': action,
              'reason': reason,
              'request_id': headers['x-openstack-request-id']}))
        body = {'alarm_id': alarm_id, 'previous': previous,
                'current': current, 'reason': reason,
                'reason_data': reason_data}
        headers['content-type'] = 'application/json'
        kwargs = {'data': jsonutils.dumps(body),
                  'headers': headers}

        if action.scheme == 'https':
            default_verify = int(cfg.CONF.alarm.rest_notifier_ssl_verify)
            options = urlparse.parse_qs(action.query)
            verify = bool(int(options.get('ceilometer-alarm-ssl-verify',
                                          [default_verify])[-1]))
            kwargs['verify'] = verify

            cert = cfg.CONF.alarm.rest_notifier_certificate_file
            key = cfg.CONF.alarm.rest_notifier_certificate_key
            if cert:
                kwargs['cert'] = (cert, key) if key else cert

        # FIXME(rhonjo): Retries are automatically done by urllib3 in requests
        # library. However, there's no interval between retries in urllib3
        # implementation. It will be better to put some interval between
        # retries (future work).
        max_retries = cfg.CONF.alarm.rest_notifier_max_retries
        session = requests.Session()
        session.mount(action.geturl(),
                      requests.adapters.HTTPAdapter(max_retries=max_retries))
        eventlet.spawn_n(session.post, action.geturl(), **kwargs)
Esempio n. 5
0
 def process_request(self, req):
     self.req_id = context.generate_request_id()
     req.environ[ENV_REQUEST_ID] = self.req_id
Esempio n. 6
0
 def process_request(self, req):
     self.req_id = context.generate_request_id()
     req.environ[ENV_REQUEST_ID] = self.req_id