77
88use Icinga \Module \Notifications \Common \Auth ;
99use Icinga \Module \Notifications \Common \EscalationConditionDescriber ;
10+ use Icinga \Module \Notifications \Common \NotificationTransmissionReason ;
1011use Icinga \Module \Notifications \Model \NotificationHistory ;
1112use Icinga \Module \Notifications \View \IncidentRenderer ;
1213use Icinga \Module \Notifications \Widget \ItemList \ObjectList ;
@@ -122,17 +123,24 @@ protected function createIncident(): ?array
122123
123124 protected function createReason (): array
124125 {
125- return [
126- new HtmlElement ('h2 ' , content: Text::create ($ this ->translate ('Trigger Chain ' ))),
126+ $ triggerChain = new HtmlElement (
127+ 'div ' ,
128+ Attributes::create (['class ' => 'trigger-chain ' ]),
127129 new HtmlElement (
128- 'div ' ,
129- Attributes::create (['class ' => 'trigger-chain ' ]),
130- new HtmlElement (
131- 'span ' ,
132- Attributes::create (['class ' => 'item ' ]),
133- Text::create ($ this ->notificationHistory ->reason ->getLabel ())
134- ),
135- //TODO: in case MUTE, UNMUTE, notifiaction is snet with rule<escalation triggered>, fix chain down below
130+ 'span ' ,
131+ Attributes::create (['class ' => 'item ' ]),
132+ Text::create ($ this ->notificationHistory ->reason ->getLabel ())
133+ )
134+ );
135+
136+ if (
137+ ! in_array (
138+ $ this ->notificationHistory ->reason ,
139+ [NotificationTransmissionReason::MUTED , NotificationTransmissionReason::UNMUTED ],
140+ true
141+ )
142+ ) {
143+ $ triggerChain ->addHtml (
136144 new HtmlElement (
137145 'span ' ,
138146 Attributes::create (['class ' => 'item ' ]),
@@ -151,7 +159,43 @@ protected function createReason(): array
151159 Attributes::create (['class ' => 'item ' ]),
152160 $ this ->notificationHistory ->state ->getIcon ()
153161 )
154- )
162+ );
163+ }
164+
165+ $ query = $ this ->notificationHistory ->skipped
166+ ->with ([
167+ 'contactgroup ' ,
168+ 'schedule ' ,
169+ 'rule ' ,
170+ 'rule_escalation '
171+ ]);
172+ $ skip = [];
173+ foreach ($ query as $ skipped ) {
174+ $ skip [] = new HtmlElement ('li ' , Attributes::create (['class ' => 'popup-item ' ]), Text::create (
175+ sprintf (
176+ 'Rule: %s, Escalation: %s, Schedule: %s, Contactgroup: %s ' ,
177+ $ skipped ->rule ->name ,
178+ $ skipped ->rule_escalation ->position ,
179+ $ skipped ->schedule ->name ,
180+ $ skipped ->contactgroup ->name
181+ )
182+ ));
183+ }
184+
185+ if (! empty ($ skip )) {
186+ $ triggerChain ->addHtml (
187+ new HtmlElement (
188+ 'ul ' ,
189+ Attributes::create (['class ' => 'skipped ' ]),
190+ Text::create (sprintf ($ this ->translate ('(%s Skipped) ' ), count ($ skip ))),
191+ new HtmlElement ('div ' , Attributes::create (['class ' => ['popup ' ]]), ...$ skip )
192+ )
193+ );
194+ }
195+
196+ return [
197+ new HtmlElement ('h2 ' , content: Text::create ($ this ->translate ('Trigger Chain ' ))),
198+ $ triggerChain
155199 ];
156200 }
157201
0 commit comments