-
-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathcmd_unack.py
More file actions
25 lines (21 loc) · 1.01 KB
/
cmd_unack.py
File metadata and controls
25 lines (21 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import click
from alertaclient.utils import action_progressbar, build_query
@click.command('unack', short_help='Un-acknowledge alerts')
@click.option('--ids', '-i', metavar='ID', multiple=True, help='List of alert IDs (can use short 8-char id)')
@click.option('--query', '-q', 'query', metavar='QUERY', help='severity:"warning" AND resource:web')
@click.option('--filter', '-f', 'filters', metavar='FILTER', multiple=True, help='KEY=VALUE eg. serverity=warning resource=web')
@click.option('--text', help='Message associated with status change')
@click.pass_obj
def cli(obj, ids, query, filters, text):
"""Set alert status to 'open'."""
client = obj['client']
if ids:
total = len(ids)
else:
if query:
query = [('q', query)]
else:
query = build_query(filters)
total, _, _ = client.get_count(query)
ids = [a.id for a in client.get_all_alerts(query)]
action_progressbar(client, action='unack', ids=ids, label=f'Un-acking {total} alerts', text=text)