Skip to content

Commit

Permalink
fix: issue extra details on opsgenie sink (#1639)
Browse files Browse the repository at this point in the history
* fix: issue extra details on opsgenie sink

* Update opsgenie sink configuration doc
  • Loading branch information
sk4mi authored Nov 20, 2024
1 parent a58fee3 commit 2400e27
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
7 changes: 7 additions & 0 deletions docs/configuration/sinks/Opsgenie.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ Robusta can report issues and events in your Kubernetes cluster to the OpsGenie

To configure OpsGenie, We need an OpsGenie API key. It can be configured using the OpsGenie team integration.

Customizing Opsgenie Extra Details
------------------------------------------------

We can add Prometheus alert labels into Opsgenie alert extra details by setting `extra_details_labels` to `true` in the `sinksConfig` section.


Configuring the OpsGenie sink
------------------------------------------------

Expand All @@ -21,6 +27,7 @@ Configuring the OpsGenie sink
- "sre"
tags:
- "prod a"
extra_details_labels: false # optional, default is false
Save the file and run

Expand Down
8 changes: 3 additions & 5 deletions src/robusta/core/sinks/opsgenie/opsgenie_sink.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(self, sink_config: OpsGenieSinkConfigWrapper, registry):
self.api_key = sink_config.opsgenie_sink.api_key
self.teams = sink_config.opsgenie_sink.teams
self.tags = sink_config.opsgenie_sink.tags
self.extra_details_labels = sink_config.opsgenie_sink.extra_details_labels

opsgenie_sdk.configuration.Configuration.set_default(None)
self.conf = opsgenie_sdk.configuration.Configuration()
Expand All @@ -32,9 +33,6 @@ def __init__(self, sink_config: OpsGenieSinkConfigWrapper, registry):
if sink_config.opsgenie_sink.host is not None:
self.conf.host = sink_config.opsgenie_sink.host

if sink_config.opsgenie_sink.extra_details_labels is not None:
self.conf.extra_details_labels = sink_config.opsgenie_sink.extra_details_labels

self.api_client = opsgenie_sdk.api_client.ApiClient(configuration=self.conf)
self.alert_api = opsgenie_sdk.AlertApi(api_client=self.api_client)

Expand Down Expand Up @@ -105,9 +103,9 @@ def __to_details(self, finding: Finding) -> dict:
lower_details_key = [k.lower() for k in details.keys()]
# If there are extra details labels in the config extra_details_labels,
# add them without altering the already existing details.
if self.conf.extra_details_labels:
if self.extra_details_labels:
for key, value in finding.subject.labels:
if key in self.conf.extra_details_labels and not key in lower_details_key:
if not key in lower_details_key:
details[key] = value
return details

Expand Down
2 changes: 1 addition & 1 deletion src/robusta/core/sinks/opsgenie/opsgenie_sink_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class OpsGenieSinkParams(SinkBaseParams):
teams: List[str] = []
tags: List[str] = []
host: Optional[str] = None # NOTE: If None, the default value will be used from opsgenie_sdk
extra_details_labels: Optional[bool] = None
extra_details_labels: Optional[bool] = False

@classmethod
def _get_sink_type(cls):
Expand Down

0 comments on commit 2400e27

Please sign in to comment.