Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: issue extra details on opsgenie sink #1639

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading