mirror of
https://github.com/alerta/alerta.git
synced 2025-08-25 17:20:31 +00:00
Get the canonical alert id when query history by id (#1125)
This commit is contained in:
parent
a8e66b457b
commit
8889a9a8c7
2 changed files with 9 additions and 1 deletions
|
@ -423,6 +423,14 @@ class Backend(Database):
|
|||
|
||||
def get_history(self, query=None, page=None, page_size=None):
|
||||
query = query or Query()
|
||||
if 'id' in query.vars:
|
||||
select = """
|
||||
SELECT a.id
|
||||
FROM alerts a, unnest(history[1:{limit}]) h
|
||||
WHERE h.id LIKE %(id)s
|
||||
""".format(limit=current_app.config['HISTORY_LIMIT'])
|
||||
query.vars['id'] = self._fetchone(select, query.vars)
|
||||
|
||||
select = """
|
||||
SELECT resource, environment, service, "group", tags, attributes, origin, customer, history, h.*
|
||||
FROM alerts, unnest(history[1:{limit}]) h
|
||||
|
|
|
@ -89,7 +89,7 @@ class QueryBuilderImpl(QueryBuilder):
|
|||
# id
|
||||
ids = params.getlist('id')
|
||||
if len(ids) == 1:
|
||||
query.append('AND (id LIKE %(id)s OR last_receive_id LIKE %(id)s)')
|
||||
query.append('AND (alerts.id LIKE %(id)s OR last_receive_id LIKE %(id)s)')
|
||||
qvars['id'] = ids[0] + '%'
|
||||
elif ids:
|
||||
query.append('AND (id ~* (%(regex_id)s) OR last_receive_id ~* (%(regex_id)s))')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue