@@ -32,6 +32,9 @@ def __init__(self, sink_config: OpsGenieSinkConfigWrapper, registry):
3232 if sink_config .opsgenie_sink .host is not None :
3333 self .conf .host = sink_config .opsgenie_sink .host
3434
35+ if sink_config .opsgenie_sink .extra_details_labels is not None :
36+ self .conf .extra_details_labels = sink_config .opsgenie_sink .extra_details_labels
37+
3538 self .api_client = opsgenie_sdk .api_client .ApiClient (configuration = self .conf )
3639 self .alert_api = opsgenie_sdk .AlertApi (api_client = self .api_client )
3740
@@ -52,20 +55,15 @@ def __close_alert(self, finding: Finding):
5255
5356 def __open_alert (self , finding : Finding , platform_enabled : bool ):
5457 description = self .__to_description (finding , platform_enabled )
58+ details = self .__to_details (finding )
5559 self .tags .insert (0 , self .cluster_name )
5660 body = opsgenie_sdk .CreateAlertPayload (
5761 source = "Robusta" ,
5862 message = finding .title ,
5963 description = description ,
6064 alias = finding .fingerprint ,
6165 responders = [{"name" : team , "type" : "team" } for team in self .teams ],
62- details = {
63- "Resource" : finding .subject .name ,
64- "Cluster" : self .cluster_name ,
65- "Namespace" : finding .subject .namespace ,
66- "Node" : finding .subject .node ,
67- "Source" : str (finding .source .name ),
68- },
66+ details = details ,
6967 tags = self .tags ,
7068 entity = finding .service_key ,
7169 priority = PRIORITY_MAP .get (finding .severity , "P3" ),
@@ -96,6 +94,23 @@ def __to_description(self, finding: Finding, platform_enabled: bool) -> str:
9694
9795 return f"{ description } { self .__enrichments_as_text (finding .enrichments )} "
9896
97+ def __to_details (self , finding : Finding ) -> dict :
98+ details = {
99+ "Resource" : finding .subject .name ,
100+ "Cluster" : self .cluster_name ,
101+ "Namespace" : finding .subject .namespace ,
102+ "Node" : finding .subject .node ,
103+ "Source" : str (finding .source .name ),
104+ }
105+ lower_details_key = [k .lower () for k in details .keys ()]
106+ # If there are extra details labels in the config extra_details_labels,
107+ # add them without altering the already existing details.
108+ if self .conf .extra_details_labels :
109+ for key , value in finding .subject .labels :
110+ if key in self .conf .extra_details_labels and not key in lower_details_key :
111+ details [key ] = value
112+ return details
113+
99114 @classmethod
100115 def __enrichments_as_text (cls , enrichments : List [Enrichment ]) -> str :
101116 transformer = Transformer ()
0 commit comments