]> granicus.if.org Git - icinga2/commitdiff
CompatLog: Fix downtimes.
authorMichael Friedrich <michael.friedrich@netways.de>
Tue, 17 Sep 2013 17:40:23 +0000 (19:40 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Tue, 17 Sep 2013 17:40:23 +0000 (19:40 +0200)
fixes #4652

components/compat/compatlog.cpp
components/compat/compatlog.h

index 918bbecd81446c181e1cf5ba6db9345f02ef4f90..f648fc3798f680abcdf5eb34b2254a2a8c707707 100644 (file)
@@ -52,9 +52,10 @@ void CompatLog::Start(void)
        DynamicObject::Start();
 
        Service::OnNewCheckResult.connect(bind(&CompatLog::CheckResultHandler, this, _1, _2));
-//     Service::OnDowntimeTriggered.connect(bind(&CompatLog::DowntimeHandler, this, _1));
        Service::OnNotificationSentChanged.connect(bind(&CompatLog::NotificationSentHandler, this, _1, _2, _3, _4, _5, _6));
        Service::OnFlappingChanged.connect(bind(&CompatLog::FlappingHandler, this, _1, _2));
+       Service::OnDowntimeTriggered.connect(boost::bind(&CompatLog::TriggerDowntimeHandler, this, _1, _2));
+       Service::OnDowntimeRemoved.connect(boost::bind(&CompatLog::RemoveDowntimeHandler, this, _1, _2));
 
        m_RotationTimer = boost::make_shared<Timer>();
        m_RotationTimer->OnTimerExpired.connect(boost::bind(&CompatLog::RotationTimerHandler, this));
@@ -167,69 +168,111 @@ void CompatLog::CheckResultHandler(const Service::Ptr& service, const Dictionary
        }
 }
 
-///**
-// * @threadsafety Always.
-// */
-//void CompatLog::DowntimeHandler(const Service::Ptr& service)
-//{
-//     Host::Ptr host = service->GetHost();
-//
-//     if (!host)
-//             return;
-//
-//     String downtime_state_str;
-//     String downtime_output;
-//
-//     switch (downtime_state) {
-//             case DowntimeStarted:
-//                     downtime_output = "Service has entered a period of scheduled downtime.";
-//                     downtime_state_str = "STARTED";
-//                     break;
-//             case DowntimeStopped:
-//                     downtime_output = "Service has exited from a period of scheduled downtime.";
-//                     downtime_state_str = "STOPPED";
-//                     break;
-//             case DowntimeCancelled:
-//                     downtime_output = "Scheduled downtime for service has been cancelled.";
-//                     downtime_state_str = "CANCELLED";
-//                     break;
-//             default:
-//                     Log(LogCritical, "compat", "Unknown downtime state: " + Convert::ToString(downtime_state));
-//                     return;
-//     }
-//
-//     std::ostringstream msgbuf;
-//     msgbuf << "SERVICE DOWNTIME ALERT: "
-//             << host->GetName() << ";"
-//             << service->GetShortName() << ";"
-//             << downtime_state_str << "; "
-//             << downtime_output
-//             << "";
-//
-//     {
-//             ObjectLock oLock(this);
-//             WriteLine(msgbuf.str());
-//     }
-//
-//     if (service == host->GetHostCheckService()) {
-//             std::ostringstream msgbuf;
-//             msgbuf << "HOST DOWNTIME ALERT: "
-//                     << host->GetName() << ";"
-//                     << downtime_state_str << "; "
-//                     << downtime_output
-//                     << "";
-//
-//             {
-//                     ObjectLock oLock(this);
-//                     WriteLine(msgbuf.str());
-//             }
-//     }
-//
-//     {
-//             ObjectLock oLock(this);
-//             Flush();
-//     }
-//}
+/**
+ * @threadsafety Always.
+ */
+void CompatLog::TriggerDowntimeHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime)
+{
+       Host::Ptr host = service->GetHost();
+
+       if (!host)
+               return;
+
+       if (!downtime)
+               return;
+
+       String downtime_output = "Service has entered a period of scheduled downtime.";
+       String downtime_state_str = "STARTED";
+
+       std::ostringstream msgbuf;
+       msgbuf << "SERVICE DOWNTIME ALERT: "
+               << host->GetName() << ";"
+               << service->GetShortName() << ";"
+               << downtime_state_str << "; "
+               << downtime_output
+               << "";
+
+       {
+               ObjectLock oLock(this);
+               WriteLine(msgbuf.str());
+       }
+
+       if (service == host->GetHostCheckService()) {
+               std::ostringstream msgbuf;
+               msgbuf << "HOST DOWNTIME ALERT: "
+                       << host->GetName() << ";"
+                       << downtime_state_str << "; "
+                       << downtime_output
+                       << "";
+
+               {
+                       ObjectLock oLock(this);
+                       WriteLine(msgbuf.str());
+               }
+       }
+
+       {
+               ObjectLock oLock(this);
+               Flush();
+       }
+}
+
+/**
+ * @threadsafety Always.
+ */
+void CompatLog::RemoveDowntimeHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime)
+{
+       Host::Ptr host = service->GetHost();
+
+       if (!host)
+               return;
+
+       if (!downtime)
+               return;
+
+       String downtime_output;
+       String downtime_state_str;
+
+       if (downtime->Get("was_cancelled") == true) {
+               downtime_output = "Scheduled downtime for service has been cancelled.";
+               downtime_state_str = "CANCELLED";
+       } else {
+               downtime_output = "Service has exited from a period of scheduled downtime.";
+               downtime_state_str = "STOPPED";
+       }
+
+       std::ostringstream msgbuf;
+       msgbuf << "SERVICE DOWNTIME ALERT: "
+               << host->GetName() << ";"
+               << service->GetShortName() << ";"
+               << downtime_state_str << "; "
+               << downtime_output
+               << "";
+
+       {
+               ObjectLock oLock(this);
+               WriteLine(msgbuf.str());
+       }
+
+       if (service == host->GetHostCheckService()) {
+               std::ostringstream msgbuf;
+               msgbuf << "HOST DOWNTIME ALERT: "
+                       << host->GetName() << ";"
+                       << downtime_state_str << "; "
+                       << downtime_output
+                       << "";
+
+               {
+                       ObjectLock oLock(this);
+                       WriteLine(msgbuf.str());
+               }
+       }
+
+       {
+               ObjectLock oLock(this);
+               Flush();
+       }
+}
 
 /**
  * @threadsafety Always.
index 67adebac6b4ee67179fbb22009c400713a17f701..283c273db75d9308cc7808f39bb296d7c659b903 100644 (file)
@@ -65,6 +65,8 @@ private:
        void DowntimeHandler(const Service::Ptr& service, DowntimeState downtime_state);
        void NotificationSentHandler(const Service::Ptr& service, const User::Ptr& user, NotificationType const& notification_type, Dictionary::Ptr const& cr, const String& author, const String& comment_text);
        void FlappingHandler(const Service::Ptr& service, FlappingState flapping_state);
+        void TriggerDowntimeHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime);
+        void RemoveDowntimeHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime);
 
        Timer::Ptr m_RotationTimer;
        void RotationTimerHandler(void);