Пример #1
0
    def on_get(self, req, res, alarm_id=None):
        if alarm_id is None:
            helpers.validate_authorization(req, self._default_authorized_roles)
            tenant_id = helpers.get_tenant_id(req)

            query_parms = falcon.uri.parse_query_string(req.query_string)

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

            limit = helpers.get_limit(req)

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

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

        else:
            helpers.validate_authorization(req, self._default_authorized_roles)
            tenant_id = helpers.get_tenant_id(req)

            result = self._alarm_show(req.uri, tenant_id, alarm_id)

            res.body = helpers.dumpit_utf8(result)
            res.status = falcon.HTTP_200
Пример #2
0
    def on_get(self, req, res, notification_method_id=None):
        if notification_method_id is None:
            helpers.validate_authorization(req, self._default_authorized_roles)
            tenant_id = helpers.get_tenant_id(req)
            sort_by = helpers.get_query_param(req, 'sort_by', default_val=None)
            if sort_by is not None:
                if isinstance(sort_by, basestring):
                    sort_by = sort_by.split(',')

                allowed_sort_by = {'id', 'name', 'type', 'address',
                                   'updated_at', 'created_at'}

                validation.validate_sort_by(sort_by, allowed_sort_by)

            offset = helpers.get_query_param(req, 'offset')
            limit = helpers.get_limit(req)
            result = self._list_notifications(tenant_id, req.uri, sort_by,
                                              offset, limit)
            res.body = helpers.dumpit_utf8(result)
            res.status = falcon.HTTP_200
        else:
            helpers.validate_authorization(req,
                                           self._default_authorized_roles)
            tenant_id = helpers.get_tenant_id(req)
            result = self._list_notification(tenant_id,
                                             notification_method_id,
                                             req.uri)
            res.body = helpers.dumpit_utf8(result)
            res.status = falcon.HTTP_200
Пример #3
0
    def on_get(self, req, res, alarm_id=None):
        if alarm_id is None:
            helpers.validate_authorization(req, self._default_authorized_roles)
            tenant_id = helpers.get_tenant_id(req)

            query_parms = falcon.uri.parse_query_string(req.query_string)

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

            limit = helpers.get_limit(req)

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

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

        else:
            helpers.validate_authorization(req, self._default_authorized_roles)
            tenant_id = helpers.get_tenant_id(req)

            result = self._alarm_show(req.uri, tenant_id, alarm_id)

            res.body = helpers.dumpit_utf8(result)
            res.status = falcon.HTTP_200
Пример #4
0
    def on_get(self, req, res, alarm_definition_id=None):
        if alarm_definition_id is None:
            helpers.validate_authorization(req, self._default_authorized_roles)
            tenant_id = helpers.get_tenant_id(req)
            name = helpers.get_query_name(req)
            dimensions = helpers.get_query_dimensions(req)
            offset = helpers.get_query_param(req, 'offset')
            limit = helpers.get_limit(req)

            result = self._alarm_definition_list(tenant_id, name, dimensions,
                                                 req.uri, offset, limit)

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

        else:
            helpers.validate_authorization(req, self._default_authorized_roles)
            tenant_id = helpers.get_tenant_id(req)

            result = self._alarm_definition_show(tenant_id,
                                                 alarm_definition_id)

            helpers.add_links_to_resource(result,
                                          re.sub('/' + alarm_definition_id, '',
                                                 req.uri))
            res.body = helpers.dumpit_utf8(result)
            res.status = falcon.HTTP_200
Пример #5
0
    def on_get(self, req, res, alarm_id=None):

        if alarm_id is None:
            helpers.validate_authorization(req, self._default_authorized_roles)
            tenant_id = helpers.get_tenant_id(req)
            start_timestamp = helpers.get_query_starttime_timestamp(req, False)
            end_timestamp = helpers.get_query_endtime_timestamp(req, False)
            query_parms = falcon.uri.parse_query_string(req.query_string)
            offset = helpers.get_query_param(req, 'offset')
            limit = helpers.get_limit(req)

            result = self._alarm_history_list(tenant_id, start_timestamp,
                                              end_timestamp, query_parms,
                                              req.uri, offset, limit)

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

        else:
            helpers.validate_authorization(req, self._default_authorized_roles)
            tenant_id = helpers.get_tenant_id(req)
            offset = helpers.get_query_param(req, 'offset')
            limit = helpers.get_limit(req)

            result = self._alarm_history(tenant_id, [alarm_id], req.uri,
                                         offset, limit)

            res.body = helpers.dumpit_utf8(result)
            res.status = falcon.HTTP_200
