DB IDO: Update Host/Service state 'is_flapping' on FlappingChanged.

Refs #6051
This commit is contained in:
Michael Friedrich 2014-05-02 23:49:52 +02:00
parent 03e44dcdc8
commit ba12ec2927
2 changed files with 33 additions and 0 deletions

View File

@ -51,6 +51,7 @@ void DbEvents::StaticInitialize(void)
Checkable::OnAcknowledgementCleared.connect(boost::bind(&DbEvents::RemoveAcknowledgement, _1));
Checkable::OnNextCheckChanged.connect(bind(&DbEvents::NextCheckChangedHandler, _1, _2, _3));
Checkable::OnFlappingChanged.connect(bind(&DbEvents::FlappingChangedHandler, _1, _2));
/* History */
Checkable::OnCommentAdded.connect(boost::bind(&DbEvents::AddCommentHistory, _1, _2));
@ -106,6 +107,37 @@ void DbEvents::NextCheckChangedHandler(const Checkable::Ptr& checkable, double n
DbObject::OnQuery(query1);
}
void DbEvents::FlappingChangedHandler(const Checkable::Ptr& checkable, FlappingState state)
{
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("is_flapping", CompatUtility::GetCheckableIsFlapping(checkable));
fields1->Set("percent_state_change", CompatUtility::GetCheckablePercentStateChange(checkable));
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

@ -73,6 +73,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 AddComment(const Checkable::Ptr& checkable, const Comment::Ptr& comment);
static void RemoveComment(const Checkable::Ptr& checkable, const Comment::Ptr& comment);