]> granicus.if.org Git - icinga2/commitdiff
Implemented status.dat support for notifications.
authorGunnar Beutner <gunnar.beutner@netways.de>
Sat, 9 Feb 2013 16:27:32 +0000 (17:27 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Sat, 9 Feb 2013 16:33:50 +0000 (17:33 +0100)
components/compat/compatcomponent.cpp
lib/icinga/service-downtime.cpp
lib/icinga/service-notification.cpp
lib/icinga/service.cpp
lib/icinga/service.h

index ef73c63d5a160dc555e999f4715cbde52d88f73c..5332bbae55b54bc11c477552ecbc699b606f46cc 100644 (file)
@@ -355,7 +355,9 @@ void CompatComponent::DumpServiceStatusAttrs(ofstream& fp, const Service::Ptr& s
           << "\t" << "problem_has_been_acknowledged=" << (service->GetAcknowledgement() != AcknowledgementNone ? 1 : 0) << "\n"
           << "\t" << "acknowledgement_type=" << static_cast<int>(service->GetAcknowledgement()) << "\n"
           << "\t" << "acknowledgement_end_time=" << service->GetAcknowledgementExpiry() << "\n"
-          << "\t" << "scheduled_downtime_depth=" << (service->IsInDowntime() ? 1 : 0) << "\n";
+          << "\t" << "scheduled_downtime_depth=" << (service->IsInDowntime() ? 1 : 0) << "\n"
+          << "\t" << "last_notification=" << service->GetLastNotification() << "\n"
+          << "\t" << "next_notification=" << service->GetNextNotification() << "\n";
 }
 
 void CompatComponent::DumpServiceStatus(ofstream& fp, const Service::Ptr& service)
index b60ee23608f13eb729971b53d5b0aaaf2c4b9538..43fcbf83ab96a0b3f9362d098fcf1f26d0e2e918 100644 (file)
@@ -274,3 +274,19 @@ void Service::DowntimeExpireTimerHandler(void)
                service->RemoveExpiredDowntimes();
        }
 }
+
+bool Service::IsInDowntime(void) const
+{
+       Dictionary::Ptr downtimes = GetDowntimes();
+
+       if (!downtimes)
+               return false;
+
+       Dictionary::Ptr downtime;
+       BOOST_FOREACH(tie(tuples::ignore, downtime), downtimes) {
+               if (Service::IsDowntimeActive(downtime))
+                       return true;
+       }
+
+       return false;
+}
index fb7ab4fe48e7ca910e5f3598640d89218db4d4ad..11e20b1a2e2a5698614d766ca55769a4e448b467 100644 (file)
@@ -39,7 +39,7 @@ void Service::RequestNotifications(NotificationType type) const
        EndpointManager::GetInstance()->SendAnycastMessage(Endpoint::Ptr(), msg);
 }
 
-void Service::SendNotifications(NotificationType type) const
+void Service::SendNotifications(NotificationType type)
 {
        Logger::Write(LogInformation, "icinga", "Sending notifications for service '" + GetName() + "'");
 
@@ -51,6 +51,8 @@ void Service::SendNotifications(NotificationType type) const
        BOOST_FOREACH(const Notification::Ptr& notification, notifications) {
                notification->SendNotification(type);
        }
+
+       SetLastNotification(Utility::GetTime());
 }
 
 void Service::InvalidateNotificationsCache(void)
@@ -182,3 +184,33 @@ void Service::UpdateSlaveNotifications(void)
 
        Set("slave_notifications", newNotifications);
 }
+
+double Service::GetLastNotification(void) const
+{
+       Value value = Get("last_notification");
+
+       if (value.IsEmpty())
+               value = 0;
+
+       return value;
+}
+
+void Service::SetLastNotification(double time)
+{
+       Set("last_notification", time);
+}
+
+double Service::GetNextNotification(void) const
+{
+       Value value = Get("next_notification");
+
+       if (value.IsEmpty())
+               value = 0;
+
+       return value;
+}
+
+void Service::SetNextNotification(double time)
+{
+       Set("next_notification", time);
+}
index 1a65de6f2eabb8a3017e21ec9830b0cb407e9c6b..41858a65754da4bafc3bb171a02aca09bd6571ea 100644 (file)
@@ -38,7 +38,9 @@ static AttributeDescription serviceAttributes[] = {
        { "acknowledgement", Attribute_Replicated },
        { "acknowledgement_expiry", Attribute_Replicated },
        { "downtimes", Attribute_Replicated },
-       { "comments", Attribute_Replicated }
+       { "comments", Attribute_Replicated },
+       { "last_notification", Attribute_Replicated },
+       { "next_notification", Attribute_Replicated }
 };
 
 REGISTER_TYPE(Service, serviceAttributes);
@@ -227,22 +229,6 @@ bool Service::IsReachable(void) const
        return true;
 }
 
-bool Service::IsInDowntime(void) const
-{
-       Dictionary::Ptr downtimes = GetDowntimes();
-
-       if (!downtimes)
-               return false;
-
-       Dictionary::Ptr downtime;
-       BOOST_FOREACH(tie(tuples::ignore, downtime), downtimes) {
-               if (Service::IsDowntimeActive(downtime))
-                       return true;
-       }
-
-       return false;
-}
-
 void Service::SetSchedulingOffset(long offset)
 {
        Set("scheduling_offset", offset);
index e136a26a14318f6d05a4c41614891f5d97ac24c2..f8033b14a2b2b966bb62dc170a0fdbbc71692f42 100644 (file)
@@ -224,7 +224,7 @@ public:
 
        /* Notifications */
        void RequestNotifications(NotificationType type) const;
-       void SendNotifications(NotificationType type) const;
+       void SendNotifications(NotificationType type);
 
        static void InvalidateNotificationsCache(void);
        static void ValidateNotificationsCache(void);
@@ -233,6 +233,12 @@ public:
 
        void UpdateSlaveNotifications(void);
 
+       double GetLastNotification(void) const;
+       void SetLastNotification(double time);
+
+       double GetNextNotification(void) const;
+       void SetNextNotification(double time);
+
 protected:
        virtual void OnAttributeChanged(const String& name, const Value& oldValue);