Пример #6
0
    def on_get(self, req, res, notification_method_id=None):
        if notification_method_id is None:
            helpers.validate_authorization(
                req, self._get_notifications_authorized_roles)
            tenant_id = helpers.get_tenant_id(req)
            sort_by = helpers.get_query_param(req, 'sort_by', default_val=None)
            if sort_by is not None:
                if isinstance(sort_by, basestring):
                    sort_by = sort_by.split(',')

                allowed_sort_by = {
                    'id', 'name', 'type', 'address', 'updated_at', 'created_at'
                }

                validation.validate_sort_by(sort_by, allowed_sort_by)

            offset = helpers.get_query_param(req, 'offset')
            limit = helpers.get_limit(req)
            result = self._list_notifications(tenant_id, req.uri, sort_by,
                                              offset, limit)
            res.body = helpers.dumpit_utf8(result)
            res.status = falcon.HTTP_200
        else:
            helpers.validate_authorization(
                req, self._get_notifications_authorized_roles)
            tenant_id = helpers.get_tenant_id(req)
            result = self._list_notification(tenant_id, notification_method_id,
                                             req.uri)
            res.body = helpers.dumpit_utf8(result)
            res.status = falcon.HTTP_200
Пример #7
0
    def on_get(self, req, res, alarm_id=None):

        if alarm_id is None:
            helpers.validate_authorization(req,
                                           self._get_alarms_authorized_roles)
            tenant_id = helpers.get_tenant_id(req)
            start_timestamp = helpers.get_query_starttime_timestamp(req, False)
            end_timestamp = helpers.get_query_endtime_timestamp(req, False)
            query_parms = falcon.uri.parse_query_string(req.query_string)
            offset = helpers.get_query_param(req, 'offset')
            limit = helpers.get_limit(req)

            result = self._alarm_history_list(tenant_id, start_timestamp,
                                              end_timestamp, query_parms,
                                              req.uri, offset, limit)

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

        else:
            helpers.validate_authorization(req,
                                           self._get_alarms_authorized_roles)
            tenant_id = helpers.get_tenant_id(req)
            offset = helpers.get_query_param(req, 'offset')
            limit = helpers.get_limit(req)

            result = self._alarm_history(tenant_id, [alarm_id], req.uri,
                                         offset, limit)

            res.body = helpers.dumpit_utf8(result)
            res.status = falcon.HTTP_200
Пример #8
0
    def on_get(self, req, res, alarm_definition_id=None):
        if alarm_definition_id is None:
            helpers.validate_authorization(
                req, self._get_alarmdefs_authorized_roles)
            tenant_id = helpers.get_tenant_id(req)
            name = helpers.get_query_name(req)
            dimensions = helpers.get_query_dimensions(req)
            severity = helpers.get_query_param(req,
                                               "severity",
                                               default_val=None)
            if severity is not None:
                validation.validate_severity_query(severity)
            sort_by = helpers.get_query_param(req, 'sort_by', default_val=None)
            if sort_by is not None:
                if isinstance(sort_by, basestring):
                    sort_by = sort_by.split(',')

                allowed_sort_by = {
                    'id', 'name', 'severity', 'updated_at', 'created_at'
                }

                validation.validate_sort_by(sort_by, allowed_sort_by)

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

            result = self._alarm_definition_list(tenant_id, name, dimensions,
                                                 severity, req.uri, sort_by,
                                                 offset, limit)

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

        else:
            helpers.validate_authorization(
                req, self._get_alarmdefs_authorized_roles)
            tenant_id = helpers.get_tenant_id(req)

            result = self._alarm_definition_show(tenant_id,
                                                 alarm_definition_id)

            helpers.add_links_to_resource(
                result, re.sub('/' + alarm_definition_id, '', req.uri))
            res.body = helpers.dumpit_utf8(result)
            res.status = falcon.HTTP_200
