Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions notifications/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ type Event struct {
// For hosts: {"host": "host_name"} and for services: {"host": "host_name", "service": "service_name"}.
Tags map[string]string `json:"tags"`

// ExtraTags supplement Tags, for example with host or service groups for an Icinga DB source.
ExtraTags map[string]string `json:"extra_tags"`

// Type indicates the type of the event.
Type Type `json:"type"`
// Severity of the event.
Expand All @@ -53,7 +50,20 @@ type Event struct {
// from the encoded JSON.
MuteReason string `json:"mute_reason,omitempty"`

// RulesVersion and RuleIds are the source rules matching for this Event.
RulesVersion string `json:"rules_version"`
RuleIds []string `json:"rule_ids"`
// CompleteRelations contains a list of relations that should be considered complete for this event.
//
// Typically, when Icinga Notifications determines that the event didn't provide complete information
// needed to evaluate the rules in the [Relations] field, it will instruct the source to provide the
// missing information in a follow-up request. This field can be used by the source to indicate that
// it already provided all the available information it has for the certain relations and that the
// Icinga Notifications should not ask for more information for these relations.
CompleteRelations []string `json:"complete_relations,omitempty"`

// Relations contains additional information about the relations of the object this event is referring to.
//
// This will be used to evaluate JSONPath expressions in the filter columns of the event rules.
// The structure of this field is flexible and can contain any information that might be relevant
// for the evaluation of the rules. It will not be used for anything else than evaluating the rules
// and will not be persisted to the database as well.
Relations map[string]any `json:"relations,omitempty"`
}
27 changes: 14 additions & 13 deletions notifications/event/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ func TestEvent(t *testing.T) {
t.Parallel()

event := &Event{
Name: "TestEvent",
URL: "/icingadb/service?name=https%20ssl%20v3.0%20compatibility%20IE%206.0&host.name=example%20host",
Tags: map[string]string{"tag1": "value1"},
ExtraTags: map[string]string{},
Type: TypeState,
Severity: SeverityOK,
Username: "testuser",
Message: "Test",
RulesVersion: "0x1",
RuleIds: []string{"1", "2", "3", "6"},
Name: "TestEvent",
URL: "/icingadb/service?name=https%20ssl%20v3.0%20compatibility%20IE%206.0&host.name=example%20host",
Tags: map[string]string{"tag1": "value1"},
Type: TypeState,
Severity: SeverityOK,
Username: "testuser",
Message: "Test",
CompleteRelations: []string{"relation1", "relation2"},
Relations: map[string]any{
"relation1": "relation1",
"relation2": "relation2",
},
}

data, err := json.Marshal(event)
Expand All @@ -38,13 +40,12 @@ func TestEvent(t *testing.T) {
"name":"TestEvent",
"url":"/icingadb/service?name=https%20ssl%20v3.0%20compatibility%20IE%206.0&host.name=example%20host",
"tags":{"tag1":"value1"},
"extra_tags":{},
"type":"state",
"severity":"ok",
"username":"testuser",
"message":"Test",
"rules_version": "0x1",
"rule_ids": ["1", "2", "3", "6"]
"complete_relations":["relation1", "relation2"],
"relations":{"relation1":"relation1","relation2":"relation2"}
}`
assert.JSONEq(t, expected, string(data), "JSON encoding does not match expected output")
})
Expand Down
10 changes: 10 additions & 0 deletions notifications/http_headers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package notifications

// XIcingaRejectIfRelationsIncomplete is a custom HTTP header that can be used by sources to indicate that Icinga
// Notifications should reject the request if the event's relations are incomplete.
//
// By default, Icinga Notifications will attempt to process events even if their relations are incomplete,
// which may not be desirable in some cases. If a source sets this header to "true", Icinga Notifications
// rejects the request with all the missing relations in the response body, allowing the source to retry
// with the complete set of relations.
const XIcingaRejectIfRelationsIncomplete = "X-Icinga-Reject-If-Relations-Incomplete"
Loading