diff --git a/cmd/server/system_notification_rule.go b/cmd/server/system_notification_rule.go index 5850b9c..082b9fc 100644 --- a/cmd/server/system_notification_rule.go +++ b/cmd/server/system_notification_rule.go @@ -16,11 +16,13 @@ import ( ) type RuleAnnotation struct { - CheckPoint string `yaml:"CheckPoint"` - Description string `yaml:"description"` - Discriminative string `yaml:"discriminative"` - Message string `yaml:"message"` - Summary string `yaml:"summary"` + CheckPoint string `yaml:"CheckPoint"` + Description string `yaml:"description"` + Discriminative string `yaml:"discriminative"` + Message string `yaml:"message"` + Summary string `yaml:"summary"` + AlertType string `json:"alertType"` + SystemNotificationRuleId string `json:"systemNotificationRuleId"` } type RuleLabels struct { @@ -104,10 +106,12 @@ func processSystemNotificationRule() error { Expr: expr, For: rule.SystemNotificationCondition.Duration, Annotations: RuleAnnotation{ - CheckPoint: replaceMetricParameter(rule.SystemNotificationTemplate.MetricParameters, rule.MessageActionProposal), - Description: replaceMetricParameter(rule.SystemNotificationTemplate.MetricParameters, rule.MessageContent), - Message: replaceMetricParameter(rule.SystemNotificationTemplate.MetricParameters, rule.MessageTitle), - Discriminative: discriminative, + CheckPoint: replaceMetricParameter(rule.SystemNotificationTemplate.MetricParameters, rule.MessageActionProposal), + Description: replaceMetricParameter(rule.SystemNotificationTemplate.MetricParameters, rule.MessageContent), + Message: replaceMetricParameter(rule.SystemNotificationTemplate.MetricParameters, rule.MessageTitle), + Discriminative: discriminative, + AlertType: rule.NotificationType, + SystemNotificationRuleId: rule.ID.String(), }, Labels: RuleLabels{ Severity: rule.SystemNotificationCondition.Severity, @@ -178,7 +182,7 @@ func processSystemNotificationRule() error { organizationRuleIds = append(organizationRuleIds, r.ID) } } - err = systemNotificationRuleAccessor.UpdateSystemNotificationRuleStatus(organizationRuleIds, domain.SystemNotificationRuleStatus_APPLYED) + err = systemNotificationRuleAccessor.UpdateSystemNotificationRuleStatus(organizationRuleIds, domain.SystemNotificationRuleStatus_APPLIED) if err != nil { log.Error(context.TODO(), err) continue diff --git a/go.mod b/go.mod index e1fa182..f6b78f4 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,6 @@ toolchain go1.21.7 require ( github.com/gofrs/uuid v4.0.0+incompatible - github.com/openinfradev/tks-api v0.0.0-20240404091154-a3b290667109 github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.18.2 gopkg.in/yaml.v2 v2.4.0 @@ -48,6 +47,7 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect + github.com/openinfradev/tks-api v0.0.0-20240411053710-5b8a434e8797 // indirect github.com/pelletier/go-toml/v2 v2.1.0 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/sagikazarmark/locafero v0.4.0 // indirect diff --git a/go.sum b/go.sum index f0668ab..1235b18 100644 --- a/go.sum +++ b/go.sum @@ -142,8 +142,10 @@ github.com/onsi/ginkgo/v2 v2.4.0 h1:+Ig9nvqgS5OBSACXNk15PLdp0U9XPYROt9CFzVdFGIs= github.com/onsi/ginkgo/v2 v2.4.0/go.mod h1:iHkDK1fKGcBoEHT5W7YBq4RFWaQulw+caOMkAt4OrFo= github.com/onsi/gomega v1.23.0 h1:/oxKu9c2HVap+F3PfKort2Hw5DEU+HGlW8n+tguWsys= github.com/onsi/gomega v1.23.0/go.mod h1:Z/NWtiqwBrwUt4/2loMmHL63EDLnYHmVbuBpDr2vQAg= -github.com/openinfradev/tks-api v0.0.0-20240404091154-a3b290667109 h1:fLqD+UXruMR9Chv0ZykLKlDqwT/OibQtO9+nL1Km9To= -github.com/openinfradev/tks-api v0.0.0-20240404091154-a3b290667109/go.mod h1:OGfXiL0YRby+OzOm+OI0d+wtPkOj3SMCiAv3lvpmaiU= +github.com/openinfradev/tks-api v0.0.0-20240409091158-eff7241c1731 h1:gmVBHSDzJGdf9p4wm28bDFcA3yFU6QjZl4prCd2fvIg= +github.com/openinfradev/tks-api v0.0.0-20240409091158-eff7241c1731/go.mod h1:OGfXiL0YRby+OzOm+OI0d+wtPkOj3SMCiAv3lvpmaiU= +github.com/openinfradev/tks-api v0.0.0-20240411053710-5b8a434e8797 h1:DQ5naso3RdA0XxQ2Fj70xZ4O3vBhtWYR9Kpdy7LQqRE= +github.com/openinfradev/tks-api v0.0.0-20240411053710-5b8a434e8797/go.mod h1:Ph4lPgdWg06R1GUNCtmXfzHNlNCW/XjUAvei+m5DD2o= github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= diff --git a/internal/system-notification-rule/syste-notification-rule.go b/internal/system-notification-rule/syste-notification-rule.go index 6118462..d3d4572 100644 --- a/internal/system-notification-rule/syste-notification-rule.go +++ b/internal/system-notification-rule/syste-notification-rule.go @@ -33,6 +33,7 @@ type SystemNotificationTemplate struct { ID uuid.UUID `gorm:"primarykey"` Name string `gorm:"index:idx_name,unique"` + NotificationType string `gorm:"default:SYSTEM_NOTIFICATION"` Organizations []Organization `gorm:"many2many:system_notification_template_organizations;constraint:OnUpdate:RESTRICT,OnDelete:RESTRICT"` OrganizationIds []string `gorm:"-:all"` Description string @@ -58,6 +59,7 @@ type SystemNotificationRule struct { ID uuid.UUID `gorm:"primarykey"` Name string `gorm:"index,unique"` + NotificationType string `gorm:"default:SYSTEM_NOTIFICATION"` Description string OrganizationId string Organization Organization `gorm:"foreignKey:OrganizationId"`