Пример #9
0
 def on_get(self, req, res, notification_method_id=None):
     if notification_method_id is None:
         helpers.validate_authorization(req, self._default_authorized_roles)
         tenant_id = helpers.get_tenant_id(req)
         offset = helpers.get_query_param(req, "offset")
         limit = helpers.get_limit(req)
         result = self._list_notifications(tenant_id, req.uri, offset, limit)
         res.body = helpers.dumpit_utf8(result)
         res.status = falcon.HTTP_200
     else:
         helpers.validate_authorization(req, self._default_authorized_roles)
         tenant_id = helpers.get_tenant_id(req)
         result = self._list_notification(tenant_id, notification_method_id, req.uri)
         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_tenant_id(req)
        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')
        limit = helpers.get_limit(req)
        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, limit, merge_metrics_flag,
                                         group_by)

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

        helpers.validate_authorization(req, self._default_authorized_roles)

        tenant_id = helpers.get_tenant_id(req)

        alarm = helpers.read_http_resource(req)
        schema_alarm.validate(alarm)

        # Validator makes state optional, so check it here
        if 'state' not in alarm or not alarm['state']:
            raise HTTPUnprocessableEntityError('Unprocessable Entity',
                                               "Field 'state' is required")
        if 'lifecycle_state' not in alarm or not alarm['lifecycle_state']:
            raise HTTPUnprocessableEntityError(
                'Unprocessable Entity', "Field 'lifecycle_state' is required")
        if 'link' not in alarm or not alarm['link']:
            raise HTTPUnprocessableEntityError('Unprocessable Entity',
                                               "Field 'link' is required")

        self._alarm_update(tenant_id, alarm_id, alarm['state'],
                           alarm['lifecycle_state'], alarm['link'])

        result = self._alarm_show(req.uri, tenant_id, alarm_id)

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

        helpers.validate_authorization(req, self._default_authorized_roles)

        tenant_id = helpers.get_tenant_id(req)

        alarm = helpers.read_http_resource(req)
        schema_alarm.validate(alarm)

        # Validator makes state optional, so check it here
        if 'state' not in alarm or not alarm['state']:
            raise falcon.HTTPBadRequest('Bad request',
                                        "Field 'state' is required")

        # Assume these fields are null if not provided
        if 'lifecycle_state' not in alarm:
            alarm['lifecycle_state'] = None
        if 'link' not in alarm:
            alarm['link'] = None

        self._alarm_update(tenant_id, alarm_id, alarm['state'],
                           alarm['lifecycle_state'], alarm['link'])

        result = self._alarm_show(req.uri, tenant_id, alarm_id)

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

        if alarm_id is None:
            query_parms = falcon.uri.parse_query_string(req.query_string)

            # ensure metric_dimensions is a list
            if 'metric_dimensions' in query_parms and isinstance(query_parms['metric_dimensions'], str):
                query_parms['metric_dimensions'] = query_parms['metric_dimensions'].split(',')

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

            limit = helpers.get_limit(req)

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

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

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

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

        helpers.validate_authorization(req, self._default_authorized_roles)

        tenant_id = helpers.get_tenant_id(req)

        alarm = helpers.read_http_resource(req)
        schema_alarm.validate(alarm)

        # Validator makes state optional, so check it here
        if 'state' not in alarm or not alarm['state']:
            raise falcon.HTTPBadRequest('Bad request',
                                        "Field 'state' is required")

        # Assume these fields are null if not provided
        if 'lifecycle_state' not in alarm:
            alarm['lifecycle_state'] = None
        if 'link' not in alarm:
            alarm['link'] = None

        self._alarm_update(tenant_id, alarm_id, alarm['state'],
                           alarm['lifecycle_state'], alarm['link'])

        result = self._alarm_show(req.uri, tenant_id, alarm_id)

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

        if alarm_id is None:
            query_parms = falcon.uri.parse_query_string(req.query_string)

            # ensure metric_dimensions is a list
            if 'metric_dimensions' in query_parms and isinstance(
                    query_parms['metric_dimensions'], str):
                query_parms['metric_dimensions'] = query_parms[
                    'metric_dimensions'].split(',')

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

            limit = helpers.get_limit(req)

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

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

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

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

        helpers.validate_authorization(req, self._default_authorized_roles)

        tenant_id = helpers.get_tenant_id(req)

        alarm = helpers.read_http_resource(req)
        schema_alarm.validate(alarm)

        old_alarm = self._alarms_repo.get_alarm(tenant_id, alarm_id)[0]

        # if a field is not present or is None, replace it with the old value
        if 'state' not in alarm or not alarm['state']:
            alarm['state'] = old_alarm['state']
        if 'lifecycle_state' not in alarm or alarm['lifecycle_state'] is None:
            alarm['lifecycle_state'] = old_alarm['lifecycle_state']
        if 'link' not in alarm or alarm['link'] is None:
            alarm['link'] = old_alarm['link']

        self._alarm_patch(tenant_id, alarm_id, alarm['state'],
                          alarm['lifecycle_state'], alarm['link'])

        result = self._alarm_show(req.uri, tenant_id, alarm_id)

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

        helpers.validate_authorization(req, self._default_authorized_roles)

        tenant_id = helpers.get_tenant_id(req)

        alarm = helpers.read_http_resource(req)
        schema_alarm.validate(alarm)

        old_alarm = self._alarms_repo.get_alarm(tenant_id, alarm_id)[0]

        # if a field is not present or is None, replace it with the old value
        if 'state' not in alarm or not alarm['state']:
            alarm['state'] = old_alarm['state']
        if 'lifecycle_state' not in alarm or alarm['lifecycle_state'] is None:
            alarm['lifecycle_state'] = old_alarm['lifecycle_state']
        if 'link' not in alarm or alarm['link'] is None:
            alarm['link'] = old_alarm['link']

        self._alarm_patch(tenant_id, alarm_id, alarm['state'],
                          alarm['lifecycle_state'], alarm['link'])

        result = self._alarm_show(req.uri, tenant_id, alarm_id)

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

        helpers.validate_authorization(req, self._default_authorized_roles)

        tenant_id = helpers.get_tenant_id(req)

        alarm = helpers.read_http_resource(req)
        schema_alarm.validate(alarm)

        # Validator makes state optional, so check it here
        if 'state' not in alarm or not alarm['state']:
            raise HTTPUnprocessableEntityError('Unprocessable Entity',
                                               "Field 'state' is required")
        if 'lifecycle_state' not in alarm or not alarm['lifecycle_state']:
            raise HTTPUnprocessableEntityError('Unprocessable Entity',
                                               "Field 'lifecycle_state' is required")
        if 'link' not in alarm or not alarm['link']:
            raise HTTPUnprocessableEntityError('Unprocessable Entity',
                                               "Field 'link' is required")

        self._alarm_update(tenant_id, alarm_id, alarm['state'],
                           alarm['lifecycle_state'], alarm['link'])

        result = self._alarm_show(req.uri, tenant_id, alarm_id)

        res.body = helpers.dumpit_utf8(result)
        res.status = falcon.HTTP_200
