@@ -34,44 +34,52 @@ def ack_opsgenie_alert_from_slack(event: ExecutionBaseEvent, params: OpsGenieAck
3434 """
3535 Sends an ack to opsgenie alert
3636 """
37- def ack_opsgenie_alert () -> None :
38- event .emit_event (
39- "opsgenie_ack" ,
40- fingerprint = params .alert_fingerprint ,
41- user = params .slack_username ,
42- note = f"This alert was ack-ed from a Robusta Slack message by { params .slack_username } "
43- )
44-
45- if not params .slack_message :
46- logging .warning ("No action Slack found, unable to update slack message." )
47- return
48-
49- # slack action block
50- actions = params .slack_message .get ("actions" , [])
51- if not actions :
52- logging .warning ("No actions found in the Slack message." )
53- return
54-
55- block_id = actions [0 ].get ("block_id" )
56- if not block_id :
57- logging .warning ("Block ID is missing in the first action of the Slack message." )
58- return
59-
60- event .emit_event (
61- "replace_callback_with_string" ,
62- slack_message = params .slack_message ,
63- block_id = block_id ,
64- message_string = f"✅ *OpsGenie Ack by @{ params .slack_username } *"
65- )
66-
67- ack_opsgenie_alert ()
37+ event .emit_event (
38+ "opsgenie_ack" ,
39+ fingerprint = params .alert_fingerprint ,
40+ user = params .slack_username ,
41+ note = f"This alert was ack-ed from a Robusta Slack message by { params .slack_username } "
42+ )
43+
44+ if not params .slack_message :
45+ logging .warning ("No action Slack found, unable to update slack message." )
46+ return
47+
48+ # slack action block
49+ actions = params .slack_message .get ("actions" , [])
50+ if not actions :
51+ logging .warning ("No actions found in the Slack message." )
52+ return
53+
54+ block_id = actions [0 ].get ("block_id" )
55+ if not block_id :
56+ logging .warning ("Block ID is missing in the first action of the Slack message." )
57+ return
58+
59+ event .emit_event (
60+ "replace_callback_with_string" ,
61+ slack_message = params .slack_message ,
62+ block_id = block_id ,
63+ message_string = f"✅ *OpsGenie Ack by @{ params .slack_username } *"
64+ )
65+
66+
67+ class OpsGenieLinkParams (ActionParams ):
68+ """
69+ :var url_base: The base url for your opsgenie account for example: "robusta-test-url.app.eu.opsgenie.com"
70+ """
71+ url_base : str
6872
6973
7074@action
71- def ack_slack_opsgenie_enricher (alert : PrometheusKubernetesAlert ):
75+ def opsgenie_slack_enricher (alert : PrometheusKubernetesAlert , params : OpsGenieLinkParams ):
7276 """
73- Add a button to the alert - clicking it will ask chat gpt to help find a solution.
77+ Add a button to the alert - clicking it will ask chat gpt to help find a solution.
7478 """
79+ normalized_url_base = normalize_url_base (params .url_base )
80+ alert .add_link (Link (url = f"https://{ normalized_url_base } /alert/list?query=alias:{ alert .alert .fingerprint } " ,
81+ name = "OpsGenie Alert" , type = LinkType .OPSGENIE_LIST_ALERT_BY_ALIAS ))
82+
7583 alert .add_enrichment (
7684 [
7785 CallbackBlock (
@@ -88,12 +96,6 @@ def ack_slack_opsgenie_enricher(alert: PrometheusKubernetesAlert):
8896 )
8997
9098
91- class OpsGenieLinkParams (ActionParams ):
92- """
93- :var url_base: The base url for your opsgenie account for example: "robusta-test-url.app.eu.opsgenie.com"
94- """
95- url_base : Optional [str ] = None
96-
9799
98100def normalize_url_base (url_base : str ) -> str :
99101 """
@@ -104,13 +106,4 @@ def normalize_url_base(url_base: str) -> str:
104106 url_base = parsed_url .netloc if parsed_url .netloc else parsed_url .path
105107
106108 # Remove trailing slash if present
107- return url_base .rstrip ('/' )
108-
109-
110- @action
111- def opsgenie_link_enricher (alert : PrometheusKubernetesAlert , params : OpsGenieLinkParams ):
112- """
113- Adds a link to finding of for the opsgenie alert.
114- """
115- normalized_url_base = normalize_url_base (params .url_base )
116- alert .add_link (Link (url = f"https://{ normalized_url_base } /alert/list?query=alias:{ alert .alert .fingerprint } " , name = "OpsGenie Alert" , type = LinkType .OPSGENIE ))
109+ return url_base .rstrip ('/' )
0 commit comments