From 1eb209e4f000a7953c547d384e4043b8bbd2f237 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Tue, 1 Oct 2013 12:45:58 +0200 Subject: [PATCH] db_ido: Add contactnotifications. refs #4768 --- lib/db_ido/servicedbobject.cpp | 49 +++++++++++++++++++++++++++++++--- lib/db_ido/servicedbobject.h | 1 + 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index 8c2c1fde8..c22d72ebe 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -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(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(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(); + 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& 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(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(now); diff --git a/lib/db_ido/servicedbobject.h b/lib/db_ido/servicedbobject.h index 1b8fd7230..6791f9d56 100644 --- a/lib/db_ido/servicedbobject.h +++ b/lib/db_ido/servicedbobject.h @@ -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& 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); -- 2.40.0