committed by
Carl Bergquist
parent
34f314552d
commit
e06abb30aa
@@ -117,6 +117,21 @@ func (this *Alert) ContainsUpdates(other *Alert) bool {
|
||||
return result
|
||||
}
|
||||
|
||||
func (alert *Alert) GetTagsFromSettings() []*Tag {
|
||||
tags := []*Tag{}
|
||||
if alert.Settings != nil {
|
||||
if data, ok := alert.Settings.CheckGet("alertRuleTags"); ok {
|
||||
for tagNameString, tagValue := range data.MustMap() {
|
||||
// MustMap() already guarantees the return of a `map[string]interface{}`.
|
||||
// Therefore we only need to verify that tagValue is a String.
|
||||
tagValueString := simplejson.NewFromAny(tagValue).MustString()
|
||||
tags = append(tags, &Tag{Key: tagNameString, Value: tagValueString})
|
||||
}
|
||||
}
|
||||
}
|
||||
return tags
|
||||
}
|
||||
|
||||
type AlertingClusterInfo struct {
|
||||
ServerId string
|
||||
ClusterSize int
|
||||
|
||||
@@ -35,5 +35,28 @@ func TestAlertingModelTest(t *testing.T) {
|
||||
rule1.Settings = json2
|
||||
So(rule1.ContainsUpdates(rule2), ShouldBeTrue)
|
||||
})
|
||||
|
||||
Convey("Should parse alertRule tags correctly", func() {
|
||||
json2, _ := simplejson.NewJson([]byte(`{
|
||||
"field": "value",
|
||||
"alertRuleTags": {
|
||||
"foo": "bar",
|
||||
"waldo": "fred",
|
||||
"tagMap": { "mapValue": "value" }
|
||||
}
|
||||
}`))
|
||||
rule1.Settings = json2
|
||||
expectedTags := []*Tag{
|
||||
{Id: 0, Key: "foo", Value: "bar"},
|
||||
{Id: 0, Key: "waldo", Value: "fred"},
|
||||
{Id: 0, Key: "tagMap", Value: ""},
|
||||
}
|
||||
actualTags := rule1.GetTagsFromSettings()
|
||||
|
||||
So(len(actualTags), ShouldEqual, len(expectedTags))
|
||||
for _, tag := range expectedTags {
|
||||
So(ContainsTag(actualTags, tag), ShouldBeTrue)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user