@@ -223,9 +223,19 @@ def query_metrics_clusters(
223223 return sorted (clusters )
224224
225225
226+ _FIRING_STATES = {"alerting" , "firing" }
227+
228+
226229def is_firing (entry : dict ) -> bool :
227- """Check if an alert entry represents a firing alert."""
228- return entry ["state" ].lower () == "alerting"
230+ """Check if an alert entry indicates the alert was firing during the window.
231+
232+ An alert was firing if it transitioned INTO a firing state (newState is firing)
233+ or transitioned OUT of a firing state (prevState is firing, meaning it was
234+ firing before it resolved).
235+ """
236+ state = entry .get ("state" , "" ).lower ()
237+ prev = entry .get ("previous_state" , "" ).lower ()
238+ return state in _FIRING_STATES or prev in _FIRING_STATES
229239
230240
231241def print_report (
@@ -379,6 +389,12 @@ def main():
379389 entries = [format_alert_entry (a ) for a in matching ]
380390 entries .sort (key = lambda e : e ["timestamp" ])
381391
392+ firing = [e for e in entries if is_firing (e )]
393+ print (f"=== Alert Summary ===" )
394+ print (f" { len (annotations )} alert annotations found, { len (matching )} matched monitored rules." )
395+ print (f" { len (firing )} alerts were firing during this time window." )
396+ print ()
397+
382398 # Query Prometheus for metrics coverage if expected clusters specified
383399 metrics_clusters = None
384400 if args .expected_clusters > 0 :
0 commit comments