Skip to content

Commit

Permalink
Recognize sendResolved property of alertmanager (#144)
Browse files Browse the repository at this point in the history
feat: pick up sendResolved
fix: typos
  • Loading branch information
celaus authored Sep 19, 2024
1 parent 73350f7 commit ce4a7a0
Show file tree
Hide file tree
Showing 16 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ spec:
key: "webhook-url" # Key in the Kubernetes Secret
- name: opsgenie-general
opsgenieConfigs:
- apiURL: https://api.opsgenie.com/v2/alerts
- sendResolved: true
apiURL: https://api.opsgenie.com/v2/alerts
- name: slack-default
slackConfigs:
- apiURL:
- sendResolved: false
apiURL:
name: "slack-webhook-secret" # Name of the Kubernetes Secret
key: "webhook-url" # Key in the Kubernetes Secret
21 changes: 14 additions & 7 deletions controllers/alertmanagerconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,9 @@ func matchedRoutesToMatchedReceiversMap(matchedRoutes []*prometheus.Route, allRe
return matchedReceiversMap
}

func generateNotificationGroupFromRoutes(matchedRouts []*prometheus.Route, matchedReceivers map[string]*prometheus.Receiver) ([]coralogixv1alpha1.NotificationGroup, error) {
func generateNotificationGroupFromRoutes(matchedRoutes []*prometheus.Route, matchedReceivers map[string]*prometheus.Receiver) ([]coralogixv1alpha1.NotificationGroup, error) {
var notificationsGroups []coralogixv1alpha1.NotificationGroup
for _, route := range matchedRouts {
for _, route := range matchedRoutes {
receiver, ok := matchedReceivers[route.Receiver]
if !ok || receiver == nil {
continue
Expand All @@ -304,13 +304,13 @@ func generateNotificationGroupFromRoutes(matchedRouts []*prometheus.Route, match
Notifications: []coralogixv1alpha1.Notification{},
}

for i := range receiver.SlackConfigs {
for i, conf := range receiver.SlackConfigs {
webhookName := fmt.Sprintf("%s.%s.%d", receiver.Name, "slack", i)
notificationsGroup.Notifications = append(notificationsGroup.Notifications, webhookNameToAlertNotification(webhookName, retriggeringPeriodMinutes))
notificationsGroup.Notifications = append(notificationsGroup.Notifications, webhookNameToAlertNotification(webhookName, retriggeringPeriodMinutes, conf.SendResolved))
}
for i := range receiver.OpsGenieConfigs {
for i, conf := range receiver.OpsGenieConfigs {
webhookName := fmt.Sprintf("%s.%s.%d", receiver.Name, "opsgenie", i)
notificationsGroup.Notifications = append(notificationsGroup.Notifications, webhookNameToAlertNotification(webhookName, retriggeringPeriodMinutes))
notificationsGroup.Notifications = append(notificationsGroup.Notifications, webhookNameToAlertNotification(webhookName, retriggeringPeriodMinutes, conf.SendResolved))
}

notificationsGroups = append(notificationsGroups, notificationsGroup)
Expand All @@ -331,10 +331,17 @@ func getRetriggeringPeriodMinutes(route *prometheus.Route) (int32, error) {
return retriggeringPeriodMinutes, nil
}

func webhookNameToAlertNotification(webhookName string, retriggeringPeriodMinutes int32) coralogixv1alpha1.Notification {
func webhookNameToAlertNotification(webhookName string, retriggeringPeriodMinutes int32, notifyOnResolve *bool) coralogixv1alpha1.Notification {
var notifyOn string
if notifyOnResolve != nil && *notifyOnResolve {
notifyOn = coralogixv1alpha1.NotifyOnTriggeredAndResolved
} else {
notifyOn = coralogixv1alpha1.NotifyOnTriggeredOnly
}
return coralogixv1alpha1.Notification{
IntegrationName: pointer.String(webhookName),
RetriggeringPeriodMinutes: retriggeringPeriodMinutes,
NotifyOn: coralogixv1alpha1.NotifyOn(notifyOn),
}
}

Expand Down
2 changes: 1 addition & 1 deletion kuttl-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ testDirs:
- tests/e2e/alerts
- tests/e2e/rulegroups
- tests/e2e/recordingrulegroupsets
- tests/e2e/promatheusrules
- tests/e2e/prometheusrules
- tests/e2e/outboundwebhooks
- tests/e2e/alertmangerconfigs
namespace: default
Expand Down

0 comments on commit ce4a7a0

Please sign in to comment.