]> granicus.if.org Git - icinga2/blobdiff - components/notification/notificationcomponent.cpp
Various bugfixes.
[icinga2] / components / notification / notificationcomponent.cpp
index 02ba944e20ba860b7b8c5467309df9f869d1f570..a7994215522cf97dca21bcdd59a7cd0045596b4b 100644 (file)
@@ -60,21 +60,27 @@ void NotificationComponent::NotificationTimerHandler(void)
                Service::Ptr service = dynamic_pointer_cast<Service>(object);
                bool reachable = service->IsReachable();
 
-               ObjectLock olock(service);
+               bool send_notification;
 
-               if (service->GetStateType() == StateTypeSoft)
-                       continue;
+               {
+                       ObjectLock olock(service);
 
-               if (service->GetState() == StateOK)
-                       continue;
+                       if (service->GetStateType() == StateTypeSoft)
+                               continue;
 
-               if (service->GetNotificationInterval() <= 0)
-                       continue;
+                       if (service->GetState() == StateOK)
+                               continue;
 
-               if (service->GetLastNotification() > now - service->GetNotificationInterval())
-                       continue;
+                       if (service->GetNotificationInterval() <= 0)
+                               continue;
 
-               if (reachable && !service->IsInDowntime() && !service->IsAcknowledged())
+                       if (service->GetLastNotification() > now - service->GetNotificationInterval())
+                               continue;
+
+                       send_notification = reachable && !service->IsInDowntime() && !service->IsAcknowledged();
+               }
+
+               if (send_notification)
                        service->RequestNotifications(NotificationProblem);
        }
 }
@@ -99,5 +105,8 @@ void NotificationComponent::SendNotificationsRequestHandler(const Endpoint::Ptr&
 
        Service::Ptr service = Service::GetByName(svc);
 
+       if (!service)
+               return;
+
        service->SendNotifications(static_cast<NotificationType>(type));
 }