Пример #1
0
    def on_get(self, req, res, alarm_id=None):

        if alarm_id is None:
            helpers.validate_authorization(req,
                                           self._get_alarms_authorized_roles)
            start_timestamp = helpers.get_query_starttime_timestamp(req, False)
            end_timestamp = helpers.get_query_endtime_timestamp(req, False)
            offset = helpers.get_query_param(req, 'offset')
            dimensions = helpers.get_query_dimensions(req)
            helpers.validate_query_dimensions(dimensions)

            result = self._alarm_history_list(req.project_id, start_timestamp,
                                              end_timestamp, dimensions,
                                              req.uri, offset, req.limit)

            res.body = helpers.to_json(result)
            res.status = falcon.HTTP_200

        else:
            helpers.validate_authorization(req,
                                           self._get_alarms_authorized_roles)
            offset = helpers.get_query_param(req, 'offset')

            result = self._alarm_history(req.project_id, alarm_id, req.uri,
                                         offset, req.limit)

            res.body = helpers.to_json(result)
            res.status = falcon.HTTP_200
Пример #2
0
    def on_get(self, req, res):
        helpers.validate_authorization(req, self._get_metrics_authorized_roles)
        tenant_id = (
            helpers.get_x_tenant_or_tenant_id(req,
                                              self._delegate_authorized_roles))
        name = helpers.get_query_name(req, True)
        helpers.validate_query_name(name)
        dimensions = helpers.get_query_dimensions(req)
        helpers.validate_query_dimensions(dimensions)
        start_timestamp = helpers.get_query_starttime_timestamp(req)
        end_timestamp = helpers.get_query_endtime_timestamp(req, False)
        helpers.validate_start_end_timestamps(start_timestamp, end_timestamp)
        statistics = helpers.get_query_statistics(req)
        period = helpers.get_query_period(req)
        offset = helpers.get_query_param(req, 'offset')
        merge_metrics_flag = get_merge_metrics_flag(req)
        group_by = helpers.get_query_group_by(req)

        result = self._metric_statistics(tenant_id, name, dimensions,
                                         start_timestamp, end_timestamp,
                                         statistics, period, req.uri,
                                         offset, req.limit, merge_metrics_flag,
                                         group_by)

        res.body = helpers.dumpit_utf8(result)
        res.status = falcon.HTTP_200
Пример #3
0
    def on_get(self, req, res):
        helpers.validate_authorization(req, self._get_metrics_authorized_roles)
        tenant_id = (
            helpers.get_x_tenant_or_tenant_id(req,
                                              self._delegate_authorized_roles))
        name = helpers.get_query_name(req, True)
        helpers.validate_query_name(name)
        dimensions = helpers.get_query_dimensions(req)
        helpers.validate_query_dimensions(dimensions)
        start_timestamp = helpers.get_query_starttime_timestamp(req)
        end_timestamp = helpers.get_query_endtime_timestamp(req, False)
        helpers.validate_start_end_timestamps(start_timestamp, end_timestamp)
        statistics = helpers.get_query_statistics(req)
        period = helpers.get_query_period(req)
        offset = helpers.get_query_param(req, 'offset')
        merge_metrics_flag = get_merge_metrics_flag(req)
        group_by = helpers.get_query_group_by(req)

        result = self._metric_statistics(tenant_id, name, dimensions,
                                         start_timestamp, end_timestamp,
                                         statistics, period, req.uri,
                                         offset, req.limit, merge_metrics_flag,
                                         group_by)

        res.body = helpers.dumpit_utf8(result)
        res.status = falcon.HTTP_200
Пример #4
0
    def on_get(self, req, res):
        helpers.validate_authorization(req, ['api:alarms:count'])
        query_parms = falcon.uri.parse_query_string(req.query_string)

        if 'state' in query_parms:
            validation.validate_alarm_state(query_parms['state'])
            query_parms['state'] = query_parms['state'].upper()

        if 'severity' in query_parms:
            validation.validate_severity_query(query_parms['severity'])
            query_parms['severity'] = query_parms['severity'].upper()

        if 'group_by' in query_parms:
            if not isinstance(query_parms['group_by'], list):
                query_parms['group_by'] = query_parms['group_by'].split(',')
            self._validate_group_by(query_parms['group_by'])

        query_parms['metric_dimensions'] = helpers.get_query_dimensions(req, 'metric_dimensions')
        helpers.validate_query_dimensions(query_parms['metric_dimensions'])

        offset = helpers.get_query_param(req, 'offset')

        if offset is not None:
            try:
                offset = int(offset)
            except Exception:
                raise HTTPUnprocessableEntityError(
                    "Unprocessable Entity",
                    "Offset must be a valid integer, was {}".format(offset))

        result = self._alarms_count(req.uri, req.project_id, query_parms, offset, req.limit)

        res.body = helpers.to_json(result)
        res.status = falcon.HTTP_200
