Skip to content

Commit dfc7f6e

Browse files
committed
pr changes
1 parent cec9859 commit dfc7f6e

3 files changed

Lines changed: 9 additions & 7 deletions

File tree

docs/configuration/sinks/Opsgenie.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ The OpsGenie sink supports static and dynamic team routing, optional fallback te
2626
api_key: OpsGenie integration API key # configured from OpsGenie team integration
2727
teams:
2828
- "noc" # Static team
29-
- "$labels.team" # Dynamic team routing based on alert label
29+
- "$labels.team" # Dynamic routing based on alert labels or annotations.
30+
# For example, if an alert subject has `team=infra`, it routes to the "infra" team.
31+
# Use $labels.<label_name> or $annotations.<label_name> as placeholders.
3032
default_team: "oncall" # Optional fallback team for Dynamic team routing
3133
tags:
3234
- "prod a"

src/robusta/core/sinks/opsgenie/opsgenie_sink.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,25 +97,25 @@ def __get_teams(self, finding: Finding) -> List[str]:
9797
finding.subject.labels,
9898
finding.subject.annotations,
9999
)
100-
if team: # Only add non-null teams
100+
if team and team not in teams: # Only add non-null, de-duped teams
101101
teams.append(team)
102102
else:
103103
# Use static team name directly
104-
teams.append(team_template)
104+
if team_template not in teams: # Only add de-duped teams
105+
teams.append(team_template)
105106
except Exception as e:
106107
logging.warning(
107108
f"Failed to process team template {team_template} for alert subject {finding.service_key}: {e}"
108109
)
109110
continue
110111

111112
# If no teams were resolved and we have a default team, use it
112-
if not teams and self.default_team:
113+
if not teams and self.default_team and self.default_team not in teams:
113114
teams.append(self.default_team)
114115
elif not teams and self.teams: # dynamic routing failed and no default team configured
115116
logging.warning(f"No valid teams resolved for finding {finding.title}. Alert may not be routed properly.")
116117

117-
# Remove duplicates
118-
return list(set(teams))
118+
return teams
119119

120120
def __open_alert(self, finding: Finding, platform_enabled: bool):
121121
description = self.__to_description(finding, platform_enabled)

tests/test_opsgenie_sink.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def test_get_teams_with_missing_label():
6060
sink = create_sink(teams=["$labels.team", "$annotations.owner"], default_team="default-team")
6161
finding = create_finding(labels={"environment": "prod"}, annotations={"owner": "ops-team"}) # missing team label
6262
teams = sink._OpsGenieSink__get_teams(finding)
63-
assert teams == ["ops-team", "default-team"]
63+
assert teams == ["default-team", "ops-team"]
6464

6565

6666
def test_get_teams_with_missing_annotation():

0 commit comments

Comments
 (0)