Exemple #1
0
    def _alarm_list(self, req_uri, tenant_id, query_parms, offset, limit):

        alarm_rows = self._alarms_repo.get_alarms(tenant_id, query_parms,
                                                  offset, limit)

        result = []
        if not alarm_rows:
            return helpers.paginate_alarming(result, req_uri, limit)

        # Forward declaration
        alarm = {}
        prev_alarm_id = None
        for alarm_row in alarm_rows:
            if prev_alarm_id != alarm_row['alarm_id']:
                if prev_alarm_id is not None:
                    result.append(alarm)

                ad = {u'id': alarm_row['alarm_definition_id'],
                      u'name': alarm_row['alarm_definition_name'],
                      u'severity': alarm_row['severity'], }
                helpers.add_links_to_resource(ad,
                                              re.sub('alarms',
                                                     'alarm-definitions',
                                                     req_uri))

                metrics = []
                alarm = {u'id': alarm_row['alarm_id'], u'metrics': metrics,
                         u'state': alarm_row['state'],
                         u'lifecycle_state': alarm_row['lifecycle_state'],
                         u'link': alarm_row['link'],
                         u'state_updated_timestamp':
                             alarm_row['state_updated_timestamp'].isoformat() +
                             'Z',
                         u'updated_timestamp':
                             alarm_row['updated_timestamp'].isoformat() + 'Z',
                         u'created_timestamp':
                             alarm_row['created_timestamp'].isoformat() + 'Z',
                         u'alarm_definition': ad}
                helpers.add_links_to_resource(alarm, req_uri)

                prev_alarm_id = alarm_row['alarm_id']

            dimensions = {}
            metric = {u'name': alarm_row['metric_name'],
                      u'dimensions': dimensions}

            if alarm_row['metric_dimensions']:
                for dimension in alarm_row['metric_dimensions'].split(','):
                    parsed_dimension = dimension.split('=')
                    dimensions[parsed_dimension[0]] = parsed_dimension[1]

            metrics.append(metric)

        result.append(alarm)

        return helpers.paginate_alarming(result, req_uri, limit)
Exemple #2
0
    def _alarm_list(self, req_uri, tenant_id, query_parms, offset, limit):

        alarm_rows = self._alarms_repo.get_alarms(tenant_id, query_parms, offset, limit)

        result = []
        if not alarm_rows:
            return helpers.paginate_alarming(result, req_uri, limit)

        # Forward declaration
        alarm = {}
        prev_alarm_id = None
        for alarm_row in alarm_rows:
            if prev_alarm_id != alarm_row["alarm_id"]:
                if prev_alarm_id is not None:
                    Alarms._render_alarm(alarm)
                    result.append(alarm)

                ad = {
                    u"id": alarm_row["alarm_definition_id"],
                    u"name": alarm_row["alarm_definition_name"],
                    u"description": alarm_row["alarm_definition_description"],
                    u"severity": alarm_row["severity"],
                }
                helpers.add_links_to_resource(ad, re.sub("alarms", "alarm-definitions", req_uri))

                metrics = []
                alarm = {
                    u"id": alarm_row["alarm_id"],
                    u"metrics": metrics,
                    u"state": alarm_row["state"],
                    u"lifecycle_state": alarm_row["lifecycle_state"],
                    u"link": alarm_row["link"],
                    u"state_updated_timestamp": alarm_row["state_updated_timestamp"].isoformat() + "Z",
                    u"updated_timestamp": alarm_row["updated_timestamp"].isoformat() + "Z",
                    u"created_timestamp": alarm_row["created_timestamp"].isoformat() + "Z",
                    u"alarm_definition": ad,
                }
                helpers.add_links_to_resource(alarm, req_uri)

                prev_alarm_id = alarm_row["alarm_id"]

            dimensions = {}
            metric = {u"name": alarm_row["metric_name"], u"dimensions": dimensions}

            if alarm_row["metric_dimensions"]:
                for dimension in alarm_row["metric_dimensions"].split(","):
                    parsed_dimension = dimension.split("=")
                    dimensions[parsed_dimension[0]] = parsed_dimension[1]

            metrics.append(metric)

        Alarms._render_alarm(alarm)

        result.append(alarm)

        return helpers.paginate_alarming(result, req_uri, limit)
    def _alarm_definition_list(self, tenant_id, name, dimensions, severity,
                               req_uri, sort_by, offset, limit):

        alarm_definition_rows = (
            self._alarm_definitions_repo.get_alarm_definitions(
                tenant_id, name, dimensions, severity, sort_by, offset, limit))

        result = []
        for alarm_definition_row in alarm_definition_rows:
            match_by = get_comma_separated_str_as_list(
                alarm_definition_row['match_by'])

            alarm_actions_list = get_comma_separated_str_as_list(
                alarm_definition_row['alarm_actions'])

            ok_actions_list = get_comma_separated_str_as_list(
                alarm_definition_row['ok_actions'])

            undetermined_actions_list = get_comma_separated_str_as_list(
                alarm_definition_row['undetermined_actions'])

            expression = alarm_definition_row['expression']
            is_deterministic = is_definition_deterministic(expression)
            ad = {
                u'id':
                alarm_definition_row['id'],
                u'name':
                alarm_definition_row['name'],
                u'description':
                alarm_definition_row['description'] if
                (alarm_definition_row['description']) else u'',
                u'expression':
                alarm_definition_row['expression'],
                u'deterministic':
                is_deterministic,
                u'match_by':
                match_by,
                u'severity':
                alarm_definition_row['severity'].upper(),
                u'actions_enabled':
                alarm_definition_row['actions_enabled'] == 1,
                u'alarm_actions':
                alarm_actions_list,
                u'ok_actions':
                ok_actions_list,
                u'undetermined_actions':
                undetermined_actions_list
            }

            helpers.add_links_to_resource(ad, req_uri)
            result.append(ad)

        result = helpers.paginate_alarming(result, req_uri, limit)

        return result
    def _alarm_definition_list(self, tenant_id, name, dimensions, severity, req_uri, sort_by,
                               offset, limit):

        alarm_definition_rows = (
            self._alarm_definitions_repo.get_alarm_definitions(tenant_id, name,
                                                               dimensions, severity, sort_by,
                                                               offset, limit))

        result = []
        for alarm_definition_row in alarm_definition_rows:
            match_by = get_comma_separated_str_as_list(
                alarm_definition_row['match_by'])

            alarm_actions_list = get_comma_separated_str_as_list(
                alarm_definition_row['alarm_actions'])

            ok_actions_list = get_comma_separated_str_as_list(
                alarm_definition_row['ok_actions'])

            undetermined_actions_list = get_comma_separated_str_as_list(
                alarm_definition_row['undetermined_actions'])

            expression = alarm_definition_row['expression']
            is_deterministic = is_definition_deterministic(expression)
            ad = {u'id': alarm_definition_row['id'],
                  u'name': alarm_definition_row['name'],
                  u'description': alarm_definition_row['description'] if (
                      alarm_definition_row['description']) else u'',
                  u'expression': alarm_definition_row['expression'],
                  u'deterministic': is_deterministic,
                  u'match_by': match_by,
                  u'severity': alarm_definition_row['severity'].upper(),
                  u'actions_enabled':
                      alarm_definition_row['actions_enabled'] == 1,
                  u'alarm_actions': alarm_actions_list,
                  u'ok_actions': ok_actions_list,
                  u'undetermined_actions': undetermined_actions_list}

            helpers.add_links_to_resource(ad, req_uri)
            result.append(ad)

        result = helpers.paginate_alarming(result, req_uri, limit)

        return result