Пример #19
0
    def on_post(self, req, res):
        helpers.validate_authorization(req, self._default_authorized_roles)

        alarm_definition = helpers.read_json_msg_body(req)

        self._validate_alarm_definition(alarm_definition)

        tenant_id = helpers.get_tenant_id(req)
        name = get_query_alarm_definition_name(alarm_definition)
        expression = get_query_alarm_definition_expression(alarm_definition)
        description = get_query_alarm_definition_description(alarm_definition)
        severity = get_query_alarm_definition_severity(alarm_definition)
        match_by = get_query_alarm_definition_match_by(alarm_definition)
        alarm_actions = get_query_alarm_definition_alarm_actions(
            alarm_definition)
        undetermined_actions = get_query_alarm_definition_undetermined_actions(
            alarm_definition)
        ok_actions = get_query_ok_actions(alarm_definition)

        result = self._alarm_definition_create(tenant_id, name, expression,
                                               description, severity, match_by,
                                               alarm_actions,
                                               undetermined_actions,
                                               ok_actions)

        helpers.add_links_to_resource(result, req.uri)
        res.body = helpers.dumpit_utf8(result)
        res.status = falcon.HTTP_201
Пример #20
0
    def on_get(self, req, res):
        helpers.validate_authorization(req, self._default_authorized_roles)
        tenant_id = helpers.get_tenant_id(req)
        query_parms = falcon.uri.parse_query_string(req.query_string)

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

        if 'severity' in query_parms:
            validation.validate_alarm_definition_severity(query_parms['severity'])

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

        # ensure metric_dimensions is a list
        if 'metric_dimensions' in query_parms and isinstance(query_parms['metric_dimensions'], str):
            query_parms['metric_dimensions'] = query_parms['metric_dimensions'].split(',')

        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))

        limit = helpers.get_limit(req)

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

        res.body = helpers.dumpit_utf8(result)
        res.status = falcon.HTTP_200
