Skip to content

Commit cf8bd79

Browse files
committed
Drop Event.Type & Event.Username fields
1 parent adaa589 commit cf8bd79

6 files changed

Lines changed: 8 additions & 276 deletions

File tree

notifications/event/event.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,8 @@ type Event struct {
3030
// For hosts: {"host": "host_name"} and for services: {"host": "host_name", "service": "service_name"}.
3131
Tags map[string]string `json:"tags"`
3232

33-
// Type indicates the type of the event.
34-
Type Type `json:"type"`
3533
// Severity of the event.
3634
Severity Severity `json:"severity,omitempty"`
37-
// Username is the name of the user who triggered the event.
38-
Username string `json:"username"`
3935
// Message is a human-readable message describing the event.
4036
Message string `json:"message"`
4137

notifications/event/event_test.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ func TestEvent(t *testing.T) {
9898
Name: "TestEvent",
9999
URL: "/icingadb/service?name=https%20ssl%20v3.0%20compatibility%20IE%206.0&host.name=example%20host",
100100
Tags: map[string]string{"tag1": "value1"},
101-
Type: TypeState,
102101
Severity: SeverityOK,
103-
Username: "testuser",
104102
Message: "Test",
105103
CompleteRelations: []string{"relation1", "relation2"},
106104
Relations: map[string]any{
@@ -117,9 +115,7 @@ func TestEvent(t *testing.T) {
117115
"name":"TestEvent",
118116
"url":"/icingadb/service?name=https%20ssl%20v3.0%20compatibility%20IE%206.0&host.name=example%20host",
119117
"tags":{"tag1":"value1"},
120-
"type":"state",
121118
"severity":"ok",
122-
"username":"testuser",
123119
"message":"Test",
124120
"complete_relations":["relation1", "relation2"],
125121
"relations":{"relation1":"relation1","relation2":"relation2"}
@@ -131,12 +127,10 @@ func TestEvent(t *testing.T) {
131127
t.Parallel()
132128

133129
event := &Event{
134-
Name: "TestEvent",
135-
URL: "https://example.com/icingaweb2/icingadb/service?name=https%20ssl%20v3.0%20compatibility%20IE%206.0&host.name=example%20host",
136-
Tags: map[string]string{"tag1": "value1"},
137-
Type: TypeMute,
138-
Username: "testuser",
139-
Message: "Test",
130+
Name: "TestEvent",
131+
URL: "https://example.com/icingaweb2/icingadb/service?name=https%20ssl%20v3.0%20compatibility%20IE%206.0&host.name=example%20host",
132+
Tags: map[string]string{"tag1": "value1"},
133+
Message: "Test",
140134
}
141135

142136
data, err := json.Marshal(event)

notifications/event/type.go

Lines changed: 0 additions & 109 deletions
This file was deleted.

notifications/event/type_string.go

Lines changed: 0 additions & 36 deletions
This file was deleted.

notifications/event/type_test.go

Lines changed: 0 additions & 88 deletions
This file was deleted.

notifications/plugin/plugin.go

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,6 @@ type Event struct {
160160
// Time when this event occurred, being encoded according to RFC 3339 when passed as JSON.
161161
Time time.Time `json:"time"`
162162

163-
// Type of this event, e.g., a "state" change, "mute" or "unmute". See further ./internal/event/event.go
164-
Type event.Type `json:"type"`
165-
166-
// Username may contain a user triggering this event, depending on the event's source.
167-
Username string `json:"username"`
168-
169163
// Message of this event, might be a check output when the related Object is an Icinga 2 object.
170164
Message string `json:"message"`
171165
}
@@ -291,19 +285,10 @@ func RunPlugin(plugin Plugin) {
291285
// The created message is a multi-line message as one might expect it in an email.
292286
func FormatMessage(writer io.Writer, req *NotificationRequest) {
293287
if req.Event.Message != "" {
294-
msgTitle := "Comment"
295-
if req.Event.Type == event.TypeState {
296-
msgTitle = "Output"
297-
}
298-
299-
_, _ = fmt.Fprintf(writer, "%s: %s\n\n", msgTitle, req.Event.Message)
288+
_, _ = fmt.Fprintf(writer, "Message: %s\n\n", req.Event.Message)
300289
}
301290

302291
_, _ = fmt.Fprintf(writer, "When: %s\n\n", req.Event.Time.Format("2006-01-02 15:04:05 MST"))
303-
304-
if req.Event.Username != "" {
305-
_, _ = fmt.Fprintf(writer, "Author: %s\n\n", req.Event.Username)
306-
}
307292
_, _ = fmt.Fprintf(writer, "Object: %s\n\n", req.Object.Url)
308293
_, _ = writer.Write([]byte("Tags:\n"))
309294
for k, v := range utils.IterateOrderedMap(req.Object.Tags) {
@@ -319,18 +304,8 @@ func FormatMessage(writer io.Writer, req *NotificationRequest) {
319304

320305
// FormatSubject returns the formatted subject string based on the event type.
321306
func FormatSubject(req *NotificationRequest) string {
322-
switch req.Event.Type {
323-
case event.TypeState:
324-
return fmt.Sprintf("[#%d] %s %s is %s", req.Incident.Id, req.Event.Type, req.Object.Name, req.Incident.Severity)
325-
case event.TypeAcknowledgementCleared, event.TypeDowntimeRemoved:
326-
if req.Incident != nil {
327-
return fmt.Sprintf("[#%d] %s from %s", req.Incident.Id, req.Event.Type, req.Object.Name)
328-
}
329-
return fmt.Sprintf("%s from %s", req.Event.Type, req.Object.Name)
330-
default:
331-
if req.Incident != nil {
332-
return fmt.Sprintf("[#%d] %s on %s", req.Incident.Id, req.Event.Type, req.Object.Name)
333-
}
334-
return fmt.Sprintf("%s on %s", req.Event.Type, req.Object.Name)
307+
if req.Incident != nil {
308+
return fmt.Sprintf("[#%d] %s is %s", req.Incident.Id, req.Object.Name, req.Incident.Severity)
335309
}
310+
return req.Object.Name
336311
}

0 commit comments

Comments
 (0)