Skip to content

Commit 5ed29e8

Browse files
committed
Drop Event.Type & Event.Username fields
1 parent 6365eab commit 5ed29e8

6 files changed

Lines changed: 9 additions & 277 deletions

File tree

notifications/event/event.go

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

46-
// Type indicates the type of the event.
47-
Type Type `json:"type"`
4846
// Severity of the event.
4947
Severity Severity `json:"severity,omitempty"`
50-
// Username is the name of the user who triggered the event.
51-
Username string `json:"username"`
5248
// Message is a human-readable message describing the event.
5349
Message string `json:"message"`
5450

notifications/event/event_test.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@ func TestEvent(t *testing.T) {
102102
Name: "TestEvent",
103103
URL: "/icingadb/service?name=https%20ssl%20v3.0%20compatibility%20IE%206.0&host.name=example%20host",
104104
Tags: map[string]string{"tag1": "value1"},
105-
Type: TypeState,
106105
Severity: SeverityOK,
107-
Username: "testuser",
108106
Message: "Test",
109107
CompleteRelations: []string{"relation1", "relation2"},
110108
Relations: map[string]any{
@@ -121,9 +119,7 @@ func TestEvent(t *testing.T) {
121119
"name":"TestEvent",
122120
"url":"/icingadb/service?name=https%20ssl%20v3.0%20compatibility%20IE%206.0&host.name=example%20host",
123121
"tags":{"tag1":"value1"},
124-
"type":"state",
125122
"severity":"ok",
126-
"username":"testuser",
127123
"message":"Test",
128124
"complete_relations":["relation1", "relation2"],
129125
"relations":{"relation1":"relation1","relation2":"relation2"}
@@ -135,12 +131,10 @@ func TestEvent(t *testing.T) {
135131
t.Parallel()
136132

137133
event := &Event{
138-
Name: "TestEvent",
139-
URL: "https://example.com/icingaweb2/icingadb/service?name=https%20ssl%20v3.0%20compatibility%20IE%206.0&host.name=example%20host",
140-
Tags: map[string]string{"tag1": "value1"},
141-
Type: TypeMute,
142-
Username: "testuser",
143-
Message: "Test",
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+
Message: "Test",
144138
}
145139

146140
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: 5 additions & 30 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) {
@@ -317,20 +302,10 @@ func FormatMessage(writer io.Writer, req *NotificationRequest) {
317302
}
318303
}
319304

320-
// FormatSubject returns the formatted subject string based on the event type.
305+
// FormatSubject returns the formatted subject string.
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)