Skip to content
Permalink
Browse files

DB IDO: Update Host/Service state 'last_notification' on Notification…

…SentToAllUsers.

Refs #6051
  • Loading branch information
dnsmichi committed May 2, 2014
1 parent ba12ec2 commit fc44798b8dded0b8250439c2e0c1a4a14a2f603a
Showing with 38 additions and 0 deletions.
  1. +37 −0 lib/db_ido/dbevents.cpp
  2. +1 −0 lib/db_ido/dbevents.h
@@ -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)
{
@@ -74,6 +74,7 @@ class DbEvents
/* 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);

0 comments on commit fc44798

Please sign in to comment.
You can’t perform that action at this time.