Example #1
0
 def get_alarm_changes(self,
                       alarm_id,
                       on_behalf_of,
                       user=None,
                       project=None,
                       type=None,
                       start_timestamp=None,
                       start_timestamp_op=None,
                       end_timestamp=None,
                       end_timestamp_op=None):
     q = make_query(alarm_id=alarm_id,
                    on_behalf_of=on_behalf_of,
                    type=type,
                    user_id=user,
                    project_id=project)
     start_row, end_row = make_timestamp_query(_make_general_rowkey_scan,
                                               start=start_timestamp,
                                               start_op=start_timestamp_op,
                                               end=end_timestamp,
                                               end_op=end_timestamp_op,
                                               bounds_only=True,
                                               some_id=alarm_id)
     with self.conn_pool.connection() as conn:
         alarm_history_table = conn.table(self.ALARM_HISTORY_TABLE)
         gen = alarm_history_table.scan(filter=q,
                                        row_start=start_row,
                                        row_stop=end_row)
         for ignored, data in gen:
             stored_entry = deserialize_entry(data)[0]
             yield models.AlarmChange(**stored_entry)
Example #2
0
 def _row_to_alarm_change_model(row):
     return api_models.AlarmChange(event_id=row.event_id,
                                   alarm_id=row.alarm_id,
                                   type=row.type,
                                   detail=row.detail,
                                   user_id=row.user_id,
                                   project_id=row.project_id,
                                   on_behalf_of=row.on_behalf_of,
                                   timestamp=row.timestamp)
Example #3
0
    def get_alarm_changes(self,
                          alarm_id,
                          on_behalf_of,
                          user=None,
                          project=None,
                          type=None,
                          start_timestamp=None,
                          start_timestamp_op=None,
                          end_timestamp=None,
                          end_timestamp_op=None):
        """Yields list of AlarmChanges describing alarm history

        Changes are always sorted in reverse order of occurrence, given
        the importance of currency.

        Segregation for non-administrative users is done on the basis
        of the on_behalf_of parameter. This allows such users to have
        visibility on both the changes initiated by themselves directly
        (generally creation, rule changes, or deletion) and also on those
        changes initiated on their behalf by the alarming service (state
        transitions after alarm thresholds are crossed).

        :param alarm_id: ID of alarm to return changes for
        :param on_behalf_of: ID of tenant to scope changes query (None for
                             administrative user, indicating all projects)
        :param user: Optional ID of user to return changes for
        :param project: Optional ID of project to return changes for
        :project type: Optional change type
        :param start_timestamp: Optional modified timestamp start range
        :param start_timestamp_op: Optional timestamp start range operation
        :param end_timestamp: Optional modified timestamp end range
        :param end_timestamp_op: Optional timestamp end range operation
        """
        q = dict(alarm_id=alarm_id)
        if on_behalf_of is not None:
            q['on_behalf_of'] = on_behalf_of
        if user is not None:
            q['user_id'] = user
        if project is not None:
            q['project_id'] = project
        if type is not None:
            q['type'] = type
        if start_timestamp or end_timestamp:
            ts_range = make_timestamp_range(start_timestamp, end_timestamp,
                                            start_timestamp_op,
                                            end_timestamp_op)
            if ts_range:
                q['timestamp'] = ts_range

        sort = [("timestamp", pymongo.DESCENDING)]
        for alarm_change in self.db.alarm_history.find(q, sort=sort):
            ac = {}
            ac.update(alarm_change)
            del ac['_id']
            yield models.AlarmChange(**ac)
Example #4
0
    def _retrieve_alarm_changes(self, query_filter, orderby, limit):
        if limit is not None:
            alarms_history = self.db.alarm_history.find(query_filter,
                                                        limit=limit,
                                                        sort=orderby)
        else:
            alarms_history = self.db.alarm_history.find(query_filter,
                                                        sort=orderby)

        for alarm_history in alarms_history:
            ah = {}
            ah.update(alarm_history)
            del ah['_id']
            yield models.AlarmChange(**ah)