0
0
Fork 0
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 ()

This commit is contained in:
Nick Satterly 2020-01-18 22:12:13 +01:00 committed by GitHub
commit 8889a9a8c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions
alerta/database/backends/postgres

View file

@ -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

View file

@ -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))')