@@ -149,6 +149,47 @@ 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 ) (* IcingaAppStatus , 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 struct {
172
+ App * IcingaAppStatus `json:"app"`
173
+ } `json:"icingaapplication"`
174
+ } `json:"status"`
175
+ }
176
+
177
+ var results []status
178
+ err = json .NewDecoder (response ).Decode (& struct {
179
+ Results * []status `json:"results"`
180
+ }{& results })
181
+ if err != nil {
182
+ return nil , err
183
+ }
184
+
185
+ app := new (IcingaAppStatus )
186
+ if len (results ) != 0 {
187
+ app = results [0 ].Status .IcingaApplication .App
188
+ }
189
+
190
+ return app , nil
191
+ }
192
+
152
193
// fetchCheckable fetches the Checkable config state of the given Host/Service name from the Icinga 2 API.
153
194
func (client * Client ) fetchCheckable (ctx context.Context , host , service string ) (* ObjectQueriesResult [HostServiceRuntimeAttributes ], error ) {
154
195
objType , objName := "host" , host
@@ -260,8 +301,13 @@ func (client *Client) checkMissedChanges(ctx context.Context, objType string, ca
260
301
}
261
302
262
303
attrs := objQueriesResult .Attrs
304
+ checkableIsMuted , err := isMuted (ctx , client , & objQueriesResult )
305
+ if err != nil {
306
+ return err
307
+ }
308
+
263
309
var fakeEv * event.Event
264
- if attrs .Acknowledgement != AcknowledgementNone {
310
+ if checkableIsMuted && attrs .Acknowledgement != AcknowledgementNone {
265
311
ackComment , err := client .fetchAcknowledgementComment (ctx , hostName , serviceName , attrs .AcknowledgementLastChange .Time ())
266
312
if err != nil {
267
313
return fmt .Errorf ("fetching acknowledgement comment for %q failed, %w" , objectName , err )
@@ -275,17 +321,17 @@ func (client *Client) checkMissedChanges(ctx context.Context, objType string, ca
275
321
if err != nil {
276
322
return fmt .Errorf ("failed to construct Event from Acknowledgement response, %w" , err )
277
323
}
278
- } else if isMuted ( & objQueriesResult ) {
324
+ } else if checkableIsMuted {
279
325
fakeEv , err = client .buildCommonEvent (ctx , hostName , serviceName )
280
326
if err != nil {
281
327
return fmt .Errorf ("failed to construct checkable fake mute event: %w" , err )
282
328
}
283
329
284
330
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 {
331
+ if attrs .DowntimeDepth != 0 {
288
332
fakeEv .SetMute (true , "Checkable is in downtime, but we missed the Icinga 2 DowntimeStart event" )
333
+ } else {
334
+ fakeEv .SetMute (true , "Checkable is flapping, but we missed the Icinga 2 FlappingStart event" )
289
335
}
290
336
} else {
291
337
// This could potentially produce numerous superfluous database (event table) entries if we generate such
0 commit comments