mirror of https://github.com/Icinga/icinga2.git
parent
cb526ddccc
commit
ec1a7bbfcb
|
@ -869,7 +869,7 @@ void ClusterListener::CommentRemovedHandler(const Service::Ptr& service, const C
|
|||
AsyncRelayMessage(Endpoint::Ptr(), message, true);
|
||||
}
|
||||
|
||||
void ClusterListener::DowntimeAddedHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime, const String& authority)
|
||||
void ClusterListener::DowntimeAddedHandler(const Service::Ptr& service, const Downtime::Ptr& downtime, const String& authority)
|
||||
{
|
||||
if (!authority.IsEmpty() && authority != GetIdentity())
|
||||
return;
|
||||
|
@ -888,14 +888,14 @@ void ClusterListener::DowntimeAddedHandler(const Service::Ptr& service, const Di
|
|||
AsyncRelayMessage(Endpoint::Ptr(), message, true);
|
||||
}
|
||||
|
||||
void ClusterListener::DowntimeRemovedHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime, const String& authority)
|
||||
void ClusterListener::DowntimeRemovedHandler(const Service::Ptr& service, const Downtime::Ptr& downtime, const String& authority)
|
||||
{
|
||||
if (!authority.IsEmpty() && authority != GetIdentity())
|
||||
return;
|
||||
|
||||
Dictionary::Ptr params = make_shared<Dictionary>();
|
||||
params->Set("service", service->GetName());
|
||||
params->Set("id", downtime->Get("id"));
|
||||
params->Set("id", downtime->GetId());
|
||||
|
||||
Dictionary::Ptr message = make_shared<Dictionary>();
|
||||
message->Set("jsonrpc", "2.0");
|
||||
|
@ -1249,12 +1249,12 @@ void ClusterListener::MessageHandler(const Endpoint::Ptr& sender, const Dictiona
|
|||
return;
|
||||
}
|
||||
|
||||
Dictionary::Ptr downtime = params->Get("downtime");
|
||||
Downtime::Ptr downtime = params->Get("downtime");
|
||||
|
||||
service->AddDowntime(downtime->Get("comment_id"),
|
||||
downtime->Get("start_time"), downtime->Get("end_time"),
|
||||
downtime->Get("fixed"), downtime->Get("triggered_by"),
|
||||
downtime->Get("duration"), downtime->Get("id"), sender->GetName());
|
||||
service->AddDowntime(downtime->GetAuthor(), downtime->GetComment(),
|
||||
downtime->GetStartTime(), downtime->GetEndTime(),
|
||||
downtime->GetFixed(), downtime->GetTriggeredBy(),
|
||||
downtime->GetDuration(), downtime->GetId(), sender->GetName());
|
||||
|
||||
AsyncRelayMessage(sender, message, true);
|
||||
} else if (message->Get("method") == "cluster::RemoveDowntime") {
|
||||
|
|
|
@ -94,8 +94,8 @@ private:
|
|||
void EnableFlappingChangedHandler(const Service::Ptr& service, bool enabled, const String& authority);
|
||||
void CommentAddedHandler(const Service::Ptr& service, const Comment::Ptr& comment, const String& authority);
|
||||
void CommentRemovedHandler(const Service::Ptr& service, const Comment::Ptr& comment, const String& authority);
|
||||
void DowntimeAddedHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime, const String& authority);
|
||||
void DowntimeRemovedHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime, const String& authority);
|
||||
void DowntimeAddedHandler(const Service::Ptr& service, const Downtime::Ptr& downtime, const String& authority);
|
||||
void DowntimeRemovedHandler(const Service::Ptr& service, const Downtime::Ptr& downtime, const String& authority);
|
||||
void AcknowledgementSetHandler(const Service::Ptr& service, const String& author, const String& comment, AcknowledgementType type, double expiry, const String& authority);
|
||||
void AcknowledgementClearedHandler(const Service::Ptr& service, const String& authority);
|
||||
|
||||
|
|
|
@ -147,7 +147,7 @@ void CompatLogger::CheckResultHandler(const Service::Ptr& service, const CheckRe
|
|||
/**
|
||||
* @threadsafety Always.
|
||||
*/
|
||||
void CompatLogger::TriggerDowntimeHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime)
|
||||
void CompatLogger::TriggerDowntimeHandler(const Service::Ptr& service, const Downtime::Ptr& downtime)
|
||||
{
|
||||
Host::Ptr host = service->GetHost();
|
||||
|
||||
|
@ -193,7 +193,7 @@ void CompatLogger::TriggerDowntimeHandler(const Service::Ptr& service, const Dic
|
|||
/**
|
||||
* @threadsafety Always.
|
||||
*/
|
||||
void CompatLogger::RemoveDowntimeHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime)
|
||||
void CompatLogger::RemoveDowntimeHandler(const Service::Ptr& service, const Downtime::Ptr& downtime)
|
||||
{
|
||||
Host::Ptr host = service->GetHost();
|
||||
|
||||
|
@ -206,7 +206,7 @@ void CompatLogger::RemoveDowntimeHandler(const Service::Ptr& service, const Dict
|
|||
String downtime_output;
|
||||
String downtime_state_str;
|
||||
|
||||
if (downtime->Get("was_cancelled") == true) {
|
||||
if (downtime->GetWasCancelled()) {
|
||||
downtime_output = "Scheduled downtime for service has been cancelled.";
|
||||
downtime_state_str = "CANCELLED";
|
||||
} else {
|
||||
|
|
|
@ -53,11 +53,10 @@ private:
|
|||
void Flush(void);
|
||||
|
||||
void CheckResultHandler(const Service::Ptr& service, const CheckResult::Ptr& cr);
|
||||
void DowntimeHandler(const Service::Ptr& service, DowntimeState downtime_state);
|
||||
void NotificationSentHandler(const Service::Ptr& service, const User::Ptr& user, NotificationType const& notification_type, CheckResult::Ptr const& cr, const String& author, const String& comment_text, const String& command_name);
|
||||
void FlappingHandler(const Service::Ptr& service, FlappingState flapping_state);
|
||||
void TriggerDowntimeHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime);
|
||||
void RemoveDowntimeHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime);
|
||||
void TriggerDowntimeHandler(const Service::Ptr& service, const Downtime::Ptr& downtime);
|
||||
void RemoveDowntimeHandler(const Service::Ptr& service, const Downtime::Ptr& downtime);
|
||||
void ExternalCommandHandler(const String& command, const std::vector<String>& arguments);
|
||||
void EventCommandHandler(const Service::Ptr& service);
|
||||
|
||||
|
|
|
@ -175,7 +175,7 @@ void StatusDataWriter::DumpDowntimes(std::ostream& fp, const Service::Ptr& owner
|
|||
ObjectLock olock(downtimes);
|
||||
|
||||
String id;
|
||||
Dictionary::Ptr downtime;
|
||||
Downtime::Ptr downtime;
|
||||
BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
|
||||
if (Service::IsDowntimeExpired(downtime))
|
||||
continue;
|
||||
|
@ -186,23 +186,23 @@ void StatusDataWriter::DumpDowntimes(std::ostream& fp, const Service::Ptr& owner
|
|||
fp << "servicedowntime {" << "\n"
|
||||
<< "\t" << "service_description=" << owner->GetShortName() << "\n";
|
||||
|
||||
Dictionary::Ptr triggeredByObj = Service::GetDowntimeByID(downtime->Get("triggered_by"));
|
||||
Downtime::Ptr triggeredByObj = Service::GetDowntimeByID(downtime->GetTriggeredBy());
|
||||
int triggeredByLegacy = 0;
|
||||
if (triggeredByObj)
|
||||
triggeredByLegacy = triggeredByObj->Get("legacy_id");
|
||||
triggeredByLegacy = triggeredByObj->GetLegacyId();
|
||||
|
||||
fp << "\t" << "host_name=" << host->GetName() << "\n"
|
||||
<< "\t" << "downtime_id=" << static_cast<String>(downtime->Get("legacy_id")) << "\n"
|
||||
<< "\t" << "entry_time=" << static_cast<double>(downtime->Get("entry_time")) << "\n"
|
||||
<< "\t" << "start_time=" << static_cast<double>(downtime->Get("start_time")) << "\n"
|
||||
<< "\t" << "end_time=" << static_cast<double>(downtime->Get("end_time")) << "\n"
|
||||
<< "\t" << "downtime_id=" << downtime->GetLegacyId() << "\n"
|
||||
<< "\t" << "entry_time=" << downtime->GetEntryTime() << "\n"
|
||||
<< "\t" << "start_time=" << downtime->GetStartTime() << "\n"
|
||||
<< "\t" << "end_time=" << downtime->GetEndTime() << "\n"
|
||||
<< "\t" << "triggered_by=" << triggeredByLegacy << "\n"
|
||||
<< "\t" << "fixed=" << static_cast<long>(downtime->Get("fixed")) << "\n"
|
||||
<< "\t" << "duration=" << static_cast<long>(downtime->Get("duration")) << "\n"
|
||||
<< "\t" << "fixed=" << static_cast<long>(downtime->GetFixed()) << "\n"
|
||||
<< "\t" << "duration=" << static_cast<long>(downtime->GetDuration()) << "\n"
|
||||
<< "\t" << "is_in_effect=" << (Service::IsDowntimeActive(downtime) ? 1 : 0) << "\n"
|
||||
<< "\t" << "author=" << static_cast<String>(downtime->Get("author")) << "\n"
|
||||
<< "\t" << "comment=" << static_cast<String>(downtime->Get("comment")) << "\n"
|
||||
<< "\t" << "trigger_time=" << static_cast<double>(downtime->Get("trigger_time")) << "\n"
|
||||
<< "\t" << "author=" << downtime->GetAuthor() << "\n"
|
||||
<< "\t" << "comment=" << downtime->GetComment() << "\n"
|
||||
<< "\t" << "trigger_time=" << downtime->GetTriggerTime() << "\n"
|
||||
<< "\t" << "}" << "\n"
|
||||
<< "\n";
|
||||
}
|
||||
|
|
|
@ -78,35 +78,35 @@ Object::Ptr DowntimesTable::ServiceAccessor(const Value& row, const Column::Obje
|
|||
|
||||
Value DowntimesTable::AuthorAccessor(const Value& row)
|
||||
{
|
||||
Dictionary::Ptr downtime = Service::GetDowntimeByID(row);
|
||||
Downtime::Ptr downtime = Service::GetDowntimeByID(row);
|
||||
|
||||
return downtime->Get("author");
|
||||
return downtime->GetAuthor();
|
||||
}
|
||||
|
||||
Value DowntimesTable::CommentAccessor(const Value& row)
|
||||
{
|
||||
Dictionary::Ptr downtime = Service::GetDowntimeByID(row);
|
||||
Downtime::Ptr downtime = Service::GetDowntimeByID(row);
|
||||
|
||||
return downtime->Get("comment");
|
||||
return downtime->GetComment();
|
||||
}
|
||||
|
||||
Value DowntimesTable::IdAccessor(const Value& row)
|
||||
{
|
||||
Dictionary::Ptr downtime = Service::GetDowntimeByID(row);
|
||||
Downtime::Ptr downtime = Service::GetDowntimeByID(row);
|
||||
|
||||
return downtime->Get("legacy_id");
|
||||
return downtime->GetLegacyId();
|
||||
}
|
||||
|
||||
Value DowntimesTable::EntryTimeAccessor(const Value& row)
|
||||
{
|
||||
Dictionary::Ptr downtime = Service::GetDowntimeByID(row);
|
||||
Downtime::Ptr downtime = Service::GetDowntimeByID(row);
|
||||
|
||||
return static_cast<int>(downtime->Get("entry_time"));
|
||||
return static_cast<int>(downtime->GetEntryTime());
|
||||
}
|
||||
|
||||
Value DowntimesTable::TypeAccessor(const Value& row)
|
||||
{
|
||||
Dictionary::Ptr downtime = Service::GetDowntimeByID(row);
|
||||
Downtime::Ptr downtime = Service::GetDowntimeByID(row);
|
||||
// 1 .. active, 0 .. pending
|
||||
return (Service::IsDowntimeActive(downtime) ? 1 : 0);
|
||||
}
|
||||
|
@ -120,35 +120,35 @@ Value DowntimesTable::IsServiceAccessor(const Value& row)
|
|||
|
||||
Value DowntimesTable::StartTimeAccessor(const Value& row)
|
||||
{
|
||||
Dictionary::Ptr downtime = Service::GetDowntimeByID(row);
|
||||
Downtime::Ptr downtime = Service::GetDowntimeByID(row);
|
||||
|
||||
return static_cast<int>(downtime->Get("start_time"));
|
||||
return static_cast<int>(downtime->GetStartTime());
|
||||
}
|
||||
|
||||
Value DowntimesTable::EndTimeAccessor(const Value& row)
|
||||
{
|
||||
Dictionary::Ptr downtime = Service::GetDowntimeByID(row);
|
||||
Downtime::Ptr downtime = Service::GetDowntimeByID(row);
|
||||
|
||||
return static_cast<int>(downtime->Get("end_time"));
|
||||
return static_cast<int>(downtime->GetEndTime());
|
||||
}
|
||||
|
||||
Value DowntimesTable::FixedAccessor(const Value& row)
|
||||
{
|
||||
Dictionary::Ptr downtime = Service::GetDowntimeByID(row);
|
||||
Downtime::Ptr downtime = Service::GetDowntimeByID(row);
|
||||
|
||||
return downtime->Get("fixed");
|
||||
return downtime->GetFixed();
|
||||
}
|
||||
|
||||
Value DowntimesTable::DurationAccessor(const Value& row)
|
||||
{
|
||||
Dictionary::Ptr downtime = Service::GetDowntimeByID(row);
|
||||
Downtime::Ptr downtime = Service::GetDowntimeByID(row);
|
||||
|
||||
return downtime->Get("duration");
|
||||
return downtime->GetDuration();
|
||||
}
|
||||
|
||||
Value DowntimesTable::TriggeredByAccessor(const Value& row)
|
||||
{
|
||||
Dictionary::Ptr downtime = Service::GetDowntimeByID(row);
|
||||
Downtime::Ptr downtime = Service::GetDowntimeByID(row);
|
||||
|
||||
return downtime->Get("triggered_by");
|
||||
return downtime->GetTriggeredBy();
|
||||
}
|
||||
|
|
|
@ -1419,7 +1419,7 @@ Value HostsTable::DowntimesAccessor(const Value& row)
|
|||
ObjectLock olock(downtimes);
|
||||
|
||||
String id;
|
||||
Dictionary::Ptr downtime;
|
||||
Downtime::Ptr downtime;
|
||||
BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
|
||||
|
||||
if (!downtime)
|
||||
|
@ -1428,7 +1428,7 @@ Value HostsTable::DowntimesAccessor(const Value& row)
|
|||
if (Service::IsDowntimeExpired(downtime))
|
||||
continue;
|
||||
|
||||
ids->Add(downtime->Get("legacy_id"));
|
||||
ids->Add(downtime->GetLegacyId());
|
||||
}
|
||||
|
||||
return ids;
|
||||
|
@ -1454,7 +1454,7 @@ Value HostsTable::DowntimesWithInfoAccessor(const Value& row)
|
|||
ObjectLock olock(downtimes);
|
||||
|
||||
String id;
|
||||
Dictionary::Ptr downtime;
|
||||
Downtime::Ptr downtime;
|
||||
BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
|
||||
|
||||
if (!downtime)
|
||||
|
@ -1464,9 +1464,9 @@ Value HostsTable::DowntimesWithInfoAccessor(const Value& row)
|
|||
continue;
|
||||
|
||||
Array::Ptr downtime_info = make_shared<Array>();
|
||||
downtime_info->Add(downtime->Get("legacy_id"));
|
||||
downtime_info->Add(downtime->Get("author"));
|
||||
downtime_info->Add(downtime->Get("comment"));
|
||||
downtime_info->Add(downtime->GetLegacyId());
|
||||
downtime_info->Add(downtime->GetAuthor());
|
||||
downtime_info->Add(downtime->GetComment());
|
||||
ids->Add(downtime_info);
|
||||
}
|
||||
|
||||
|
|
|
@ -1044,7 +1044,7 @@ Value ServicesTable::DowntimesAccessor(const Value& row)
|
|||
ObjectLock olock(downtimes);
|
||||
|
||||
String id;
|
||||
Dictionary::Ptr downtime;
|
||||
Downtime::Ptr downtime;
|
||||
BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
|
||||
|
||||
if (!downtime)
|
||||
|
@ -1053,7 +1053,7 @@ Value ServicesTable::DowntimesAccessor(const Value& row)
|
|||
if (Service::IsDowntimeExpired(downtime))
|
||||
continue;
|
||||
|
||||
ids->Add(downtime->Get("legacy_id"));
|
||||
ids->Add(downtime->GetLegacyId());
|
||||
}
|
||||
|
||||
return ids;
|
||||
|
@ -1073,7 +1073,7 @@ Value ServicesTable::DowntimesWithInfoAccessor(const Value& row)
|
|||
ObjectLock olock(downtimes);
|
||||
|
||||
String id;
|
||||
Dictionary::Ptr downtime;
|
||||
Downtime::Ptr downtime;
|
||||
BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
|
||||
|
||||
if (!downtime)
|
||||
|
@ -1083,9 +1083,9 @@ Value ServicesTable::DowntimesWithInfoAccessor(const Value& row)
|
|||
continue;
|
||||
|
||||
Array::Ptr downtime_info = make_shared<Array>();
|
||||
downtime_info->Add(downtime->Get("legacy_id"));
|
||||
downtime_info->Add(downtime->Get("author"));
|
||||
downtime_info->Add(downtime->Get("comment"));
|
||||
downtime_info->Add(downtime->GetLegacyId());
|
||||
downtime_info->Add(downtime->GetAuthor());
|
||||
downtime_info->Add(downtime->GetComment());
|
||||
ids->Add(downtime_info);
|
||||
}
|
||||
|
||||
|
|
|
@ -542,23 +542,23 @@ void ServiceDbObject::AddDowntimes(const Service::Ptr& service)
|
|||
ObjectLock olock(downtimes);
|
||||
|
||||
String downtime_id;
|
||||
Dictionary::Ptr downtime;
|
||||
Downtime::Ptr downtime;
|
||||
BOOST_FOREACH(boost::tie(downtime_id, downtime), downtimes) {
|
||||
AddDowntime(service, downtime);
|
||||
}
|
||||
}
|
||||
|
||||
void ServiceDbObject::AddDowntime(const Service::Ptr& service, const Dictionary::Ptr& downtime)
|
||||
void ServiceDbObject::AddDowntime(const Service::Ptr& service, const Downtime::Ptr& downtime)
|
||||
{
|
||||
AddDowntimeInternal(service, downtime, false);
|
||||
}
|
||||
|
||||
void ServiceDbObject::AddDowntimeHistory(const Service::Ptr& service, const Dictionary::Ptr& downtime)
|
||||
void ServiceDbObject::AddDowntimeHistory(const Service::Ptr& service, const Downtime::Ptr& downtime)
|
||||
{
|
||||
AddDowntimeInternal(service, downtime, true);
|
||||
}
|
||||
|
||||
void ServiceDbObject::AddDowntimeInternal(const Service::Ptr& service, const Dictionary::Ptr& downtime, bool historical)
|
||||
void ServiceDbObject::AddDowntimeInternal(const Service::Ptr& service, const Downtime::Ptr& downtime, bool historical)
|
||||
{
|
||||
Host::Ptr host = service->GetHost();
|
||||
|
||||
|
@ -570,47 +570,47 @@ void ServiceDbObject::AddDowntimeInternal(const Service::Ptr& service, const Dic
|
|||
return;
|
||||
}
|
||||
|
||||
Log(LogDebug, "db_ido", "adding service downtime (id = " + downtime->Get("legacy_id") + ") for '" + service->GetName() + "'");
|
||||
Log(LogDebug, "db_ido", "adding service downtime (id = " + Convert::ToString(downtime->GetLegacyId()) + ") for '" + service->GetName() + "'");
|
||||
|
||||
/* add the service downtime */
|
||||
AddDowntimeByType(service, downtime, historical);
|
||||
|
||||
/* add the hostcheck service downtime to the host as well */
|
||||
if (host->GetCheckService() == service) {
|
||||
Log(LogDebug, "db_ido", "adding host downtime (id = " + downtime->Get("legacy_id") + ") for '" + host->GetName() + "'");
|
||||
Log(LogDebug, "db_ido", "adding host downtime (id = " + Convert::ToString(downtime->GetLegacyId()) + ") for '" + host->GetName() + "'");
|
||||
AddDowntimeByType(host, downtime, historical);
|
||||
}
|
||||
}
|
||||
|
||||
void ServiceDbObject::AddDowntimeByType(const DynamicObject::Ptr& object, const Dictionary::Ptr& downtime, bool historical)
|
||||
void ServiceDbObject::AddDowntimeByType(const DynamicObject::Ptr& object, const Downtime::Ptr& downtime, bool historical)
|
||||
{
|
||||
Dictionary::Ptr fields1 = make_shared<Dictionary>();
|
||||
fields1->Set("entry_time", DbValue::FromTimestamp(downtime->Get("entry_time")));
|
||||
fields1->Set("entry_time", DbValue::FromTimestamp(downtime->GetEntryTime()));
|
||||
fields1->Set("object_id", object);
|
||||
|
||||
if (object->GetType() == DynamicType::GetByName("Host")) {
|
||||
fields1->Set("downtime_type", 2);
|
||||
/* requires idoutils 1.10 schema fix */
|
||||
fields1->Set("internal_downtime_id", downtime->Get("legacy_id"));
|
||||
fields1->Set("internal_downtime_id", downtime->GetLegacyId());
|
||||
} else if (object->GetType() == DynamicType::GetByName("Service")) {
|
||||
fields1->Set("downtime_type", 1);
|
||||
fields1->Set("internal_downtime_id", downtime->Get("legacy_id"));
|
||||
fields1->Set("internal_downtime_id", downtime->GetLegacyId());
|
||||
} else {
|
||||
Log(LogDebug, "db_ido", "unknown object type for adding downtime.");
|
||||
return;
|
||||
}
|
||||
|
||||
fields1->Set("author_name", downtime->Get("author"));
|
||||
fields1->Set("triggered_by_id", downtime->Get("triggered_by"));
|
||||
fields1->Set("is_fixed", downtime->Get("is_fixed"));
|
||||
fields1->Set("duration", downtime->Get("duration"));
|
||||
fields1->Set("scheduled_start_time", DbValue::FromTimestamp(downtime->Get("start_time")));
|
||||
fields1->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->Get("end_time")));
|
||||
fields1->Set("author_name", downtime->GetAuthor());
|
||||
fields1->Set("triggered_by_id", downtime->GetTriggeredBy());
|
||||
fields1->Set("is_fixed", downtime->GetFixed());
|
||||
fields1->Set("duration", downtime->GetDuration());
|
||||
fields1->Set("scheduled_start_time", DbValue::FromTimestamp(downtime->GetStartTime()));
|
||||
fields1->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->GetEndTime()));
|
||||
fields1->Set("was_started", Empty);
|
||||
fields1->Set("actual_start_time", Empty);
|
||||
fields1->Set("actual_start_time_usec", Empty);
|
||||
fields1->Set("is_in_effect", Empty);
|
||||
fields1->Set("trigger_time", DbValue::FromTimestamp(downtime->Get("trigger_time")));
|
||||
fields1->Set("trigger_time", DbValue::FromTimestamp(downtime->GetTriggerTime()));
|
||||
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||
|
||||
DbQuery query1;
|
||||
|
@ -649,7 +649,7 @@ void ServiceDbObject::RemoveDowntimes(const Service::Ptr& service)
|
|||
}
|
||||
}
|
||||
|
||||
void ServiceDbObject::RemoveDowntime(const Service::Ptr& service, const Dictionary::Ptr& downtime)
|
||||
void ServiceDbObject::RemoveDowntime(const Service::Ptr& service, const Downtime::Ptr& downtime)
|
||||
{
|
||||
Host::Ptr host = service->GetHost();
|
||||
|
||||
|
@ -661,7 +661,7 @@ void ServiceDbObject::RemoveDowntime(const Service::Ptr& service, const Dictiona
|
|||
return;
|
||||
}
|
||||
|
||||
Log(LogDebug, "db_ido", "removing service downtime (id = " + downtime->Get("legacy_id") + ") for '" + service->GetName() + "'");
|
||||
Log(LogDebug, "db_ido", "removing service downtime (id = " + Convert::ToString(downtime->GetLegacyId()) + ") for '" + service->GetName() + "'");
|
||||
|
||||
/* Status */
|
||||
DbQuery query1;
|
||||
|
@ -670,7 +670,7 @@ void ServiceDbObject::RemoveDowntime(const Service::Ptr& service, const Dictiona
|
|||
query1.Category = DbCatDowntime;
|
||||
query1.WhereCriteria = make_shared<Dictionary>();
|
||||
query1.WhereCriteria->Set("object_id", service);
|
||||
query1.WhereCriteria->Set("internal_downtime_id", downtime->Get("legacy_id"));
|
||||
query1.WhereCriteria->Set("internal_downtime_id", downtime->GetLegacyId());
|
||||
OnQuery(query1);
|
||||
|
||||
/* delete hostcheck service's host comments */
|
||||
|
@ -689,22 +689,22 @@ void ServiceDbObject::RemoveDowntime(const Service::Ptr& service, const Dictiona
|
|||
query3.Category = DbCatDowntime;
|
||||
|
||||
Dictionary::Ptr fields3 = make_shared<Dictionary>();
|
||||
fields3->Set("was_cancelled", downtime->Get("was_cancelled") ? 1 : 0);
|
||||
fields3->Set("was_cancelled", downtime->GetWasCancelled() ? 1 : 0);
|
||||
fields3->Set("actual_end_time", DbValue::FromTimestamp(time_bag->Get("time_sec")));
|
||||
fields3->Set("actual_end_time_usec", time_bag->Get("time_usec"));
|
||||
query3.Fields = fields3;
|
||||
|
||||
query3.WhereCriteria = make_shared<Dictionary>();
|
||||
query3.WhereCriteria->Set("internal_downtime_id", downtime->Get("legacy_id"));
|
||||
query3.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(downtime->Get("entry_time")));
|
||||
query3.WhereCriteria->Set("scheduled_start_time", DbValue::FromTimestamp(downtime->Get("start_time")));
|
||||
query3.WhereCriteria->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->Get("end_time")));
|
||||
query3.WhereCriteria->Set("internal_downtime_id", downtime->GetLegacyId());
|
||||
query3.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(downtime->GetEntryTime()));
|
||||
query3.WhereCriteria->Set("scheduled_start_time", DbValue::FromTimestamp(downtime->GetStartTime()));
|
||||
query3.WhereCriteria->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->GetEndTime()));
|
||||
query3.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||
|
||||
OnQuery(query3);
|
||||
}
|
||||
|
||||
void ServiceDbObject::TriggerDowntime(const Service::Ptr& service, const Dictionary::Ptr& downtime)
|
||||
void ServiceDbObject::TriggerDowntime(const Service::Ptr& service, const Downtime::Ptr& downtime)
|
||||
{
|
||||
Host::Ptr host = service->GetHost();
|
||||
|
||||
|
@ -716,7 +716,7 @@ void ServiceDbObject::TriggerDowntime(const Service::Ptr& service, const Diction
|
|||
return;
|
||||
}
|
||||
|
||||
Log(LogDebug, "db_ido", "updating triggered service downtime (id = " + downtime->Get("legacy_id") + ") for '" + service->GetName() + "'");
|
||||
Log(LogDebug, "db_ido", "updating triggered service downtime (id = " + Convert::ToString(downtime->GetLegacyId()) + ") for '" + service->GetName() + "'");
|
||||
|
||||
double now = Utility::GetTime();
|
||||
Dictionary::Ptr time_bag = CompatUtility::ConvertTimestamp(now);
|
||||
|
@ -732,12 +732,12 @@ void ServiceDbObject::TriggerDowntime(const Service::Ptr& service, const Diction
|
|||
fields1->Set("actual_start_time", DbValue::FromTimestamp(time_bag->Get("time_sec")));
|
||||
fields1->Set("actual_start_time_usec", time_bag->Get("time_usec"));
|
||||
fields1->Set("is_in_effect", 1);
|
||||
fields1->Set("trigger_time", DbValue::FromTimestamp(downtime->Get("trigger_time")));
|
||||
fields1->Set("trigger_time", DbValue::FromTimestamp(downtime->GetTriggerTime()));
|
||||
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||
|
||||
query1.WhereCriteria = make_shared<Dictionary>();
|
||||
query1.WhereCriteria->Set("object_id", service);
|
||||
query1.WhereCriteria->Set("internal_downtime_id", downtime->Get("legacy_id"));
|
||||
query1.WhereCriteria->Set("internal_downtime_id", downtime->GetLegacyId());
|
||||
|
||||
query1.Fields = fields1;
|
||||
OnQuery(query1);
|
||||
|
@ -759,14 +759,14 @@ void ServiceDbObject::TriggerDowntime(const Service::Ptr& service, const Diction
|
|||
fields3->Set("is_in_effect", 1);
|
||||
fields3->Set("actual_start_time", DbValue::FromTimestamp(time_bag->Get("time_sec")));
|
||||
fields3->Set("actual_start_time_usec", time_bag->Get("time_usec"));
|
||||
fields3->Set("trigger_time", DbValue::FromTimestamp(downtime->Get("trigger_time")));
|
||||
fields3->Set("trigger_time", DbValue::FromTimestamp(downtime->GetTriggerTime()));
|
||||
query3.Fields = fields3;
|
||||
|
||||
query3.WhereCriteria = make_shared<Dictionary>();
|
||||
query3.WhereCriteria->Set("internal_downtime_id", downtime->Get("legacy_id"));
|
||||
query3.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(downtime->Get("entry_time")));
|
||||
query3.WhereCriteria->Set("scheduled_start_time", DbValue::FromTimestamp(downtime->Get("start_time")));
|
||||
query3.WhereCriteria->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->Get("end_time")));
|
||||
query3.WhereCriteria->Set("internal_downtime_id", downtime->GetLegacyId());
|
||||
query3.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(downtime->GetEntryTime()));
|
||||
query3.WhereCriteria->Set("scheduled_start_time", DbValue::FromTimestamp(downtime->GetStartTime()));
|
||||
query3.WhereCriteria->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->GetEndTime()));
|
||||
query3.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||
|
||||
OnQuery(query3);
|
||||
|
@ -1056,7 +1056,7 @@ void ServiceDbObject::AddCheckResultLogHistory(const Service::Ptr& service, cons
|
|||
}
|
||||
}
|
||||
|
||||
void ServiceDbObject::AddTriggerDowntimeLogHistory(const Service::Ptr& service, const Dictionary::Ptr& downtime)
|
||||
void ServiceDbObject::AddTriggerDowntimeLogHistory(const Service::Ptr& service, const Downtime::Ptr& downtime)
|
||||
{
|
||||
Host::Ptr host = service->GetHost();
|
||||
|
||||
|
@ -1088,7 +1088,7 @@ void ServiceDbObject::AddTriggerDowntimeLogHistory(const Service::Ptr& service,
|
|||
}
|
||||
}
|
||||
|
||||
void ServiceDbObject::AddRemoveDowntimeLogHistory(const Service::Ptr& service, const Dictionary::Ptr& downtime)
|
||||
void ServiceDbObject::AddRemoveDowntimeLogHistory(const Service::Ptr& service, const Downtime::Ptr& downtime)
|
||||
{
|
||||
Host::Ptr host = service->GetHost();
|
||||
|
||||
|
@ -1101,7 +1101,7 @@ void ServiceDbObject::AddRemoveDowntimeLogHistory(const Service::Ptr& service, c
|
|||
String downtime_output;
|
||||
String downtime_state_str;
|
||||
|
||||
if (downtime->Get("was_cancelled") == true) {
|
||||
if (downtime->GetWasCancelled()) {
|
||||
downtime_output = "Scheduled downtime for service has been cancelled.";
|
||||
downtime_state_str = "CANCELLED";
|
||||
} else {
|
||||
|
|
|
@ -80,8 +80,8 @@ private:
|
|||
static void AddComments(const Service::Ptr& service);
|
||||
static void RemoveComments(const Service::Ptr& service);
|
||||
|
||||
static void AddDowntimeInternal(const Service::Ptr& service, const Dictionary::Ptr& downtime, bool historical);
|
||||
static void AddDowntimeByType(const DynamicObject::Ptr& object, const Dictionary::Ptr& downtime, bool historical);
|
||||
static void AddDowntimeInternal(const Service::Ptr& service, const Downtime::Ptr& downtime, bool historical);
|
||||
static void AddDowntimeByType(const DynamicObject::Ptr& object, const Downtime::Ptr& downtime, bool historical);
|
||||
static void AddDowntimes(const Service::Ptr& service);
|
||||
static void RemoveDowntimes(const Service::Ptr& service);
|
||||
|
||||
|
@ -91,21 +91,21 @@ private:
|
|||
static void AddComment(const Service::Ptr& service, const Comment::Ptr& comment);
|
||||
static void RemoveComment(const Service::Ptr& service, const Comment::Ptr& comment);
|
||||
|
||||
static void AddDowntime(const Service::Ptr& service, const Dictionary::Ptr& downtime);
|
||||
static void RemoveDowntime(const Service::Ptr& service, const Dictionary::Ptr& downtime);
|
||||
static void TriggerDowntime(const Service::Ptr& service, const Dictionary::Ptr& downtime);
|
||||
static void AddDowntime(const Service::Ptr& service, const Downtime::Ptr& downtime);
|
||||
static void RemoveDowntime(const Service::Ptr& service, const Downtime::Ptr& downtime);
|
||||
static void TriggerDowntime(const Service::Ptr& service, const Downtime::Ptr& downtime);
|
||||
|
||||
/* History */
|
||||
static void AddCommentHistory(const Service::Ptr& service, const Comment::Ptr& comment);
|
||||
static void AddDowntimeHistory(const Service::Ptr& service, const Dictionary::Ptr& downtime);
|
||||
static void AddDowntimeHistory(const Service::Ptr& service, const Downtime::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<User::Ptr>& users, NotificationType type, const CheckResult::Ptr& cr, const String& author, const String& text);
|
||||
static void AddStateChangeHistory(const Service::Ptr& service, const CheckResult::Ptr& cr, StateType type);
|
||||
|
||||
static void AddCheckResultLogHistory(const Service::Ptr& service, const CheckResult::Ptr &cr);
|
||||
static void AddTriggerDowntimeLogHistory(const Service::Ptr& service, const Dictionary::Ptr& downtime);
|
||||
static void AddRemoveDowntimeLogHistory(const Service::Ptr& service, const Dictionary::Ptr& downtime);
|
||||
static void AddTriggerDowntimeLogHistory(const Service::Ptr& service, const Downtime::Ptr& downtime);
|
||||
static void AddRemoveDowntimeLogHistory(const Service::Ptr& service, const Downtime::Ptr& downtime);
|
||||
static void AddNotificationSentLogHistory(const Service::Ptr& service, const User::Ptr& user, NotificationType notification_type, const CheckResult::Ptr& cr, const String& author, const String& comment_text);
|
||||
static void AddFlappingLogHistory(const Service::Ptr& service, FlappingState flapping_state);
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ mkclass_target(checkresult.ti checkresult.th)
|
|||
mkclass_target(command.ti command.th)
|
||||
mkclass_target(comment.ti comment.th)
|
||||
mkclass_target(domain.ti domain.th)
|
||||
mkclass_target(downtime.ti downtime.th)
|
||||
mkclass_target(eventcommand.ti eventcommand.th)
|
||||
mkclass_target(hostgroup.ti hostgroup.th)
|
||||
mkclass_target(host.ti host.th)
|
||||
|
@ -38,14 +39,15 @@ mkembedconfig_target(icinga-type.conf icinga-type.cpp)
|
|||
add_library(icinga SHARED
|
||||
api.cpp api.h checkcommand.cpp checkcommand.th checkresult.cpp checkresult.th
|
||||
cib.cpp command.cpp command.th comment.cpp comment.th compatutility.cpp
|
||||
domain.cpp domain.th eventcommand.cpp eventcommand.th externalcommandprocessor.cpp host.cpp
|
||||
host.th hostgroup.cpp hostgroup.th icingaapplication.cpp icingaapplication.th
|
||||
macroprocessor.cpp macroresolver.cpp notificationcommand.cpp notificationcommand.th
|
||||
notification.cpp notification.th perfdatavalue.cpp perfdatavalue.th
|
||||
pluginutility.cpp service-check.cpp service-comment.cpp service.cpp
|
||||
service-downtime.cpp service-event.cpp service-flapping.cpp service.th
|
||||
servicegroup.cpp servicegroup.th service-notification.cpp timeperiod.cpp
|
||||
timeperiod.th user.cpp user.th usergroup.cpp usergroup.th icinga-type.cpp
|
||||
domain.cpp domain.th downtime.cpp downtime.th eventcommand.cpp eventcommand.th
|
||||
externalcommandprocessor.cpp host.cpp host.th hostgroup.cpp hostgroup.th
|
||||
icingaapplication.cpp icingaapplication.th macroprocessor.cpp macroresolver.cpp
|
||||
notificationcommand.cpp notificationcommand.th notification.cpp notification.th
|
||||
perfdatavalue.cpp perfdatavalue.th pluginutility.cpp service-check.cpp
|
||||
service-comment.cpp service.cpp service-downtime.cpp service-event.cpp
|
||||
service-flapping.cpp service.th servicegroup.cpp servicegroup.th
|
||||
service-notification.cpp timeperiod.cpp timeperiod.th user.cpp user.th
|
||||
usergroup.cpp usergroup.th icinga-type.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(icinga ${Boost_LIBRARIES} base config)
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012-2013 Icinga Development Team (http://www.icinga.org/) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software Foundation *
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#include "icinga/downtime.h"
|
||||
#include "base/dynamictype.h"
|
||||
|
||||
using namespace icinga;
|
||||
|
||||
REGISTER_TYPE(Downtime);
|
|
@ -0,0 +1,42 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012-2013 Icinga Development Team (http://www.icinga.org/) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software Foundation *
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef DOWNTIME_H
|
||||
#define DOWNTIME_H
|
||||
|
||||
#include "icinga/i2-icinga.h"
|
||||
#include "icinga/downtime.th"
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
||||
/**
|
||||
* A service downtime.
|
||||
*
|
||||
* @ingroup icinga
|
||||
*/
|
||||
class I2_ICINGA_API Downtime : public ObjectImpl<Downtime>
|
||||
{
|
||||
public:
|
||||
DECLARE_PTR_TYPEDEFS(Downtime);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* DOWNTIME_H */
|
|
@ -0,0 +1,23 @@
|
|||
namespace icinga
|
||||
{
|
||||
|
||||
class Downtime
|
||||
{
|
||||
[state] String id;
|
||||
[state] double entry_time;
|
||||
[state] String author;
|
||||
[state] String comment;
|
||||
[state] double start_time;
|
||||
[state] double end_time;
|
||||
[state] double trigger_time;
|
||||
[state] bool fixed;
|
||||
[state] double duration;
|
||||
[state] String triggered_by;
|
||||
[state] Dictionary::Ptr triggers {
|
||||
default {{{ return make_shared<Dictionary>(); }}}
|
||||
};
|
||||
[state] int legacy_id;
|
||||
[state] bool was_cancelled;
|
||||
};
|
||||
|
||||
}
|
|
@ -1009,8 +1009,7 @@ void ExternalCommandProcessor::ScheduleSvcDowntime(double, const std::vector<Str
|
|||
triggeredBy = Service::GetDowntimeIDFromLegacyID(triggeredByLegacy);
|
||||
|
||||
Log(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
|
||||
String comment_id = service->AddComment(CommentDowntime, arguments[7], arguments[8], Convert::ToDouble(arguments[3]));
|
||||
(void) service->AddDowntime(comment_id,
|
||||
(void) service->AddDowntime(arguments[7], arguments[8],
|
||||
Convert::ToDouble(arguments[2]), Convert::ToDouble(arguments[3]),
|
||||
Convert::ToBool(arguments[4]), triggeredBy, Convert::ToDouble(arguments[6]));
|
||||
}
|
||||
|
@ -1044,8 +1043,7 @@ void ExternalCommandProcessor::ScheduleHostDowntime(double, const std::vector<St
|
|||
Log(LogInformation, "icinga", "Creating downtime for host " + host->GetName());
|
||||
Service::Ptr service = host->GetCheckService();
|
||||
if (service) {
|
||||
String comment_id = service->AddComment(CommentDowntime, arguments[6], arguments[7], Convert::ToDouble(arguments[2]));
|
||||
(void) service->AddDowntime(comment_id,
|
||||
(void) service->AddDowntime(arguments[6], arguments[7],
|
||||
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
|
||||
Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
|
||||
}
|
||||
|
@ -1079,8 +1077,7 @@ void ExternalCommandProcessor::ScheduleHostSvcDowntime(double, const std::vector
|
|||
|
||||
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
|
||||
Log(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
|
||||
String comment_id = service->AddComment(CommentDowntime, arguments[6], arguments[7], Convert::ToDouble(arguments[2]));
|
||||
(void) service->AddDowntime(comment_id,
|
||||
(void) service->AddDowntime(arguments[6], arguments[7],
|
||||
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
|
||||
Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
|
||||
}
|
||||
|
@ -1105,8 +1102,7 @@ void ExternalCommandProcessor::ScheduleHostgroupHostDowntime(double, const std::
|
|||
Log(LogInformation, "icinga", "Creating downtime for host " + host->GetName());
|
||||
Service::Ptr service = host->GetCheckService();
|
||||
if (service) {
|
||||
String comment_id = service->AddComment(CommentDowntime, arguments[6], arguments[7], Convert::ToDouble(arguments[2]));
|
||||
(void) service->AddDowntime(comment_id,
|
||||
(void) service->AddDowntime(arguments[6], arguments[7],
|
||||
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
|
||||
Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
|
||||
}
|
||||
|
@ -1142,8 +1138,7 @@ void ExternalCommandProcessor::ScheduleHostgroupSvcDowntime(double, const std::v
|
|||
|
||||
BOOST_FOREACH(const Service::Ptr& service, services) {
|
||||
Log(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
|
||||
String comment_id = service->AddComment(CommentDowntime, arguments[6], arguments[7], Convert::ToDouble(arguments[2]));
|
||||
(void) service->AddDowntime(comment_id,
|
||||
(void) service->AddDowntime(arguments[6], arguments[7],
|
||||
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
|
||||
Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
|
||||
}
|
||||
|
@ -1179,8 +1174,7 @@ void ExternalCommandProcessor::ScheduleServicegroupHostDowntime(double, const st
|
|||
|
||||
BOOST_FOREACH(const Service::Ptr& service, services) {
|
||||
Log(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
|
||||
String comment_id = service->AddComment(CommentDowntime, arguments[6], arguments[7], Convert::ToDouble(arguments[2]));
|
||||
(void) service->AddDowntime(comment_id,
|
||||
(void) service->AddDowntime(arguments[6], arguments[7],
|
||||
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
|
||||
Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
|
||||
}
|
||||
|
@ -1203,8 +1197,7 @@ void ExternalCommandProcessor::ScheduleServicegroupSvcDowntime(double, const std
|
|||
|
||||
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
|
||||
Log(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
|
||||
String comment_id = service->AddComment(CommentDowntime, arguments[6], arguments[7], Convert::ToDouble(arguments[2]));
|
||||
(void) service->AddDowntime(comment_id,
|
||||
(void) service->AddDowntime(arguments[6], arguments[7],
|
||||
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
|
||||
Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "base/logger_fwd.h"
|
||||
#include "base/timer.h"
|
||||
#include "base/utility.h"
|
||||
#include "base/convert.h"
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
|
@ -34,9 +35,9 @@ static std::map<int, String> l_LegacyDowntimesCache;
|
|||
static std::map<String, Service::WeakPtr> l_DowntimesCache;
|
||||
static Timer::Ptr l_DowntimesExpireTimer;
|
||||
|
||||
boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&, const String&)> Service::OnDowntimeAdded;
|
||||
boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&, const String&)> Service::OnDowntimeRemoved;
|
||||
boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&)> Service::OnDowntimeTriggered;
|
||||
boost::signals2::signal<void (const Service::Ptr&, const Downtime::Ptr&, const String&)> Service::OnDowntimeAdded;
|
||||
boost::signals2::signal<void (const Service::Ptr&, const Downtime::Ptr&, const String&)> Service::OnDowntimeRemoved;
|
||||
boost::signals2::signal<void (const Service::Ptr&, const Downtime::Ptr&)> Service::OnDowntimeTriggered;
|
||||
|
||||
int Service::GetNextDowntimeID(void)
|
||||
{
|
||||
|
@ -45,7 +46,7 @@ int Service::GetNextDowntimeID(void)
|
|||
return l_NextDowntimeID;
|
||||
}
|
||||
|
||||
String Service::AddDowntime(const String& comment_id,
|
||||
String Service::AddDowntime(const String& author, const String& comment,
|
||||
double startTime, double endTime, bool fixed,
|
||||
const String& triggeredBy, double duration, const String& id, const String& authority)
|
||||
{
|
||||
|
@ -56,17 +57,16 @@ String Service::AddDowntime(const String& comment_id,
|
|||
else
|
||||
uid = id;
|
||||
|
||||
Dictionary::Ptr downtime = make_shared<Dictionary>();
|
||||
downtime->Set("id", uid);
|
||||
downtime->Set("entry_time", Utility::GetTime());
|
||||
downtime->Set("comment_id", comment_id);
|
||||
downtime->Set("start_time", startTime);
|
||||
downtime->Set("end_time", endTime);
|
||||
downtime->Set("fixed", fixed);
|
||||
downtime->Set("duration", duration);
|
||||
downtime->Set("triggered_by", triggeredBy);
|
||||
downtime->Set("triggers", make_shared<Dictionary>());
|
||||
downtime->Set("trigger_time", 0);
|
||||
Downtime::Ptr downtime = make_shared<Downtime>();
|
||||
downtime->SetId(uid);
|
||||
downtime->SetEntryTime(Utility::GetTime());
|
||||
downtime->SetAuthor(author);
|
||||
downtime->SetComment(comment);
|
||||
downtime->SetStartTime(startTime);
|
||||
downtime->SetEndTime(endTime);
|
||||
downtime->SetFixed(fixed);
|
||||
downtime->SetDuration(duration);
|
||||
downtime->SetTriggeredBy(triggeredBy);
|
||||
|
||||
int legacy_id;
|
||||
|
||||
|
@ -75,13 +75,13 @@ String Service::AddDowntime(const String& comment_id,
|
|||
legacy_id = l_NextDowntimeID++;
|
||||
}
|
||||
|
||||
downtime->Set("legacy_id", legacy_id);
|
||||
downtime->SetLegacyId(legacy_id);
|
||||
|
||||
if (!triggeredBy.IsEmpty()) {
|
||||
Service::Ptr otherOwner = GetOwnerByDowntimeID(triggeredBy);
|
||||
Dictionary::Ptr otherDowntimes = otherOwner->GetDowntimes();
|
||||
Dictionary::Ptr otherDowntime = otherDowntimes->Get(triggeredBy);
|
||||
Dictionary::Ptr triggers = otherDowntime->Get("triggers");
|
||||
Downtime::Ptr otherDowntime = otherDowntimes->Get(triggeredBy);
|
||||
Dictionary::Ptr triggers = otherDowntime->GetTriggers();
|
||||
|
||||
{
|
||||
ObjectLock olock(otherOwner);
|
||||
|
@ -97,7 +97,7 @@ String Service::AddDowntime(const String& comment_id,
|
|||
l_DowntimesCache[uid] = GetSelf();
|
||||
}
|
||||
|
||||
Log(LogWarning, "icinga", "added downtime with ID '" + downtime->Get("legacy_id") + "'.");
|
||||
Log(LogWarning, "icinga", "added downtime with ID '" + Convert::ToString(downtime->GetLegacyId()) + "'.");
|
||||
|
||||
Utility::QueueAsyncCallback(boost::bind(boost::ref(OnDowntimeAdded), GetSelf(), downtime, authority));
|
||||
|
||||
|
@ -113,14 +113,12 @@ void Service::RemoveDowntime(const String& id, bool cancelled, const String& aut
|
|||
|
||||
Dictionary::Ptr downtimes = owner->GetDowntimes();
|
||||
|
||||
Dictionary::Ptr downtime = downtimes->Get(id);
|
||||
Downtime::Ptr downtime = downtimes->Get(id);
|
||||
|
||||
if (!downtime)
|
||||
return;
|
||||
|
||||
String comment_id = downtime->Get("comment_id");
|
||||
|
||||
int legacy_id = downtime->Get("legacy_id");
|
||||
int legacy_id = downtime->GetLegacyId();
|
||||
|
||||
downtimes->Remove(id);
|
||||
|
||||
|
@ -130,11 +128,9 @@ void Service::RemoveDowntime(const String& id, bool cancelled, const String& aut
|
|||
l_DowntimesCache.erase(id);
|
||||
}
|
||||
|
||||
RemoveComment(comment_id);
|
||||
downtime->SetWasCancelled(cancelled);
|
||||
|
||||
downtime->Set("was_cancelled", cancelled);
|
||||
|
||||
Log(LogWarning, "icinga", "removed downtime with ID '" + downtime->Get("legacy_id") + "' from service '" + owner->GetName() + "'.");
|
||||
Log(LogWarning, "icinga", "removed downtime with ID '" + Convert::ToString(downtime->GetLegacyId()) + "' from service '" + owner->GetName() + "'.");
|
||||
|
||||
Utility::QueueAsyncCallback(boost::bind(boost::ref(OnDowntimeRemoved), owner, downtime, authority));
|
||||
}
|
||||
|
@ -162,33 +158,33 @@ void Service::TriggerDowntimes(void)
|
|||
void Service::TriggerDowntime(const String& id)
|
||||
{
|
||||
Service::Ptr owner = GetOwnerByDowntimeID(id);
|
||||
Dictionary::Ptr downtime = GetDowntimeByID(id);
|
||||
Downtime::Ptr downtime = GetDowntimeByID(id);
|
||||
|
||||
if (!downtime)
|
||||
return;
|
||||
|
||||
if (IsDowntimeActive(downtime) && IsDowntimeTriggered(downtime)) {
|
||||
Log(LogDebug, "icinga", "Not triggering downtime with ID '" + downtime->Get("legacy_id") + "': already triggered.");
|
||||
Log(LogDebug, "icinga", "Not triggering downtime with ID '" + Convert::ToString(downtime->GetLegacyId()) + "': already triggered.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsDowntimeExpired(downtime)) {
|
||||
Log(LogDebug, "icinga", "Not triggering downtime with ID '" + downtime->Get("legacy_id") + "': expired.");
|
||||
Log(LogDebug, "icinga", "Not triggering downtime with ID '" + Convert::ToString(downtime->GetLegacyId()) + "': expired.");
|
||||
return;
|
||||
}
|
||||
|
||||
double now = Utility::GetTime();
|
||||
|
||||
if (now < downtime->Get("start_time") ||
|
||||
now > downtime->Get("end_time"))
|
||||
if (now < downtime->GetStartTime() ||
|
||||
now > downtime->GetEndTime())
|
||||
return;
|
||||
|
||||
Log(LogDebug, "icinga", "Triggering downtime with ID '" + downtime->Get("legacy_id") + "'.");
|
||||
Log(LogDebug, "icinga", "Triggering downtime with ID '" + Convert::ToString(downtime->GetLegacyId()) + "'.");
|
||||
|
||||
if (downtime->Get("trigger_time") == 0)
|
||||
downtime->Set("trigger_time", now);
|
||||
if (downtime->GetTriggerTime() == 0)
|
||||
downtime->SetTriggerTime(now);
|
||||
|
||||
Dictionary::Ptr triggers = downtime->Get("triggers");
|
||||
Dictionary::Ptr triggers = downtime->GetTriggers();
|
||||
ObjectLock olock(triggers);
|
||||
String tid;
|
||||
BOOST_FOREACH(boost::tie(tid, boost::tuples::ignore), triggers) {
|
||||
|
@ -216,52 +212,52 @@ Service::Ptr Service::GetOwnerByDowntimeID(const String& id)
|
|||
return l_DowntimesCache[id].lock();
|
||||
}
|
||||
|
||||
Dictionary::Ptr Service::GetDowntimeByID(const String& id)
|
||||
Downtime::Ptr Service::GetDowntimeByID(const String& id)
|
||||
{
|
||||
Service::Ptr owner = GetOwnerByDowntimeID(id);
|
||||
|
||||
if (!owner)
|
||||
return Dictionary::Ptr();
|
||||
return Downtime::Ptr();
|
||||
|
||||
Dictionary::Ptr downtimes = owner->GetDowntimes();
|
||||
|
||||
if (downtimes)
|
||||
return downtimes->Get(id);
|
||||
|
||||
return Dictionary::Ptr();
|
||||
return Downtime::Ptr();
|
||||
}
|
||||
|
||||
bool Service::IsDowntimeActive(const Dictionary::Ptr& downtime)
|
||||
bool Service::IsDowntimeActive(const Downtime::Ptr& downtime)
|
||||
{
|
||||
double now = Utility::GetTime();
|
||||
|
||||
if (now < downtime->Get("start_time") ||
|
||||
now > downtime->Get("end_time"))
|
||||
if (now < downtime->GetStartTime() ||
|
||||
now > downtime->GetEndTime())
|
||||
return false;
|
||||
|
||||
if (static_cast<bool>(downtime->Get("fixed")))
|
||||
if (downtime->GetFixed())
|
||||
return true;
|
||||
|
||||
double triggerTime = downtime->Get("trigger_time");
|
||||
double triggerTime = downtime->GetTriggerTime();
|
||||
|
||||
if (triggerTime == 0)
|
||||
return false;
|
||||
|
||||
return (triggerTime + downtime->Get("duration") < now);
|
||||
return (triggerTime + downtime->GetDuration() < now);
|
||||
}
|
||||
|
||||
bool Service::IsDowntimeTriggered(const Dictionary::Ptr& downtime)
|
||||
bool Service::IsDowntimeTriggered(const Downtime::Ptr& downtime)
|
||||
{
|
||||
double now = Utility::GetTime();
|
||||
|
||||
double triggerTime = downtime->Get("trigger_time");
|
||||
double triggerTime = downtime->GetTriggerTime();
|
||||
|
||||
return (triggerTime > 0 && triggerTime <= now);
|
||||
}
|
||||
|
||||
bool Service::IsDowntimeExpired(const Dictionary::Ptr& downtime)
|
||||
bool Service::IsDowntimeExpired(const Downtime::Ptr& downtime)
|
||||
{
|
||||
return (downtime->Get("end_time") < Utility::GetTime());
|
||||
return (downtime->GetEndTime() < Utility::GetTime());
|
||||
}
|
||||
|
||||
void Service::StartDowntimesExpiredTimer(void)
|
||||
|
@ -285,9 +281,9 @@ void Service::AddDowntimesToCache(void)
|
|||
ObjectLock olock(downtimes);
|
||||
|
||||
String id;
|
||||
Dictionary::Ptr downtime;
|
||||
Downtime::Ptr downtime;
|
||||
BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
|
||||
int legacy_id = downtime->Get("legacy_id");
|
||||
int legacy_id = downtime->GetLegacyId();
|
||||
|
||||
if (legacy_id >= l_NextDowntimeID)
|
||||
l_NextDowntimeID = legacy_id + 1;
|
||||
|
@ -307,7 +303,7 @@ void Service::RemoveExpiredDowntimes(void)
|
|||
ObjectLock olock(downtimes);
|
||||
|
||||
String id;
|
||||
Dictionary::Ptr downtime;
|
||||
Downtime::Ptr downtime;
|
||||
BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
|
||||
if (IsDowntimeExpired(downtime))
|
||||
expiredDowntimes.push_back(id);
|
||||
|
@ -332,7 +328,7 @@ bool Service::IsInDowntime(void) const
|
|||
|
||||
ObjectLock olock(downtimes);
|
||||
|
||||
Dictionary::Ptr downtime;
|
||||
Downtime::Ptr downtime;
|
||||
BOOST_FOREACH(boost::tie(boost::tuples::ignore, downtime), downtimes) {
|
||||
if (Service::IsDowntimeActive(downtime))
|
||||
return true;
|
||||
|
@ -348,7 +344,7 @@ int Service::GetDowntimeDepth(void) const
|
|||
|
||||
ObjectLock olock(downtimes);
|
||||
|
||||
Dictionary::Ptr downtime;
|
||||
Downtime::Ptr downtime;
|
||||
BOOST_FOREACH(boost::tie(boost::tuples::ignore, downtime), downtimes) {
|
||||
if (Service::IsDowntimeActive(downtime))
|
||||
downtime_depth++;
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "icinga/timeperiod.h"
|
||||
#include "icinga/notification.h"
|
||||
#include "icinga/comment.h"
|
||||
#include "icinga/downtime.h"
|
||||
#include "base/i2-base.h"
|
||||
#include "base/array.h"
|
||||
#include <boost/signals2.hpp>
|
||||
|
@ -35,18 +36,6 @@
|
|||
namespace icinga
|
||||
{
|
||||
|
||||
/**
|
||||
* The state of a service downtime.
|
||||
*
|
||||
* @ingroup icinga
|
||||
*/
|
||||
enum DowntimeState
|
||||
{
|
||||
DowntimeStarted = 0,
|
||||
DowntimeCancelled = 1,
|
||||
DowntimeStopped = 2
|
||||
};
|
||||
|
||||
/**
|
||||
* The state of service flapping.
|
||||
*
|
||||
|
@ -60,18 +49,6 @@ enum FlappingState
|
|||
FlappingEnabled = 3
|
||||
};
|
||||
|
||||
/**
|
||||
* The state of a changed downtime
|
||||
*
|
||||
* @ingroup icinga
|
||||
*/
|
||||
enum DowntimeChangedType
|
||||
{
|
||||
DowntimeChangedAdded = 0,
|
||||
DowntimeChangedUpdated = 1,
|
||||
DowntimeChangedDeleted = 2
|
||||
};
|
||||
|
||||
/**
|
||||
* Modified attributes.
|
||||
*
|
||||
|
@ -191,10 +168,10 @@ public:
|
|||
static boost::signals2::signal<void (const Service::Ptr&, const std::set<User::Ptr>&, const NotificationType&, const CheckResult::Ptr&, const String&, const String&)> OnNotificationSentToAllUsers;
|
||||
static boost::signals2::signal<void (const Service::Ptr&, const Comment::Ptr&, const String&)> OnCommentAdded;
|
||||
static boost::signals2::signal<void (const Service::Ptr&, const Comment::Ptr&, const String&)> OnCommentRemoved;
|
||||
static boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&, const String&)> OnDowntimeAdded;
|
||||
static boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&, const String&)> OnDowntimeRemoved;
|
||||
static boost::signals2::signal<void (const Service::Ptr&, const Downtime::Ptr&, const String&)> OnDowntimeAdded;
|
||||
static boost::signals2::signal<void (const Service::Ptr&, const Downtime::Ptr&, const String&)> OnDowntimeRemoved;
|
||||
static boost::signals2::signal<void (const Service::Ptr&, FlappingState)> OnFlappingChanged;
|
||||
static boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&)> OnDowntimeTriggered;
|
||||
static boost::signals2::signal<void (const Service::Ptr&, const Downtime::Ptr&)> OnDowntimeTriggered;
|
||||
static boost::signals2::signal<void (const Service::Ptr&, const String&, const String&, AcknowledgementType, double, const String&)> OnAcknowledgementSet;
|
||||
static boost::signals2::signal<void (const Service::Ptr&, const String&)> OnAcknowledgementCleared;
|
||||
static boost::signals2::signal<void (const Service::Ptr&)> OnEventCommandExecuted;
|
||||
|
@ -206,7 +183,7 @@ public:
|
|||
|
||||
int GetDowntimeDepth(void) const;
|
||||
|
||||
String AddDowntime(const String& comment_id,
|
||||
String AddDowntime(const String& author, const String& comment,
|
||||
double startTime, double endTime, bool fixed,
|
||||
const String& triggeredBy, double duration,
|
||||
const String& id = String(), const String& authority = String());
|
||||
|
@ -218,11 +195,11 @@ public:
|
|||
|
||||
static String GetDowntimeIDFromLegacyID(int id);
|
||||
static Service::Ptr GetOwnerByDowntimeID(const String& id);
|
||||
static Dictionary::Ptr GetDowntimeByID(const String& id);
|
||||
static Downtime::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);
|
||||
static bool IsDowntimeActive(const Downtime::Ptr& downtime);
|
||||
static bool IsDowntimeTriggered(const Downtime::Ptr& downtime);
|
||||
static bool IsDowntimeExpired(const Downtime::Ptr& downtime);
|
||||
|
||||
void StartDowntimesExpiredTimer(void);
|
||||
|
||||
|
|
Loading…
Reference in New Issue