MCPcopy Create free account
hub / github.com/Icinga/icinga2 / NotificationTimerHandler

Method NotificationTimerHandler

lib/notification/notificationcomponent.cpp:129–259  ·  view source on GitHub ↗

* Periodically sends notifications. * * @param - Event arguments for the timer. */

Source from the content-addressed store, hash-verified

127 * @param - Event arguments for the timer.
128 */
129void NotificationComponent::NotificationTimerHandler()
130{
131 double now = Utility::GetTime();
132
133 /* Function already checks whether 'api' feature is enabled. */
134 Endpoint::Ptr myEndpoint = Endpoint::GetLocalEndpoint();
135
136 for (const Notification::Ptr& notification : ConfigType::GetObjectsByType<Notification>()) {
137 if (!notification->IsActive())
138 continue;
139
140 String notificationName = notification->GetName();
141 bool updatedObjectAuthority = ApiListener::UpdatedObjectAuthority();
142
143 /* Skip notification if paused, in a cluster setup & HA feature is enabled. */
144 if (notification->IsPaused()) {
145 if (updatedObjectAuthority) {
146 auto stashedNotifications (notification->GetStashedNotifications());
147 ObjectLock olock(stashedNotifications);
148
149 if (stashedNotifications->GetLength()) {
150 Log(LogNotice, "NotificationComponent")
151 << "Notification '" << notificationName << "': HA cluster active, this endpoint does not have the authority. Dropping all stashed notifications.";
152
153 stashedNotifications->Clear();
154 }
155 }
156
157 if (myEndpoint && GetEnableHA()) {
158 Log(LogNotice, "NotificationComponent")
159 << "Reminder notification '" << notificationName << "': HA cluster active, this endpoint does not have the authority (paused=true). Skipping.";
160 continue;
161 }
162 }
163
164 Checkable::Ptr checkable = notification->GetCheckable();
165 ObjectLock lock{checkable};
166
167 if (!IcingaApplication::GetInstance()->GetEnableNotifications() || !checkable->GetEnableNotifications())
168 continue;
169
170 bool reachable = checkable->IsReachable(DependencyNotification);
171
172 if (reachable) {
173 {
174 Array::Ptr unstashedNotifications = new Array();
175
176 {
177 auto stashedNotifications (notification->GetStashedNotifications());
178 ObjectLock olock(stashedNotifications);
179
180 stashedNotifications->CopyTo(unstashedNotifications);
181 stashedNotifications->Clear();
182 }
183
184 ObjectLock olock(unstashedNotifications);
185
186 for (Dictionary::Ptr unstashedNotification : unstashedNotifications) {

Callers

nothing calls this directly

Calls 15

LogClass · 0.85
IsActiveMethod · 0.80
IsPausedMethod · 0.80
GetIntervalMethod · 0.80
IsInDowntimeMethod · 0.80
IsAcknowledgedMethod · 0.80
IsFlappingMethod · 0.80
GetNameMethod · 0.45
GetLengthMethod · 0.45

Tested by

no test coverage detected