Skip to content

Commit

Permalink
feature. add policyName, policyTemplateName to policyNotifications
Browse files Browse the repository at this point in the history
  • Loading branch information
ktkfree committed May 9, 2024
1 parent ae1571f commit ed3e967
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions cmd/server/system_notification_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ type RuleAnnotation struct {
Summary string `yaml:"summary"`
AlertType string `yaml:"alertType"`
SystemNotificationRuleId string `yaml:"systemNotificationRuleId"`
PolicyName string `yaml:"policyName"`
PolicyTemplateName string `yaml:"policyTemplateName"`
}

type RuleLabels struct {
Expand Down Expand Up @@ -127,7 +129,7 @@ func modelToYaml(in any) string {
}
*/

func makeRuleForConfigMap(systemNotificationRule systemNotification.SystemNotificationRule) Rule {
func makeRuleForConfigMap(systemNotificationRule systemNotification.SystemNotificationRule) (out Rule) {
var parameters []domain.SystemNotificationParameter
err := json.Unmarshal(systemNotificationRule.SystemNotificationCondition.Parameter, &parameters)
if err != nil {
Expand All @@ -152,7 +154,7 @@ func makeRuleForConfigMap(systemNotificationRule systemNotification.SystemNotifi
}
}

return Rule{
out = Rule{
Alert: systemNotificationRule.Name,
Expr: expr,
For: systemNotificationRule.SystemNotificationCondition.Duration,
Expand All @@ -168,6 +170,13 @@ func makeRuleForConfigMap(systemNotificationRule systemNotification.SystemNotifi
Severity: systemNotificationRule.SystemNotificationCondition.Severity,
},
}

if systemNotificationRule.NotificationType == "POLICY_NOTIFICATION" {
out.Annotations.PolicyName = "{{$labels.name}}"
out.Annotations.PolicyTemplateName = "{{$labels.kind}}"
}

return out
}

func applyRules(organizationId string, primaryClusterId string, rc RulerConfig) (err error) {
Expand Down

0 comments on commit ed3e967

Please sign in to comment.