Пример #5
0
    def on_get(self, req, res):
        helpers.validate_authorization(req, self._get_alarms_authorized_roles)
        query_parms = falcon.uri.parse_query_string(req.query_string)

        if 'state' in query_parms:
            validation.validate_alarm_state(query_parms['state'])
            query_parms['state'] = query_parms['state'].upper()

        if 'severity' in query_parms:
            validation.validate_severity_query(query_parms['severity'])
            query_parms['severity'] = query_parms['severity'].upper()

        if 'group_by' in query_parms:
            if not isinstance(query_parms['group_by'], list):
                query_parms['group_by'] = query_parms['group_by'].split(',')
            self._validate_group_by(query_parms['group_by'])

        query_parms['metric_dimensions'] = helpers.get_query_dimensions(req, 'metric_dimensions')
        helpers.validate_query_dimensions(query_parms['metric_dimensions'])

        offset = helpers.get_query_param(req, 'offset')

        if offset is not None:
            try:
                offset = int(offset)
            except Exception:
                raise HTTPUnprocessableEntityError("Unprocessable Entity",
                                                   "Offset must be a valid integer, was {}".format(offset))

        result = self._alarms_count(req.uri, req.project_id, query_parms, offset, req.limit)

        res.body = helpers.dumpit_utf8(result)
        res.status = falcon.HTTP_200
Пример #6
0
    def on_get(self, req, res, alarm_id=None):

        if alarm_id is None:
            helpers.validate_authorization(req, self._get_alarms_authorized_roles)
            start_timestamp = helpers.get_query_starttime_timestamp(req, False)
            end_timestamp = helpers.get_query_endtime_timestamp(req, False)
            offset = helpers.get_query_param(req, 'offset')
            dimensions = helpers.get_query_dimensions(req)
            helpers.validate_query_dimensions(dimensions)

            result = self._alarm_history_list(req.project_id, start_timestamp,
                                              end_timestamp, dimensions,
                                              req.uri, offset, req.limit)

            res.body = helpers.to_json(result)
            res.status = falcon.HTTP_200

        else:
            helpers.validate_authorization(req, self._get_alarms_authorized_roles)
            offset = helpers.get_query_param(req, 'offset')

            result = self._alarm_history(req.project_id, alarm_id,
                                         req.uri, offset,
                                         req.limit)

            res.body = helpers.to_json(result)
            res.status = falcon.HTTP_200
Пример #7
0
 def on_get(self, req, res):
     helpers.validate_authorization(req, ['api:metrics:get'])
     tenant_id = helpers.get_x_tenant_or_tenant_id(req, ['api:delegate'])
     dimensions = helpers.get_query_dimensions(req)
     helpers.validate_query_dimensions(dimensions)
     offset = helpers.get_query_param(req, 'offset')
     result = self._list_metric_names(tenant_id, dimensions, req.uri,
                                      offset, req.limit)
     res.body = helpers.to_json(result)
     res.status = falcon.HTTP_200
Пример #8
0
 def on_get(self, req, res):
     helpers.validate_authorization(req, self._default_authorized_roles)
     tenant_id = helpers.get_tenant_id(req)
     dimensions = helpers.get_query_dimensions(req)
     helpers.validate_query_dimensions(dimensions)
     offset = helpers.get_query_param(req, 'offset')
     limit = helpers.get_limit(req)
     result = self._list_metric_names(tenant_id, dimensions, req.uri,
                                      offset, limit)
     res.body = helpers.dumpit_utf8(result)
     res.status = falcon.HTTP_200
Пример #9
0
 def on_get(self, req, res):
     helpers.validate_authorization(req, self._get_metrics_authorized_roles)
     tenant_id = helpers.get_tenant_id(req)
     dimensions = helpers.get_query_dimensions(req)
     helpers.validate_query_dimensions(dimensions)
     offset = helpers.get_query_param(req, 'offset')
     limit = helpers.get_limit(req)
     result = self._list_metric_names(tenant_id, dimensions,
                                      req.uri, offset, limit)
     res.body = helpers.dumpit_utf8(result)
     res.status = falcon.HTTP_200
Пример #10
0
 def on_get(self, req, res):
     helpers.validate_authorization(req, self._get_metrics_authorized_roles)
     tenant_id = (
         helpers.get_x_tenant_or_tenant_id(req,
                                           self._delegate_authorized_roles))
     dimensions = helpers.get_query_dimensions(req)
     helpers.validate_query_dimensions(dimensions)
     offset = helpers.get_query_param(req, 'offset')
     result = self._list_metric_names(tenant_id, dimensions,
                                      req.uri, offset, req.limit)
     res.body = helpers.to_json(result)
     res.status = falcon.HTTP_200
