| 1 |
# |
| 2 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 3 |
# not use this file except in compliance with the License. You may obtain |
| 4 |
# a copy of the License at |
| 5 |
# |
| 6 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 7 |
# |
| 8 |
# Unless required by applicable law or agreed to in writing, software |
| 9 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 10 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 11 |
# License for the specific language governing permissions and limitations |
| 12 |
# under the License. |
| 13 |
|
| 14 |
from oslo_serialization import jsonutils |
| 15 |
|
| 16 |
from aodhclient import utils |
| 17 |
from aodhclient.v2 import base |
| 18 |
|
| 19 |
|
| 20 |
class AlarmHistoryManager(base.Manager): |
| 21 |
|
| 22 |
url = "v2/alarms/%s/history" |
| 23 |
|
| 24 |
def get(self, alarm_id, limit=None, marker=None, sorts=None): |
| 25 |
"""Get history of an alarm |
| 26 |
|
| 27 |
:param alarm_id: ID of the alarm |
| 28 |
:type alarm_id: str |
| 29 |
:param limit: maximum number of resources to return |
| 30 |
:type limit: int |
| 31 |
:param marker: the last item of the previous page; we return the next |
| 32 |
results after this value. |
| 33 |
:type marker: str |
| 34 |
:param sorts: list of resource attributes to order by. |
| 35 |
:type sorts: list of str |
| 36 |
""" |
| 37 |
pagination = utils.get_pagination_options(limit, marker, sorts) |
| 38 |
url = self.url % alarm_id |
| 39 |
if pagination: |
| 40 |
url = f"{url}?{pagination}" |
| 41 |
return self._get(url).json() |
| 42 |
|
| 43 |
def search(self, query=None): |
| 44 |
"""List of history matching corresponding query |
| 45 |
|
| 46 |
:param query: The query dictionary |
| 47 |
:type query: dict |
| 48 |
""" |
| 49 |
query = {'filter': query} if query else {} |
| 50 |
url = "v2/query/alarms/history" |
| 51 |
return self._post(url, headers={'Content-Type': "application/json"}, |
| 52 |
data=jsonutils.dumps(query)).json() |