@@ -149,6 +149,44 @@ func (client *Client) queryObjectsApiQuery(ctx context.Context, objType string,
149
149
})
150
150
}
151
151
152
+ // fetchIcingaAppStatus retrieves the global state of the IcingaApplication type via the /v1/status endpoint.
153
+ func (client * Client ) fetchIcingaAppStatus (ctx context.Context ) (* IcingaApplication , error ) {
154
+ response , err := client .queryObjectsApi (
155
+ ctx ,
156
+ []string {"/v1/status/IcingaApplication/" },
157
+ http .MethodGet ,
158
+ nil ,
159
+ map [string ]string {"Accept" : "application/json" })
160
+ if err != nil {
161
+ return nil , err
162
+ }
163
+
164
+ defer func () {
165
+ _ , _ = io .Copy (io .Discard , response )
166
+ _ = response .Close ()
167
+ }()
168
+
169
+ type status struct {
170
+ Status struct {
171
+ IcingaApplication * IcingaApplication `json:"icingaapplication"`
172
+ } `json:"status"`
173
+ }
174
+
175
+ var results []status
176
+ err = json .NewDecoder (response ).Decode (& struct {
177
+ Results * []status `json:"results"`
178
+ }{& results })
179
+ if err != nil {
180
+ return nil , err
181
+ }
182
+
183
+ if len (results ) == 0 {
184
+ return nil , fmt .Errorf ("unable to fetch IcingaApplication status" )
185
+ }
186
+
187
+ return results [0 ].Status .IcingaApplication , nil
188
+ }
189
+
152
190
// fetchCheckable fetches the Checkable config state of the given Host/Service name from the Icinga 2 API.
153
191
func (client * Client ) fetchCheckable (ctx context.Context , host , service string ) (* ObjectQueriesResult [HostServiceRuntimeAttributes ], error ) {
154
192
objType , objName := "host" , host
@@ -260,8 +298,13 @@ func (client *Client) checkMissedChanges(ctx context.Context, objType string, ca
260
298
}
261
299
262
300
attrs := objQueriesResult .Attrs
301
+ checkableIsMuted , err := isMuted (ctx , client , & objQueriesResult )
302
+ if err != nil {
303
+ return err
304
+ }
305
+
263
306
var fakeEv * event.Event
264
- if attrs .Acknowledgement != AcknowledgementNone {
307
+ if checkableIsMuted && attrs .Acknowledgement != AcknowledgementNone {
265
308
ackComment , err := client .fetchAcknowledgementComment (ctx , hostName , serviceName , attrs .AcknowledgementLastChange .Time ())
266
309
if err != nil {
267
310
return fmt .Errorf ("fetching acknowledgement comment for %q failed, %w" , objectName , err )
@@ -275,17 +318,17 @@ func (client *Client) checkMissedChanges(ctx context.Context, objType string, ca
275
318
if err != nil {
276
319
return fmt .Errorf ("failed to construct Event from Acknowledgement response, %w" , err )
277
320
}
278
- } else if isMuted ( & objQueriesResult ) {
321
+ } else if checkableIsMuted {
279
322
fakeEv , err = client .buildCommonEvent (ctx , hostName , serviceName )
280
323
if err != nil {
281
324
return fmt .Errorf ("failed to construct checkable fake mute event: %w" , err )
282
325
}
283
326
284
327
fakeEv .Type = event .TypeMute
285
- if attrs .IsFlapping {
286
- fakeEv .SetMute (true , "Checkable is flapping, but we missed the Icinga 2 FlappingStart event" )
287
- } else {
328
+ if attrs .DowntimeDepth != 0 {
288
329
fakeEv .SetMute (true , "Checkable is in downtime, but we missed the Icinga 2 DowntimeStart event" )
330
+ } else {
331
+ fakeEv .SetMute (true , "Checkable is flapping, but we missed the Icinga 2 FlappingStart event" )
289
332
}
290
333
} else {
291
334
// This could potentially produce numerous superfluous database (event table) entries if we generate such
0 commit comments