Skip to content

Commit bb66cf1

Browse files
authored
Merge pull request #31 from openinfradev/alert
feature. add attribute type & id to systemNotification
2 parents f487860 + 6007e14 commit bb66cf1

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

cmd/server/system_notification_rule.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ import (
1616
)
1717

1818
type RuleAnnotation struct {
19-
CheckPoint string `yaml:"CheckPoint"`
20-
Description string `yaml:"description"`
21-
Discriminative string `yaml:"discriminative"`
22-
Message string `yaml:"message"`
23-
Summary string `yaml:"summary"`
19+
CheckPoint string `yaml:"CheckPoint"`
20+
Description string `yaml:"description"`
21+
Discriminative string `yaml:"discriminative"`
22+
Message string `yaml:"message"`
23+
Summary string `yaml:"summary"`
24+
AlertType string `json:"alertType"`
25+
SystemNotificationRuleId string `json:"systemNotificationRuleId"`
2426
}
2527

2628
type RuleLabels struct {
@@ -104,10 +106,12 @@ func processSystemNotificationRule() error {
104106
Expr: expr,
105107
For: rule.SystemNotificationCondition.Duration,
106108
Annotations: RuleAnnotation{
107-
CheckPoint: replaceMetricParameter(rule.SystemNotificationTemplate.MetricParameters, rule.MessageActionProposal),
108-
Description: replaceMetricParameter(rule.SystemNotificationTemplate.MetricParameters, rule.MessageContent),
109-
Message: replaceMetricParameter(rule.SystemNotificationTemplate.MetricParameters, rule.MessageTitle),
110-
Discriminative: discriminative,
109+
CheckPoint: replaceMetricParameter(rule.SystemNotificationTemplate.MetricParameters, rule.MessageActionProposal),
110+
Description: replaceMetricParameter(rule.SystemNotificationTemplate.MetricParameters, rule.MessageContent),
111+
Message: replaceMetricParameter(rule.SystemNotificationTemplate.MetricParameters, rule.MessageTitle),
112+
Discriminative: discriminative,
113+
AlertType: rule.NotificationType,
114+
SystemNotificationRuleId: rule.ID.String(),
111115
},
112116
Labels: RuleLabels{
113117
Severity: rule.SystemNotificationCondition.Severity,
@@ -178,7 +182,7 @@ func processSystemNotificationRule() error {
178182
organizationRuleIds = append(organizationRuleIds, r.ID)
179183
}
180184
}
181-
err = systemNotificationRuleAccessor.UpdateSystemNotificationRuleStatus(organizationRuleIds, domain.SystemNotificationRuleStatus_APPLYED)
185+
err = systemNotificationRuleAccessor.UpdateSystemNotificationRuleStatus(organizationRuleIds, domain.SystemNotificationRuleStatus_APPLIED)
182186
if err != nil {
183187
log.Error(context.TODO(), err)
184188
continue

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ toolchain go1.21.7
66

77
require (
88
github.com/gofrs/uuid v4.0.0+incompatible
9-
github.com/openinfradev/tks-api v0.0.0-20240404091154-a3b290667109
109
github.com/spf13/pflag v1.0.5
1110
github.com/spf13/viper v1.18.2
1211
gopkg.in/yaml.v2 v2.4.0
@@ -48,6 +47,7 @@ require (
4847
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4948
github.com/modern-go/reflect2 v1.0.2 // indirect
5049
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
50+
github.com/openinfradev/tks-api v0.0.0-20240411053710-5b8a434e8797 // indirect
5151
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
5252
github.com/pkg/errors v0.9.1 // indirect
5353
github.com/sagikazarmark/locafero v0.4.0 // indirect

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,10 @@ github.com/onsi/ginkgo/v2 v2.4.0 h1:+Ig9nvqgS5OBSACXNk15PLdp0U9XPYROt9CFzVdFGIs=
142142
github.com/onsi/ginkgo/v2 v2.4.0/go.mod h1:iHkDK1fKGcBoEHT5W7YBq4RFWaQulw+caOMkAt4OrFo=
143143
github.com/onsi/gomega v1.23.0 h1:/oxKu9c2HVap+F3PfKort2Hw5DEU+HGlW8n+tguWsys=
144144
github.com/onsi/gomega v1.23.0/go.mod h1:Z/NWtiqwBrwUt4/2loMmHL63EDLnYHmVbuBpDr2vQAg=
145-
github.com/openinfradev/tks-api v0.0.0-20240404091154-a3b290667109 h1:fLqD+UXruMR9Chv0ZykLKlDqwT/OibQtO9+nL1Km9To=
146-
github.com/openinfradev/tks-api v0.0.0-20240404091154-a3b290667109/go.mod h1:OGfXiL0YRby+OzOm+OI0d+wtPkOj3SMCiAv3lvpmaiU=
145+
github.com/openinfradev/tks-api v0.0.0-20240409091158-eff7241c1731 h1:gmVBHSDzJGdf9p4wm28bDFcA3yFU6QjZl4prCd2fvIg=
146+
github.com/openinfradev/tks-api v0.0.0-20240409091158-eff7241c1731/go.mod h1:OGfXiL0YRby+OzOm+OI0d+wtPkOj3SMCiAv3lvpmaiU=
147+
github.com/openinfradev/tks-api v0.0.0-20240411053710-5b8a434e8797 h1:DQ5naso3RdA0XxQ2Fj70xZ4O3vBhtWYR9Kpdy7LQqRE=
148+
github.com/openinfradev/tks-api v0.0.0-20240411053710-5b8a434e8797/go.mod h1:Ph4lPgdWg06R1GUNCtmXfzHNlNCW/XjUAvei+m5DD2o=
147149
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
148150
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
149151
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=

internal/system-notification-rule/syste-notification-rule.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type SystemNotificationTemplate struct {
3333

3434
ID uuid.UUID `gorm:"primarykey"`
3535
Name string `gorm:"index:idx_name,unique"`
36+
NotificationType string `gorm:"default:SYSTEM_NOTIFICATION"`
3637
Organizations []Organization `gorm:"many2many:system_notification_template_organizations;constraint:OnUpdate:RESTRICT,OnDelete:RESTRICT"`
3738
OrganizationIds []string `gorm:"-:all"`
3839
Description string
@@ -58,6 +59,7 @@ type SystemNotificationRule struct {
5859

5960
ID uuid.UUID `gorm:"primarykey"`
6061
Name string `gorm:"index,unique"`
62+
NotificationType string `gorm:"default:SYSTEM_NOTIFICATION"`
6163
Description string
6264
OrganizationId string
6365
Organization Organization `gorm:"foreignKey:OrganizationId"`

0 commit comments

Comments
 (0)