Skip to content

Commit c405821

Browse files
satterlynsa-softpayclaude
authored
Fix bulk commands only operating on first page of alerts (#401)
All bulk commands (delete, ack, close, tag, untag, shelve, unshelve, unack, update, action, note) called get_alerts() without pagination, which defaults to page 1 with 50 results. If more than 50 alerts matched, the remaining alerts were silently skipped. Add get_all_alerts() method that paginates through all results and use it in all 11 bulk commands. Fixes #227 Co-authored-by: Nick Satterly <nsa@softpay.io> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent bec4992 commit c405821

12 files changed

Lines changed: 22 additions & 11 deletions

File tree

alertaclient/api.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ def get_alerts(self, query=None, page=1, page_size=None):
110110
r = self.http.get('/alerts', query, page=page, page_size=page_size)
111111
return [Alert.parse(a) for a in r['alerts']]
112112

113+
def get_all_alerts(self, query=None, page_size=1000):
114+
alerts = []
115+
page = 1
116+
while True:
117+
r = self.http.get('/alerts', query, page=page, page_size=page_size)
118+
alerts.extend([Alert.parse(a) for a in r['alerts']])
119+
if len(r['alerts']) < page_size:
120+
break
121+
page += 1
122+
return alerts
123+
113124
def get_history(self, query=None, page=1, page_size=None):
114125
r = self.http.get('/alerts/history', query, page=page, page_size=page_size)
115126
return [RichHistory.parse(a) for a in r['history']]

alertaclient/commands/cmd_ack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ def cli(obj, ids, query, filters, text):
2020
else:
2121
query = build_query(filters)
2222
total, _, _ = client.get_count(query)
23-
ids = [a.id for a in client.get_alerts(query)]
23+
ids = [a.id for a in client.get_all_alerts(query)]
2424

2525
action_progressbar(client, action='ack', ids=ids, label=f'Acking {total} alerts', text=text)

alertaclient/commands/cmd_action.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def cli(obj, action, ids, query, filters, text):
2121
else:
2222
query = build_query(filters)
2323
total, _, _ = client.get_count(query)
24-
ids = [a.id for a in client.get_alerts(query)]
24+
ids = [a.id for a in client.get_all_alerts(query)]
2525

2626
label = f'Action ({action}) {total} alerts'
2727
action_progressbar(client, action=action, ids=ids, label=label, text=text)

alertaclient/commands/cmd_close.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ def cli(obj, ids, query, filters, text):
2020
else:
2121
query = build_query(filters)
2222
total, _, _ = client.get_count(query)
23-
ids = [a.id for a in client.get_alerts(query)]
23+
ids = [a.id for a in client.get_all_alerts(query)]
2424

2525
action_progressbar(client, action='close', ids=ids, label=f'Closing {total} alerts', text=text)

alertaclient/commands/cmd_delete.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def cli(obj, ids, query, filters):
2121
else:
2222
query = build_query(filters)
2323
total, _, _ = client.get_count(query)
24-
ids = [a.id for a in client.get_alerts(query)]
24+
ids = [a.id for a in client.get_all_alerts(query)]
2525

2626
with click.progressbar(ids, label=f'Deleting {total} alerts') as bar:
2727
for id in bar:

alertaclient/commands/cmd_note.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def cli(obj, alert_ids, query, filters, text, delete):
4040
else:
4141
query = build_query(filters)
4242
total, _, _ = client.get_count(query)
43-
alert_ids = [a.id for a in client.get_alerts(query)]
43+
alert_ids = [a.id for a in client.get_all_alerts(query)]
4444

4545
with click.progressbar(alert_ids, label=f'Add note to {total} alerts') as bar:
4646
for id in bar:

alertaclient/commands/cmd_shelve.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def cli(obj, ids, query, filters, timeout, text):
2121
else:
2222
query = build_query(filters)
2323
total, _, _ = client.get_count(query)
24-
ids = [a.id for a in client.get_alerts(query)]
24+
ids = [a.id for a in client.get_all_alerts(query)]
2525

2626
action_progressbar(client, action='shelve', ids=ids,
2727
label=f'Shelving {total} alerts', text=text, timeout=timeout)

alertaclient/commands/cmd_tag.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def cli(obj, ids, query, filters, tags):
2020
else:
2121
query = build_query(filters)
2222
total, _, _ = client.get_count(query)
23-
ids = [a.id for a in client.get_alerts(query)]
23+
ids = [a.id for a in client.get_all_alerts(query)]
2424

2525
with click.progressbar(ids, label=f'Tagging {total} alerts') as bar:
2626
for id in bar:

alertaclient/commands/cmd_unack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ def cli(obj, ids, query, filters, text):
2020
else:
2121
query = build_query(filters)
2222
total, _, _ = client.get_count(query)
23-
ids = [a.id for a in client.get_alerts(query)]
23+
ids = [a.id for a in client.get_all_alerts(query)]
2424

2525
action_progressbar(client, action='unack', ids=ids, label=f'Un-acking {total} alerts', text=text)

alertaclient/commands/cmd_unshelve.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ def cli(obj, ids, query, filters, text):
2020
else:
2121
query = build_query(filters)
2222
total, _, _ = client.get_count(query)
23-
ids = [a.id for a in client.get_alerts(query)]
23+
ids = [a.id for a in client.get_all_alerts(query)]
2424

2525
action_progressbar(client, 'unshelve', ids, label=f'Un-shelving {total} alerts', text=text)

0 commit comments

Comments
 (0)