Пример #21
0
    def on_get(self, req, res, alarm_definition_id=None):
        if alarm_definition_id is None:
            helpers.validate_authorization(req, self._default_authorized_roles)
            tenant_id = helpers.get_tenant_id(req)
            name = helpers.get_query_name(req)
            dimensions = helpers.get_query_dimensions(req)
            severity = helpers.get_query_param(req, "severity", default_val=None)
            if severity is not None:
                validation.validate_severity_query(severity)
            sort_by = helpers.get_query_param(req, 'sort_by', default_val=None)
            if sort_by is not None:
                if isinstance(sort_by, basestring):
                    sort_by = sort_by.split(',')

                allowed_sort_by = {'id', 'name', 'severity',
                                   'updated_at', 'created_at'}

                validation.validate_sort_by(sort_by, allowed_sort_by)

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

            result = self._alarm_definition_list(tenant_id, name, dimensions, severity,
                                                 req.uri, sort_by, offset, limit)

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

        else:
            helpers.validate_authorization(req, self._default_authorized_roles)
            tenant_id = helpers.get_tenant_id(req)

            result = self._alarm_definition_show(tenant_id,
                                                 alarm_definition_id)

            helpers.add_links_to_resource(result,
                                          re.sub('/' + alarm_definition_id, '',
                                                 req.uri))
            res.body = helpers.dumpit_utf8(result)
            res.status = falcon.HTTP_200
Пример #22
0
 def on_get(self, req, res, notification_method_id=None):
     if notification_method_id is None:
         helpers.validate_authorization(req, self._default_authorized_roles)
         tenant_id = helpers.get_tenant_id(req)
         offset = helpers.get_query_param(req, 'offset')
         limit = helpers.get_limit(req)
         result = self._list_notifications(tenant_id, req.uri, offset,
                                           limit)
         res.body = helpers.dumpit_utf8(result)
         res.status = falcon.HTTP_200
     else:
         helpers.validate_authorization(req, self._default_authorized_roles)
         tenant_id = helpers.get_tenant_id(req)
         result = self._list_notification(tenant_id, notification_method_id,
                                          req.uri)
         res.body = helpers.dumpit_utf8(result)
         res.status = falcon.HTTP_200
Пример #23
0
 def on_post(self, req, res):
     helpers.validate_json_content_type(req)
     helpers.validate_authorization(req, self._default_authorized_roles)
     notification = helpers.read_http_resource(req)
     self._validate_notification(notification)
     tenant_id = helpers.get_tenant_id(req)
     result = self._create_notification(tenant_id, notification, req.uri)
     res.body = helpers.dumpit_utf8(result)
     res.status = falcon.HTTP_201
Пример #24
0
    def on_delete(self, req, res, alarm_id):

        helpers.validate_authorization(req, self._default_authorized_roles)

        tenant_id = helpers.get_tenant_id(req)

        self._alarm_delete(tenant_id, alarm_id)

        res.status = falcon.HTTP_204
Пример #25
0
 def on_put(self, req, res, notification_method_id):
     helpers.validate_json_content_type(req)
     helpers.validate_authorization(req, self._default_authorized_roles)
     notification = helpers.read_http_resource(req)
     self._parse_and_validate_notification(notification, require_all=True)
     tenant_id = helpers.get_tenant_id(req)
     result = self._update_notification(notification_method_id, tenant_id, notification, req.uri)
     res.body = helpers.dumpit_utf8(result)
     res.status = falcon.HTTP_200
Пример #26
0
    def on_delete(self, req, res, alarm_id):

        helpers.validate_authorization(req, self._default_authorized_roles)

        tenant_id = helpers.get_tenant_id(req)

        self._alarm_delete(tenant_id, alarm_id)

        res.status = falcon.HTTP_204