Пример #11
0
    def on_get(self, req, res, alarm_id=None):
        helpers.validate_authorization(req, ['api:alarms:get'])

        if alarm_id is None:
            query_parms = falcon.uri.parse_query_string(req.query_string)
            if 'state' in query_parms:
                validation.validate_alarm_state(query_parms['state'])
                query_parms['state'] = query_parms['state'].upper()

            if 'severity' in query_parms:
                validation.validate_severity_query(query_parms['severity'])
                query_parms['severity'] = query_parms['severity'].upper()

            if 'sort_by' in query_parms:
                if isinstance(query_parms['sort_by'], six.string_types):
                    query_parms['sort_by'] = query_parms['sort_by'].split(',')

                allowed_sort_by = {
                    'alarm_id', 'alarm_definition_id', 'alarm_definition_name',
                    'state', 'severity', 'lifecycle_state', 'link',
                    'state_updated_timestamp', 'updated_timestamp',
                    'created_timestamp'
                }
                validation.validate_sort_by(query_parms['sort_by'],
                                            allowed_sort_by)

            query_parms['metric_dimensions'] = helpers.get_query_dimensions(
                req, 'metric_dimensions')
            helpers.validate_query_dimensions(query_parms['metric_dimensions'])

            offset = helpers.get_query_param(req, 'offset')
            if offset is not None and not isinstance(offset, int):
                try:
                    offset = int(offset)
                except Exception as ex:
                    LOG.exception(ex)
                    raise HTTPUnprocessableEntityError(
                        "Unprocessable Entity",
                        "Offset value {} must be an integer".format(offset))

            result = self._alarm_list(req.uri, req.project_id, query_parms,
                                      offset, req.limit)

            res.body = helpers.to_json(result)
            res.status = falcon.HTTP_200

        else:
            result = self._alarm_show(req.uri, req.project_id, alarm_id)

            res.body = helpers.to_json(result)
            res.status = falcon.HTTP_200
Пример #12
0
    def on_get(self, req, res, alarm_id=None):
        helpers.validate_authorization(req, ['api:alarms:get'])

        if alarm_id is None:
            query_parms = falcon.uri.parse_query_string(req.query_string)
            if 'state' in query_parms:
                validation.validate_alarm_state(query_parms['state'])
                query_parms['state'] = query_parms['state'].upper()

            if 'severity' in query_parms:
                validation.validate_severity_query(query_parms['severity'])
                query_parms['severity'] = query_parms['severity'].upper()

            if 'sort_by' in query_parms:
                if isinstance(query_parms['sort_by'], six.string_types):
                    query_parms['sort_by'] = query_parms['sort_by'].split(',')

                allowed_sort_by = {
                    'alarm_id', 'alarm_definition_id', 'alarm_definition_name',
                    'state', 'severity', 'lifecycle_state', 'link',
                    'state_updated_timestamp', 'updated_timestamp', 'created_timestamp'}
                validation.validate_sort_by(query_parms['sort_by'], allowed_sort_by)

            query_parms['metric_dimensions'] = helpers.get_query_dimensions(
                req, 'metric_dimensions')
            helpers.validate_query_dimensions(query_parms['metric_dimensions'])

            offset = helpers.get_query_param(req, 'offset')
            if offset is not None and not isinstance(offset, int):
                try:
                    offset = int(offset)
                except Exception as ex:
                    LOG.exception(ex)
                    raise HTTPUnprocessableEntityError(
                        "Unprocessable Entity",
                        "Offset value {} must be an integer".format(offset))

            result = self._alarm_list(req.uri, req.project_id,
                                      query_parms, offset,
                                      req.limit)

            res.body = helpers.to_json(result)
            res.status = falcon.HTTP_200

        else:
            result = self._alarm_show(req.uri, req.project_id, alarm_id)

            res.body = helpers.to_json(result)
            res.status = falcon.HTTP_200
Пример #13
0
 def on_get(self, req, res):
     helpers.validate_authorization(req, ['api:metrics:get'])
     tenant_id = helpers.get_x_tenant_or_tenant_id(req, ['api:delegate'])
     name = helpers.get_query_name(req)
     helpers.validate_query_name(name)
     dimensions = helpers.get_query_dimensions(req)
     helpers.validate_query_dimensions(dimensions)
     offset = helpers.get_query_param(req, 'offset')
     start_timestamp = helpers.get_query_starttime_timestamp(req, False)
     end_timestamp = helpers.get_query_endtime_timestamp(req, False)
     helpers.validate_start_end_timestamps(start_timestamp, end_timestamp)
     result = self._list_metrics(tenant_id, name, dimensions, req.uri,
                                 offset, req.limit, start_timestamp,
                                 end_timestamp)
     res.body = helpers.to_json(result)
     res.status = falcon.HTTP_200
Пример #14
0
 def on_get(self, req, res):
     helpers.validate_authorization(req, self._get_metrics_authorized_roles)
     tenant_id = helpers.get_tenant_id(req)
     name = helpers.get_query_name(req)
     helpers.validate_query_name(name)
     dimensions = helpers.get_query_dimensions(req)
     helpers.validate_query_dimensions(dimensions)
     offset = helpers.get_query_param(req, 'offset')
     limit = helpers.get_limit(req)
     start_timestamp = helpers.get_query_starttime_timestamp(req, False)
     end_timestamp = helpers.get_query_endtime_timestamp(req, False)
     helpers.validate_start_end_timestamps(start_timestamp, end_timestamp)
     result = self._list_metrics(tenant_id, name, dimensions,
                                 req.uri, offset, limit,
                                 start_timestamp, end_timestamp)
     res.body = helpers.dumpit_utf8(result)
     res.status = falcon.HTTP_200