]> granicus.if.org Git - icinga2/commitdiff
db_ido: Add contactnotifications.
authorMichael Friedrich <michael.friedrich@netways.de>
Tue, 1 Oct 2013 10:45:58 +0000 (12:45 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Tue, 1 Oct 2013 10:45:58 +0000 (12:45 +0200)
refs #4768

lib/db_ido/servicedbobject.cpp
lib/db_ido/servicedbobject.h

index 8c2c1fde83eaa3ec40fd4a6408109d886017037a..c22d72ebe7307bdb1cee6b1325494a8b6f22cf60 100644 (file)
@@ -53,6 +53,7 @@ void ServiceDbObject::StaticInitialize(void)
        Service::OnCommentAdded.connect(boost::bind(&ServiceDbObject::AddCommentHistory, _1, _2));
        Service::OnDowntimeAdded.connect(boost::bind(&ServiceDbObject::AddDowntimeHistory, _1, _2));
        Service::OnAcknowledgementSet.connect(boost::bind(&ServiceDbObject::AddAcknowledgementHistory, _1, _2, _3, _4, _5));
+       Service::OnNotificationSentToUser.connect(bind(&ServiceDbObject::AddContactNotificationHistory, _1, _2));
        Service::OnNotificationSentToAllUsers.connect(bind(&ServiceDbObject::AddNotificationHistory, _1, _2, _3, _4, _5, _6));
 
        Service::OnStateChange.connect(boost::bind(&ServiceDbObject::AddStateChangeHistory, _1, _2, _3));
@@ -736,7 +737,7 @@ void ServiceDbObject::AddAcknowledgementHistory(const Service::Ptr& service, con
        if (!host)
                return;
 
-       Log(LogDebug, "db_ido", "add acknowledgement for '" + service->GetName() + "'");
+       Log(LogDebug, "db_ido", "add acknowledgement history for '" + service->GetName() + "'");
 
        double now = Utility::GetTime();
        unsigned long entry_time = static_cast<long>(now);
@@ -771,6 +772,46 @@ void ServiceDbObject::AddAcknowledgementHistory(const Service::Ptr& service, con
 }
 
 /* notifications */
+
+void ServiceDbObject::AddContactNotificationHistory(const Service::Ptr& service, const User::Ptr& user)
+{
+       Host::Ptr host = service->GetHost();
+
+       if (!host)
+               return;
+
+       Log(LogDebug, "db_ido", "add contact notification history for '" + service->GetName() + "'");
+
+       /* start and end happen at the same time */
+       double now = Utility::GetTime();
+       unsigned long start_time = static_cast<long>(now);
+       unsigned long end_time = start_time;
+       unsigned long start_time_usec = (now - start_time) * 1000 * 1000;
+       unsigned long end_time_usec = start_time_usec;
+
+       DbQuery query1;
+       query1.Table = "contactnotifications";
+       query1.Type = DbQueryInsert;
+
+       Dictionary::Ptr fields1 = boost::make_shared<Dictionary>();
+       fields1->Set("contact_object_id", user);
+       fields1->Set("start_time", DbValue::FromTimestamp(start_time));
+       fields1->Set("start_time_usec", start_time_usec);
+       fields1->Set("end_time", DbValue::FromTimestamp(end_time));
+       fields1->Set("end_time_usec", end_time_usec);
+
+       fields1->Set("notification_id", 0); /* DbConnection class fills in real ID */
+       fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
+
+       query1.Fields = fields1;
+       OnQuery(query1);
+
+       if (host->GetCheckService() == service) {
+               query1.Fields = fields1;
+               OnQuery(query1);
+       }
+}
+
 void ServiceDbObject::AddNotificationHistory(const Service::Ptr& service, const std::set<User::Ptr>& users, NotificationType type,
                                      const Dictionary::Ptr& cr, const String& author, const String& text)
 {
@@ -779,7 +820,7 @@ void ServiceDbObject::AddNotificationHistory(const Service::Ptr& service, const
        if (!host)
                return;
 
-       Log(LogDebug, "db_ido", "add notification for '" + service->GetName() + "'");
+       Log(LogDebug, "db_ido", "add notification history for '" + service->GetName() + "'");
 
        /* start and end happen at the same time */
        double now = Utility::GetTime();
@@ -832,7 +873,7 @@ void ServiceDbObject::AddStateChangeHistory(const Service::Ptr& service, const D
        if (!host)
                return;
 
-       Log(LogDebug, "db_ido", "add state change for '" + service->GetName() + "'");
+       Log(LogDebug, "db_ido", "add state change history for '" + service->GetName() + "'");
 
        double now = Utility::GetTime();
        unsigned long state_time = static_cast<long>(now);
@@ -1166,7 +1207,7 @@ void ServiceDbObject::AddLogHistory(const Service::Ptr& service, String buffer,
        if (!host)
                return;
 
-       Log(LogDebug, "db_ido", "add log entry for '" + service->GetName() + "'");
+       Log(LogDebug, "db_ido", "add log entry history for '" + service->GetName() + "'");
 
        double now = Utility::GetTime();
        unsigned long entry_time = static_cast<long>(now);
index 1b8fd7230354cd9d179c57bc4c7d83e6f98e818d..6791f9d56f6c219cc216ae5a1d370f42b5f9cfb0 100644 (file)
@@ -99,6 +99,7 @@ private:
         static void AddCommentHistory(const Service::Ptr& service, const Dictionary::Ptr& comment);
         static void AddDowntimeHistory(const Service::Ptr& service, const Dictionary::Ptr& downtime);
         static void AddAcknowledgementHistory(const Service::Ptr& service, const String& author, const String& comment, AcknowledgementType type, double expiry);
+        static void AddContactNotificationHistory(const Service::Ptr& service, const User::Ptr& user);
         static void AddNotificationHistory(const Service::Ptr& service, const std::set<User::Ptr>& users, NotificationType type, const Dictionary::Ptr& cr, const String& author, const String& text);
         static void AddStateChangeHistory(const Service::Ptr& service, const Dictionary::Ptr& cr, StateType type);