Пример #27
0
 def on_post(self, req, res):
     helpers.validate_json_content_type(req)
     helpers.validate_authorization(req, self._default_authorized_roles)
     notification = helpers.read_http_resource(req)
     self._parse_and_validate_notification(notification)
     tenant_id = helpers.get_tenant_id(req)
     result = self._create_notification(tenant_id, notification, req.uri)
     res.body = helpers.dumpit_utf8(result)
     res.status = falcon.HTTP_201
Пример #28
0
    def on_get(self, req, res, alarm_id=None):
        helpers.validate_authorization(req, self._default_authorized_roles)
        tenant_id = helpers.get_tenant_id(req)

        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'])

            if 'severity' in query_parms:
                validation.validate_alarm_definition_severity(
                    query_parms['severity'])

            if 'sort_by' in query_parms:
                if isinstance(query_parms['sort_by'], basestring):
                    query_parms['sort_by'] = [query_parms['sort_by']]

                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)

            # ensure metric_dimensions is a list
            if 'metric_dimensions' in query_parms and isinstance(
                    query_parms['metric_dimensions'], str):
                query_parms['metric_dimensions'] = query_parms[
                    'metric_dimensions'].split(',')
                self._validate_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))

            limit = helpers.get_limit(req)

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

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

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

            res.body = helpers.dumpit_utf8(result)
            res.status = falcon.HTTP_200
Пример #29
0
 def on_get(self, req, res):
     helpers.validate_authorization(req, self._get_metrics_authorized_roles)
     tenant_id = helpers.get_tenant_id(req)
     metric_name = helpers.get_query_param(req, 'metric_name')
     offset = helpers.get_query_param(req, 'offset')
     limit = helpers.get_limit(req)
     result = self._dimension_names(tenant_id, req.uri, metric_name,
                                    offset, limit)
     res.body = helpers.dumpit_utf8(result)
     res.status = falcon.HTTP_200
Пример #30
0
    def on_get(self, req, res, alarm_id=None):
        helpers.validate_authorization(req, self._default_authorized_roles)
        tenant_id = helpers.get_tenant_id(req)

        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'])

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

            if 'sort_by' in query_parms:
                if isinstance(query_parms['sort_by'], basestring):
                    query_parms['sort_by'] = [query_parms['sort_by']]

                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)

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

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

            # ensure metric_dimensions is a list
            if 'metric_dimensions' in query_parms and isinstance(query_parms['metric_dimensions'], str):
                query_parms['metric_dimensions'] = query_parms['metric_dimensions'].split(',')
                self._validate_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))

            limit = helpers.get_limit(req)

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

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

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

            res.body = helpers.dumpit_utf8(result)
            res.status = falcon.HTTP_200
Пример #31
0
 def on_patch(self, req, res, notification_method_id):
     helpers.validate_json_content_type(req)
     helpers.validate_authorization(req, self._default_authorized_roles)
     notification = helpers.read_http_resource(req)
     tenant_id = helpers.get_tenant_id(req)
     self._patch_get_notification(tenant_id, notification_method_id,
                                  notification)
     self._parse_and_validate_notification(notification, require_all=True)
     result = self._update_notification(notification_method_id, tenant_id,
                                        notification, req.uri)
     res.body = helpers.dumpit_utf8(result)
     res.status = falcon.HTTP_200
Пример #32
0
 def on_get(self, req, res):
     helpers.validate_authorization(req, self._default_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)
     result = self._list_metrics(tenant_id, name, dimensions,
                                 req.uri, offset, limit)
     res.body = helpers.dumpit_utf8(result)
     res.status = falcon.HTTP_200
Пример #33
0
 def on_get(self, req, res):
     helpers.validate_authorization(req, self._default_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)
     result = self._list_metrics(tenant_id, name, dimensions, req.uri,
                                 offset, limit)
     res.body = helpers.dumpit_utf8(result)
     res.status = falcon.HTTP_200
