Skip to content

Commit 6600889

Browse files
committed
notifications: Reintroduce Extra Tags
This reverts commit 89dce8b and adds ExtraTags to event.Event, which was not yet imported here at the time of the commit.
1 parent f684950 commit 6600889

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

notifications/event/event.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ type Event struct {
2626
// For hosts: {"host": "host_name"} and for services: {"host": "host_name", "service": "service_name"}.
2727
Tags map[string]string `json:"tags"`
2828

29+
// ExtraTags supplement Tags, for example with host or service groups for an Icinga DB source.
30+
ExtraTags map[string]string `json:"extra_tags"`
31+
2932
// Type indicates the type of the event.
3033
Type Type `json:"type"`
3134
// Severity of the event.

notifications/event/event_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func TestEvent(t *testing.T) {
2121
Name: "TestEvent",
2222
URL: "/icingadb/service?name=https%20ssl%20v3.0%20compatibility%20IE%206.0&host.name=example%20host",
2323
Tags: map[string]string{"tag1": "value1"},
24+
ExtraTags: map[string]string{},
2425
Type: TypeState,
2526
Severity: SeverityOK,
2627
Username: "testuser",
@@ -37,6 +38,7 @@ func TestEvent(t *testing.T) {
3738
"name":"TestEvent",
3839
"url":"/icingadb/service?name=https%20ssl%20v3.0%20compatibility%20IE%206.0&host.name=example%20host",
3940
"tags":{"tag1":"value1"},
41+
"extra_tags":{},
4042
"type":"state",
4143
"severity":"ok",
4244
"username":"testuser",

notifications/plugin/plugin.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ type Object struct {
133133

134134
// Tags defining this Object, may be "host" and "service" when from Icinga 2.
135135
Tags map[string]string `json:"tags"`
136+
137+
// ExtraTags attached, may be a host or service groups when form Icinga 2.
138+
ExtraTags map[string]string `json:"extra_tags"`
136139
}
137140

138141
// Incident of this NotificationRequest, grouping Events for this Object.
@@ -300,6 +303,13 @@ func FormatMessage(writer io.Writer, req *NotificationRequest) {
300303
_, _ = fmt.Fprintf(writer, "%s: %s\n", k, v)
301304
}
302305

306+
if len(req.Object.ExtraTags) > 0 {
307+
_, _ = writer.Write([]byte("\nExtra Tags:\n"))
308+
for k, v := range utils.IterateOrderedMap(req.Object.ExtraTags) {
309+
_, _ = fmt.Fprintf(writer, "%s: %s\n", k, v)
310+
}
311+
}
312+
303313
_, _ = fmt.Fprintf(writer, "\nIncident: %s", req.Incident.Url)
304314
}
305315

0 commit comments

Comments
 (0)