99use Evenement \EventEmitter ;
1010use Icinga \Application \Logger ;
1111use Icinga \Module \Notifications \Common \Database ;
12+ use Icinga \Module \Notifications \Hook \ObjectsRendererHook ;
1213use Icinga \Module \Notifications \Model \BrowserSession ;
1314use Icinga \Module \Notifications \Model \Daemon \Connection ;
1415use Icinga \Module \Notifications \Model \Daemon \Event ;
@@ -251,7 +252,7 @@ protected function processNotifications(): void
251252
252253 // grab new notifications and the current connections
253254 $ notifications = IncidentHistory::on (Database::get ())
254- ->with (['event ' , 'incident ' , 'incident.object ' ])
255+ ->with (['event ' , 'incident ' , 'incident.object ' , ' incident.object.source ' ])
255256 ->withColumns (['incident.object.id_tags ' ])
256257 ->filter (Filter::greaterThan ('id ' , $ this ->lastIncidentId ))
257258 ->filter (Filter::equal ('type ' , 'notified ' ))
@@ -261,31 +262,41 @@ protected function processNotifications(): void
261262 $ connections = $ this ->server ->getMatchedConnections ();
262263
263264 /** @var IncidentHistory $notification */
265+ $ notificationsToProcess = [];
264266 foreach ($ notifications as $ notification ) {
265267 if (isset ($ connections [$ notification ->contact_id ])) {
266- /** @var Incident $incident */
267- $ incident = $ notification ->incident ;
268-
269- $ event = new Event (
270- EventIdentifier::ICINGA2_NOTIFICATION ,
271- $ notification ->contact_id ,
272- (object ) [
273- 'incident_id ' => $ notification ->incident_id ,
274- 'event_id ' => $ notification ->event_id ,
275- 'severity ' => $ incident ->severity ,
276- 'title ' => $ incident ->object ->getName ()->render (),
277- 'message ' => $ notification ->event ->message
278- ]
279- );
280-
281- $ this ->emit (EventIdentifier::ICINGA2_NOTIFICATION , [$ event ]);
268+ ObjectsRendererHook::register ($ notification ->incident ->object );
269+ $ notificationsToProcess [] = $ notification ;
282270
283271 ++$ numOfNotifications ;
284272 }
285273
286274 $ this ->lastIncidentId = $ notification ->id ;
287275 }
288276
277+ if ($ numOfNotifications > 0 ) {
278+ ObjectsRendererHook::load (false );
279+
280+ foreach ($ notificationsToProcess as $ notification ) {
281+ /** @var Incident $incident */
282+ $ incident = $ notification ->incident ;
283+
284+ $ this ->emit (EventIdentifier::ICINGA2_NOTIFICATION , [
285+ new Event (
286+ EventIdentifier::ICINGA2_NOTIFICATION ,
287+ $ notification ->contact_id ,
288+ (object ) [
289+ 'incident_id ' => $ notification ->incident_id ,
290+ 'event_id ' => $ notification ->event_id ,
291+ 'severity ' => $ incident ->severity ,
292+ 'title ' => ObjectsRendererHook::getObjectNameAsString ($ incident ->object ),
293+ 'message ' => $ notification ->event ->message
294+ ]
295+ )
296+ ]);
297+ }
298+ }
299+
289300 if ($ numOfNotifications > 0 ) {
290301 self ::$ logger ::debug (self ::PREFIX . "sent " . $ numOfNotifications . " notifications " );
291302 }
0 commit comments