Пример #34
0
    def on_put(self, req, res, alarm_definition_id):

        helpers.validate_authorization(req, self._default_authorized_roles)

        alarm_definition = helpers.read_json_msg_body(req)

        self._validate_alarm_definition(alarm_definition)

        tenant_id = helpers.get_tenant_id(req)

        # Mandatory positional args
        name = get_query_alarm_definition_name(alarm_definition)
        expression = get_query_alarm_definition_expression(alarm_definition)
        actions_enabled = (
            get_query_alarm_definition_actions_enabled(alarm_definition,
                                                       required=True))

        # Validator makes actions_enabled optional. So, check it here.
        if not actions_enabled:
            raise falcon.HTTPBadRequest('Bad request', 'Missing '
                                                       'actions_enabled')

        # Optional args
        description = get_query_alarm_definition_description(alarm_definition,
                                                             return_none=True)
        alarm_actions = get_query_alarm_definition_alarm_actions(
            alarm_definition, return_none=True)
        ok_actions = get_query_ok_actions(alarm_definition, return_none=True)
        undetermined_actions = get_query_alarm_definition_undetermined_actions(
            alarm_definition, return_none=True)
        match_by = get_query_alarm_definition_match_by(alarm_definition,
                                                       return_none=True)
        severity = get_query_alarm_definition_severity(alarm_definition,
                                                       return_none=True)

        result = self._alarm_definition_update_or_patch(tenant_id,
                                                        alarm_definition_id,
                                                        name,
                                                        expression,
                                                        actions_enabled,
                                                        description,
                                                        alarm_actions,
                                                        ok_actions,
                                                        undetermined_actions,
                                                        match_by,
                                                        severity,
                                                        patch=False)

        helpers.add_links_to_resource(result, req.uri)
        res.body = helpers.dumpit_utf8(result)
        res.status = falcon.HTTP_200
Пример #35
0
    def on_get(self, req, res, notification_method_id=None):
        if notification_method_id is None:
            helpers.validate_authorization(req, self._get_notifications_authorized_roles)
            tenant_id = helpers.get_tenant_id(req)
            sort_by = helpers.get_query_param(req, "sort_by", default_val=None)
            if sort_by is not None:
                if isinstance(sort_by, basestring):
                    sort_by = sort_by.split(",")

                allowed_sort_by = {"id", "name", "type", "address", "updated_at", "created_at"}

                validation.validate_sort_by(sort_by, allowed_sort_by)

            offset = helpers.get_query_param(req, "offset")
            limit = helpers.get_limit(req)
            result = self._list_notifications(tenant_id, req.uri, sort_by, offset, limit)
            res.body = helpers.dumpit_utf8(result)
            res.status = falcon.HTTP_200
        else:
            helpers.validate_authorization(req, self._get_notifications_authorized_roles)
            tenant_id = helpers.get_tenant_id(req)
            result = self._list_notification(tenant_id, notification_method_id, req.uri)
            res.body = helpers.dumpit_utf8(result)
            res.status = falcon.HTTP_200
Пример #36
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
Пример #37
0
    def on_patch(self, req, res, alarm_definition_id):

        helpers.validate_authorization(req, self._default_authorized_roles)

        alarm_definition = helpers.read_json_msg_body(req)

        tenant_id = helpers.get_tenant_id(req)

        # Optional args
        name = get_query_alarm_definition_name(alarm_definition,
                                               return_none=True)
        expression = get_query_alarm_definition_expression(alarm_definition,
                                                           return_none=True)
        actions_enabled = (
            get_query_alarm_definition_actions_enabled(alarm_definition,
                                                       return_none=True))

        description = get_query_alarm_definition_description(alarm_definition,
                                                             return_none=True)
        alarm_actions = get_query_alarm_definition_alarm_actions(
            alarm_definition, return_none=True)
        ok_actions = get_query_ok_actions(alarm_definition, return_none=True)
        undetermined_actions = get_query_alarm_definition_undetermined_actions(
            alarm_definition, return_none=True)
        match_by = get_query_alarm_definition_match_by(alarm_definition,
                                                       return_none=True)
        severity = get_query_alarm_definition_severity(alarm_definition,
                                                       return_none=True)

        result = self._alarm_definition_update_or_patch(tenant_id,
                                                        alarm_definition_id,
                                                        name,
                                                        expression,
                                                        actions_enabled,
                                                        description,
                                                        alarm_actions,
                                                        ok_actions,
                                                        undetermined_actions,
                                                        match_by,
                                                        severity,
                                                        patch=True)

        helpers.add_links_to_resource(result, req.uri)
        res.body = helpers.dumpit_utf8(result)
        res.status = falcon.HTTP_200