예제 #1
0
    def _list_notifications(self, tenant_id, uri, offset):

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

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

        return helpers.paginate(result, uri, offset)
예제 #2
0
    def _list_notifications(self, tenant_id, uri, offset):

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

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

        return helpers.paginate(result, uri, offset)
예제 #3
0
    def _alarm_list(self, req_uri, tenant_id, query_parms, offset):

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

        result = []

        if not alarm_rows:
            return result

        # 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),
                                              rel=None)

                metrics = []
                alarm = {
                    u'id': alarm_row['alarm_id'],
                    u'metrics': metrics,
                    u'state': alarm_row['state'],
                    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, offset)
예제 #4
0
    def _alarm_definition_list(self, tenant_id, name, dimensions, req_uri,
                               offset):

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

        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'].decode('utf8'),
                u'name':
                alarm_definition_row['name'].decode("utf8"),
                u'description':
                alarm_definition_row['description'].decode('utf8')
                if alarm_definition_row['description'] else u'',
                u'expression':
                alarm_definition_row['expression'].decode('utf8'),
                u'match_by':
                match_by,
                u'severity':
                alarm_definition_row['severity'].decode('utf8').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, offset)

        return result
예제 #5
0
    def _alarm_list(self, req_uri, tenant_id, query_parms, offset):

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

        result = []

        if not alarm_rows:
            return result

        # 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),
                                              rel=None)

                metrics = []
                alarm = {u'id': alarm_row['alarm_id'], u'metrics': metrics,
                         u'state': alarm_row['state'],
                         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, offset)
예제 #6
0
    def _stream_definition_list(self, tenant_id, name, req_uri,
                                offset, limit):

        stream_definition_rows = (
            self._stream_definitions_repo.get_stream_definitions(
                tenant_id, name, offset, limit))
        result = []
        for stream_definition_row in stream_definition_rows:
            sd = self._build_stream_definition_show_result(
                stream_definition_row)
            helpers.add_links_to_resource(sd, req_uri)
            result.append(sd)

        result = helpers.paginate(result, req_uri, offset)

        return result
예제 #7
0
    def _alarm_history_list(self, tenant_id, start_timestamp, end_timestamp,
                            query_parms, req_uri, offset):

        # get_alarms expects 'metric_dimensions' for dimensions key.
        if 'dimensions' in query_parms:
            new_query_parms = {'metric_dimensions': query_parms['dimensions']}
        else:
            new_query_parms = {}

        alarm_rows = self._alarms_repo.get_alarms(tenant_id, new_query_parms)
        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, start_timestamp,
                                                  end_timestamp)

        return helpers.paginate(result, req_uri, offset)
예제 #8
0
    def _alarm_history_list(self, tenant_id, start_timestamp,
                            end_timestamp, query_parms, req_uri, offset):

        # get_alarms expects 'metric_dimensions' for dimensions key.
        if 'dimensions' in query_parms:
            new_query_parms = {'metric_dimensions': query_parms['dimensions']}
        else:
            new_query_parms = {}

        alarm_rows = self._alarms_repo.get_alarms(tenant_id, new_query_parms)
        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,
                                                  start_timestamp,
                                                  end_timestamp)

        return helpers.paginate(result, req_uri, offset)
예제 #9
0
    def _list_metrics(self, tenant_id, name, dimensions, req_uri, offset):
        """Query the metric repo for the metrics, format them and return them.

        :param tenant_id:
        :param name:
        :param dimensions:
        :raises falcon.HTTPServiceUnavailable
        """

        try:
            result = self._metrics_repo.list_metrics(tenant_id, self._region,
                                                     name, dimensions, offset)

            return helpers.paginate(result, req_uri, offset)

        except Exception as ex:
            LOG.exception(ex)
            raise falcon.HTTPServiceUnavailable('Service unavailable',
                                                ex.message, 60)
예제 #10
0
    def _alarm_definition_list(self, tenant_id, name, dimensions, req_uri,
                               offset):

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

        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'].decode('utf8'),
                  u'name': alarm_definition_row['name'].decode("utf8"),
                  u'description': alarm_definition_row['description'].decode(
                      'utf8') if alarm_definition_row['description'] else u'',
                  u'expression': alarm_definition_row['expression'].decode(
                      'utf8'), u'match_by': match_by,
                  u'severity': alarm_definition_row['severity'].decode(
                      'utf8'),
                  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, offset)

        return result
예제 #11
0
    def _list_metrics(self, tenant_id, name, dimensions, req_uri, offset):
        """Query the metric repo for the metrics, format them and return them.

        :param tenant_id:
        :param name:
        :param dimensions:
        :raises falcon.HTTPServiceUnavailable
        """

        try:
            result = self._metrics_repo.list_metrics(tenant_id,
                                                     self._region,
                                                     name,
                                                     dimensions, offset)

            return helpers.paginate(result, req_uri, offset)

        except Exception as ex:
            LOG.exception(ex)
            raise falcon.HTTPServiceUnavailable('Service unavailable',
                                                ex.message, 60)
예제 #12
0
 def _list_events(self, tenant_id, uri, offset, limit):
     rows = self._events_repo.list_events(tenant_id, offset, limit)
     return helpers.paginate(self._build_events(rows), uri, offset)
예제 #13
0
    def _alarm_history(self, tenant_id, alarm_id, req_uri, offset):

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

        return helpers.paginate(result, req_uri, offset)
예제 #14
0
    def _alarm_history(self, tenant_id, alarm_id, req_uri, offset):

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

        return helpers.paginate(result, req_uri, offset)