Пример #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(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(result, req_uri, limit)
Пример #2
0
    def _list_notifications(self, tenant_id, uri, sort_by, offset, limit):

        rows = self._notifications_repo.list_notifications(tenant_id, sort_by, offset, limit)

        result = [self._build_notification_result(row, uri) for row in rows]

        return helpers.paginate(result, uri, limit)
Пример #3
0
    def _list_metrics(self, tenant_id, name, dimensions, req_uri, offset,
                      limit, start_timestamp, end_timestamp):

        result = self._metrics_repo.list_metrics(tenant_id, self._region, name,
                                                 dimensions, offset, limit,
                                                 start_timestamp,
                                                 end_timestamp)

        return helpers.paginate(result, req_uri, limit)
Пример #4
0
    def _list_metric_names(self, tenant_id, dimensions, req_uri, offset,
                           limit):

        result = self._metrics_repo.list_metric_names(tenant_id,
                                                      self._region,
                                                      dimensions,
                                                      offset, limit)

        return helpers.paginate(result, req_uri, limit)
Пример #5
0
    def _list_notifications(self, tenant_id, uri, sort_by, offset, limit):

        rows = self._notifications_repo.list_notifications(tenant_id, sort_by,
                                                           offset, limit)

        result = [self._build_notification_result(row,
                                                  uri) for row in rows]

        return helpers.paginate(result, uri, limit)
Пример #6
0
    def _list_metrics(self, tenant_id, name, dimensions, req_uri, offset,
                      limit, start_timestamp, end_timestamp):

        result = self._metrics_repo.list_metrics(tenant_id,
                                                 self._region,
                                                 name,
                                                 dimensions,
                                                 offset, limit,
                                                 start_timestamp,
                                                 end_timestamp)

        return helpers.paginate(result, req_uri, limit)
Пример #7
0
    def _alarm_definition_list(self, tenant_id, name, dimensions, req_uri,
                               offset, limit):

        alarm_definition_rows = (
            self._alarm_definitions_repo.get_alarm_definitions(
                tenant_id, name, dimensions, 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'])

            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'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(result, req_uri, limit)

        return result
Пример #8
0
    def _alarm_history_list(self, tenant_id, start_timestamp, end_timestamp,
                            dimensions, req_uri, offset, limit):

        # get_alarms expects 'metric_dimensions' for dimensions key.
        new_query_parms = {'metric_dimensions': dimensions}

        alarm_rows = self._alarms_repo.get_alarms(tenant_id, new_query_parms,
                                                  None, None)
        alarm_id_list = [alarm_row['alarm_id'] for alarm_row in alarm_rows]

        result = self._metrics_repo.alarm_history(tenant_id, alarm_id_list,
                                                  offset, limit,
                                                  start_timestamp,
                                                  end_timestamp)

        return helpers.paginate(result, req_uri, limit)
Пример #9
0
    def _alarm_history_list(self, tenant_id, start_timestamp,
                            end_timestamp, dimensions, req_uri, offset,
                            limit):

        # get_alarms expects 'metric_dimensions' for dimensions key.
        new_query_parms = {'metric_dimensions': dimensions}

        alarm_rows = self._alarms_repo.get_alarms(tenant_id, new_query_parms,
                                                  None, None)
        alarm_id_list = [alarm_row['alarm_id'] for alarm_row in alarm_rows]

        result = self._metrics_repo.alarm_history(tenant_id, alarm_id_list,
                                                  offset, limit,
                                                  start_timestamp,
                                                  end_timestamp)

        return helpers.paginate(result, req_uri, limit)
Пример #10
0
    def _alarm_history_list(self, tenant_id, start_timestamp, end_timestamp, query_parms, req_uri, offset, limit):

        # get_alarms expects 'metric_dimensions' for dimensions key.
        if "dimensions" in query_parms:
            dimensions = query_parms["dimensions"]
            if not isinstance(dimensions, list):
                dimensions = [dimensions]
            new_query_parms = {"metric_dimensions": dimensions}
        else:
            new_query_parms = {}

        alarm_rows = self._alarms_repo.get_alarms(tenant_id, new_query_parms, None, None)
        alarm_id_list = [alarm_row["alarm_id"] for alarm_row in alarm_rows]

        result = self._metrics_repo.alarm_history(
            tenant_id, alarm_id_list, offset, limit, start_timestamp, end_timestamp
        )

        return helpers.paginate(result, req_uri, limit)
Пример #11
0
    def _alarm_definition_list(self, tenant_id, name, dimensions, req_uri,
                               offset, limit):

        alarm_definition_rows = (
            self._alarm_definitions_repo.get_alarm_definitions(tenant_id, name,
                                                               dimensions,
                                                               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'])

            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'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(result, req_uri, limit)

        return result
Пример #12
0
    def _alarm_history(self, tenant_id, alarm_id, req_uri, offset, limit):

        result = self._metrics_repo.alarm_history(tenant_id, [alarm_id],
                                                  offset, limit)

        return helpers.paginate(result, req_uri, limit)
Пример #13
0
    def _alarm_history(self, tenant_id, alarm_id, req_uri, offset, limit):

        result = self._metrics_repo.alarm_history(tenant_id, alarm_id, offset,
                                                  limit)

        return helpers.paginate(result, req_uri, limit)
Пример #14
0
 def _list_notifications(self, uri, limit):
     rows = self._notification_method_type_repo.list_notification_method_types()
     result = [dict(type=row) for row in rows]
     return helpers.paginate(result, uri, limit)
Пример #15
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(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(result, req_uri, limit)
Пример #16
0
 def _list_notifications(self, uri, limit):
     rows = self._notification_method_type_repo.list_notification_method_types()
     result = [dict(type=row) for row in rows]
     return helpers.paginate(result, uri, limit)