Add RemoveDowntime() cancelled parameter, check for expired/triggered downtimes.

refs #4652
refs #4710
This commit is contained in:
Michael Friedrich 2013-09-17 19:37:10 +02:00
parent 501d18cf2b
commit bcc370b82c
4 changed files with 35 additions and 7 deletions

View File

@ -1294,7 +1294,7 @@ void ClusterComponent::MessageHandler(const Endpoint::Ptr& sender, const Diction
String id = params->Get("id");
service->RemoveDowntime(id, sender->GetName());
service->RemoveDowntime(id, false, sender->GetName());
RelayMessage(sender, message, true);
} else if (message->Get("method") == "cluster::SetAcknowledgement") {

View File

@ -898,7 +898,7 @@ void ExternalCommandProcessor::DelSvcDowntime(double, const std::vector<String>&
int id = Convert::ToLong(arguments[0]);
Log(LogInformation, "icinga", "Removing downtime ID " + arguments[0]);
String rid = Service::GetDowntimeIDFromLegacyID(id);
Service::RemoveDowntime(rid);
Service::RemoveDowntime(rid, true);
}
void ExternalCommandProcessor::ScheduleHostDowntime(double, const std::vector<String>& arguments)
@ -931,7 +931,7 @@ void ExternalCommandProcessor::DelHostDowntime(double, const std::vector<String>
int id = Convert::ToLong(arguments[0]);
Log(LogInformation, "icinga", "Removing downtime ID " + arguments[0]);
String rid = Service::GetDowntimeIDFromLegacyID(id);
Service::RemoveDowntime(rid);
Service::RemoveDowntime(rid, true);
}
void ExternalCommandProcessor::ScheduleHostSvcDowntime(double, const std::vector<String>& arguments)

View File

@ -116,12 +116,14 @@ String Service::AddDowntime(const String& comment_id,
l_DowntimesCache[uid] = GetSelf();
}
Log(LogWarning, "icinga", "added downtime with ID '" + downtime->Get("legacy_id") + "'.");
Utility::QueueAsyncCallback(boost::bind(boost::ref(OnDowntimeAdded), GetSelf(), downtime, authority));
return uid;
}
void Service::RemoveDowntime(const String& id, const String& authority)
void Service::RemoveDowntime(const String& id, const bool& cancelled, const String& authority)
{
Service::Ptr owner = GetOwnerByDowntimeID(id);
@ -149,9 +151,13 @@ void Service::RemoveDowntime(const String& id, const String& authority)
l_LegacyDowntimesCache.erase(legacy_id);
l_DowntimesCache.erase(id);
}
RemoveComment(comment_id);
downtime->Set("was_cancelled", cancelled);
Log(LogWarning, "icinga", "removed downtime with ID '" + downtime->Get("legacy_id") + "' from service '" + owner->GetName() + "'.");
Utility::QueueAsyncCallback(boost::bind(boost::ref(OnDowntimeRemoved), owner, downtime, authority));
}
@ -186,12 +192,24 @@ void Service::TriggerDowntime(const String& id)
if (!downtime)
return;
if (IsDowntimeActive(downtime) && IsDowntimeTriggered(downtime)) {
Log(LogWarning, "icinga", "not triggering downtime with ID '" + downtime->Get("legacy_id") + "': already triggered.");
return;
}
if (IsDowntimeExpired(downtime)) {
Log(LogWarning, "icinga", "not triggering downtime with ID '" + downtime->Get("legacy_id") + "': expired.");
return;
}
double now = Utility::GetTime();
if (now < downtime->Get("start_time") ||
now > downtime->Get("end_time"))
return;
Log(LogWarning, "icinga", "triggering downtime with ID '" + downtime->Get("legacy_id") + "'.");
if (downtime->Get("trigger_time") == 0)
downtime->Set("trigger_time", now);
@ -257,6 +275,15 @@ bool Service::IsDowntimeActive(const Dictionary::Ptr& downtime)
return (triggerTime + downtime->Get("duration") < now);
}
bool Service::IsDowntimeTriggered(const Dictionary::Ptr& downtime)
{
double now = Utility::GetTime();
double triggerTime = downtime->Get("trigger_time");
return (triggerTime > 0 && triggerTime <= now);
}
bool Service::IsDowntimeExpired(const Dictionary::Ptr& downtime)
{
return (downtime->Get("end_time") < Utility::GetTime());
@ -310,7 +337,7 @@ void Service::RemoveExpiredDowntimes(void)
if (!expiredDowntimes.empty()) {
BOOST_FOREACH(const String& id, expiredDowntimes) {
RemoveDowntime(id);
RemoveDowntime(id, false);
}
}
}

View File

@ -262,7 +262,7 @@ public:
const String& triggeredBy, double duration,
const String& id = String(), const String& authority = String());
static void RemoveDowntime(const String& id, const String& = String());
static void RemoveDowntime(const String& id, const bool& cancelled, const String& = String());
void TriggerDowntimes(void);
static void TriggerDowntime(const String& id);
@ -272,6 +272,7 @@ public:
static Dictionary::Ptr GetDowntimeByID(const String& id);
static bool IsDowntimeActive(const Dictionary::Ptr& downtime);
static bool IsDowntimeTriggered(const Dictionary::Ptr& downtime);
static bool IsDowntimeExpired(const Dictionary::Ptr& downtime);
bool IsInDowntime(void) const;