-
-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathcmd_tag.py
More file actions
27 lines (23 loc) · 1.02 KB
/
cmd_tag.py
File metadata and controls
27 lines (23 loc) · 1.02 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
26
27
import click
from alertaclient.utils import build_query
@click.command('tag', short_help='Tag 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('--tag', '-T', 'tags', required=True, multiple=True, help='List of tags')
@click.pass_obj
def cli(obj, ids, query, filters, tags):
"""Add tags to alerts."""
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)]
with click.progressbar(ids, label=f'Tagging {total} alerts') as bar:
for id in bar:
client.tag_alert(id, tags)