DB IDO: Update Host/Service state 'last_notification' on NotificationSentToAllUsers.

Refs #6051
This commit is contained in:
Michael Friedrich 2014-05-03 00:16:53 +02:00
parent ba12ec2927
commit fc44798b8d
2 changed files with 38 additions and 0 deletions

View File

@ -52,6 +52,7 @@ void DbEvents::StaticInitialize(void)
Checkable::OnNextCheckChanged.connect(bind(&DbEvents::NextCheckChangedHandler, _1, _2, _3));
Checkable::OnFlappingChanged.connect(bind(&DbEvents::FlappingChangedHandler, _1, _2));
Checkable::OnNotificationSentToAllUsers.connect(bind(&DbEvents::LastNotificationChangedHandler, _1, _2));
/* History */
Checkable::OnCommentAdded.connect(boost::bind(&DbEvents::AddCommentHistory, _1, _2));
@ -138,6 +139,42 @@ void DbEvents::FlappingChangedHandler(const Checkable::Ptr& checkable, FlappingS
DbObject::OnQuery(query1);
}
void DbEvents::LastNotificationChangedHandler(const Notification::Ptr& notification, const Checkable::Ptr& checkable)
{
double now = Utility::GetTime();
std::pair<unsigned long, unsigned long> now_bag = CompatUtility::ConvertTimestamp(now);
std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(notification->GetNextNotification());
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
DbQuery query1;
if (service)
query1.Table = "servicestatus";
else
query1.Table = "hoststatus";
query1.Type = DbQueryUpdate;
Dictionary::Ptr fields1 = make_shared<Dictionary>();
fields1->Set("last_notification", DbValue::FromTimestamp(now_bag.first));
fields1->Set("next_notification", DbValue::FromTimestamp(time_bag.first));
fields1->Set("current_notification_number", notification->GetNotificationNumber());
query1.Fields = fields1;
query1.WhereCriteria = make_shared<Dictionary>();
if (service)
query1.WhereCriteria->Set("service_object_id", service);
else
query1.WhereCriteria->Set("host_object_id", host);
query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
DbObject::OnQuery(query1);
}
/* comments */
void DbEvents::AddComments(const Checkable::Ptr& checkable)
{

View File

@ -74,6 +74,7 @@ public:
/* Status */
static void NextCheckChangedHandler(const Checkable::Ptr& checkable, double nextCheck, const String& authority);
static void FlappingChangedHandler(const Checkable::Ptr& checkable, FlappingState state);
static void LastNotificationChangedHandler(const Notification::Ptr& notification, const Checkable::Ptr& checkable);
static void AddComment(const Checkable::Ptr& checkable, const Comment::Ptr& comment);
static void RemoveComment(const Checkable::Ptr& checkable, const Comment::Ptr& comment);