Skip to content

Commit d68373d

Browse files
committed
eventstream: HostServiceRuntimeAttributes real name field
Turns out, both Host and Service objects do have a real name field which contains their name. Thus, the hacky __name field can be dropped.
1 parent bb8828d commit d68373d

File tree

3 files changed

+5
-14
lines changed

3 files changed

+5
-14
lines changed

internal/eventstream/api_responses.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,8 @@ type Downtime struct {
6969
// When catching up potentially missed changes, the following fields seems to be the relevant ones which, fortunately,
7070
// are identical for Icinga 2 Host and Service objects.
7171
//
72-
// According to the documentation, neither the Host nor the Service name is part of the attributes for Host resp.
73-
// Service objects. However, next to being part of the wrapping API response, see ObjectQueriesResult, it is also
74-
// available in the "__name" attribute, reflected in the Name field. For Service objects, it is "${host}!${service}".
75-
// Furthermore, Service objects have a required non-empty reference to their Host.
76-
//
7772
// NOTE:
73+
// - Name is either the Host or the Service name.
7874
// - Host is empty for Host objects; Host contains the Service's Host object name for Services.
7975
// - State might be 0 = UP, 1 = DOWN for hosts and 0 = OK, 1 = WARNING, 2 = CRITICAL, 3 = UNKNOWN for services.
8076
// - StateType might be 0 = SOFT, 1 = HARD.
@@ -83,7 +79,7 @@ type Downtime struct {
8379
// https://icinga.com/docs/icinga-2/latest/doc/09-object-types/#host
8480
// https://icinga.com/docs/icinga-2/latest/doc/09-object-types/#service
8581
type HostServiceRuntimeAttributes struct {
86-
Name string `json:"__name"`
82+
Name string `json:"name"`
8783
Host string `json:"host_name,omitempty"`
8884
Groups []string `json:"groups"`
8985
State int `json:"state"`

internal/eventstream/api_responses_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func TestObjectQueriesResult_UnmarshalJSON(t *testing.T) {
190190
Name: "docker-master!ssh",
191191
Type: "Service",
192192
Attrs: &HostServiceRuntimeAttributes{
193-
Name: "docker-master!ssh",
193+
Name: "ssh",
194194
Host: "docker-master",
195195
Groups: []string{},
196196
State: 2,

internal/eventstream/client_api.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"net/http"
99
"net/url"
1010
"slices"
11-
"strings"
1211
"time"
1312
)
1413

@@ -165,7 +164,7 @@ func (client *Client) checkMissedChanges(objType, filterExpr string, attrsCallba
165164

166165
for _, objQueriesResult := range objQueriesResults {
167166
if client.Ctx.Err() != nil {
168-
client.Logger.Info("Stopping %s API response processing as context is finished", objType)
167+
client.Logger.Infof("Stopping %s API response processing as context is finished", objType)
169168
return
170169
}
171170

@@ -181,12 +180,8 @@ func (client *Client) checkMissedChanges(objType, filterExpr string, attrsCallba
181180
hostName = attrs.Name
182181

183182
case "Service":
184-
if !strings.HasPrefix(attrs.Name, attrs.Host+"!") {
185-
client.Logger.Errorf("Queried API Service object's name mismatches, %q is no prefix of %q", attrs.Host, attrs.Name)
186-
continue
187-
}
188183
hostName = attrs.Host
189-
serviceName = attrs.Name[len(attrs.Host+"!"):]
184+
serviceName = attrs.Name
190185

191186
default:
192187
client.Logger.Errorf("Querying API delivered a %q object when expecting %s", objQueriesResult.Type, objType)

0 commit comments

Comments
 (0)