}
#endif /* _WIN32 */
+void CompatComponent::DumpDowntimes(ofstream& fp, const DynamicObject::Ptr& owner)
+{
+ Service::Ptr service;
+ Host::Ptr host;
+ Dictionary::Ptr downtimes;
+
+ if (owner->GetType() == DynamicType::GetByName("Service")) {
+ service = dynamic_pointer_cast<Service>(owner);
+ downtimes = service->GetDowntimes();
+
+ host = service->GetHost();
+ } else {
+ host = dynamic_pointer_cast<Host>(owner);
+ downtimes = host->GetDowntimes();
+ }
+
+ if (!downtimes)
+ return;
+
+ String id;
+ Dictionary::Ptr downtime;
+ BOOST_FOREACH(tie(id, downtime), downtimes) {
+ if (!service)
+ fp << "hostdowntime {" << "\n";
+ else
+ fp << "servicedowntime {" << "\n"
+ << "\t" << "service_description=" << service->GetAlias() << "\n";
+
+ fp << "\t" << "host_name=" << host->GetName() << "\n"
+ << "\t" << "downtime_id=" << 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" << "triggered_by=" << static_cast<long>(downtime->Get("triggered_by")) << "\n"
+ << "\t" << "fixed=" << static_cast<long>(downtime->Get("fixed")) << "\n"
+ << "\t" << "duration=" << static_cast<long>(downtime->Get("duration")) << "\n"
+ << "\t" << "is_in_effect=" << (DowntimeProcessor::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=" << 0 << "\n"
+ << "\t" << "}" << "\n"
+ << "\n";
+ }
+}
+
void CompatComponent::DumpHostStatus(ofstream& fp, const Host::Ptr& host)
{
int state;
<< "\t" << "problem_has_been_acknowledged=" << (host->GetAcknowledgement() != AcknowledgementNone ? 1 : 0) << "\n"
<< "\t" << "acknowledgement_type=" << static_cast<int>(host->GetAcknowledgement()) << "\n"
<< "\t" << "acknowledgement_end_time=" << host->GetAcknowledgementExpiry() << "\n"
+ << "\t" << "scheduled_downtime_depth=" << (host->IsInDowntime() ? 1 : 0) << "\n"
<< "\t" << "}" << "\n"
<< "\n";
+
+ DumpDowntimes(fp, host);
}
void CompatComponent::DumpHostObject(ofstream& fp, const Host::Ptr& host)
<< "\t" << "problem_has_been_acknowledged=" << (service->GetAcknowledgement() != AcknowledgementNone ? 1 : 0) << "\n"
<< "\t" << "acknowledgement_type=" << static_cast<int>(service->GetAcknowledgement()) << "\n"
<< "\t" << "acknowledgement_end_time=" << service->GetAcknowledgementExpiry() << "\n"
+ << "\t" << "scheduled_downtime_depth=" << (service->IsInDowntime() ? 1 : 0) << "\n"
<< "\t" << "}" << "\n"
<< "\n";
+
+ DumpDowntimes(fp, service);
}
void CompatComponent::DumpServiceObject(ofstream& fp, const Service::Ptr& service)
<< "\t" << "enable_failure_prediction=0" << "\n"
<< "\t" << "active_scheduled_service_check_stats=" << CIB::GetActiveChecksStatistics(60) << "," << CIB::GetActiveChecksStatistics(5 * 60) << "," << CIB::GetActiveChecksStatistics(15 * 60) << "\n"
<< "\t" << "passive_service_check_stats=" << CIB::GetPassiveChecksStatistics(60) << "," << CIB::GetPassiveChecksStatistics(5 * 60) << "," << CIB::GetPassiveChecksStatistics(15 * 60) << "\n"
+ << "\t" << "next_downtime_id=" << DowntimeProcessor::GetNextDowntimeID() << "\n"
<< "\t" << "}" << "\n"
<< "\n";
RegisterCommand("ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS", &ExternalCommand::EnableHostgroupPassiveSvcChecks);
RegisterCommand("DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS", &ExternalCommand::DisableHostgroupPassiveSvcChecks);
RegisterCommand("PROCESS_FILE", &ExternalCommand::ProcessFile);
+ RegisterCommand("SCHEDULE_SVC_DOWNTIME", &ExternalCommand::ScheduleSvcDowntime);
+ RegisterCommand("DEL_SVC_DOWNTIME", &ExternalCommand::DelSvcDowntime);
+ RegisterCommand("SCHEDULE_HOST_DOWNTIME", &ExternalCommand::ScheduleHostDowntime);
+ RegisterCommand("DEL_HOST_DOWNTIME", &ExternalCommand::DelHostDowntime);
+ RegisterCommand("SCHEDULE_HOST_SVC_DOWNTIME", &ExternalCommand::ScheduleHostSvcDowntime);
+ RegisterCommand("SCHEDULE_HOSTGROUP_HOST_DOWNTIME", &ExternalCommand::ScheduleHostgroupHostDowntime);
+ RegisterCommand("SCHEDULE_HOSTGROUP_SVC_DOWNTIME", &ExternalCommand::ScheduleHostgroupSvcDowntime);
+ RegisterCommand("SCHEDULE_SERVICEGROUP_HOST_DOWNTIME", &ExternalCommand::ScheduleServicegroupHostDowntime);
+ RegisterCommand("SCHEDULE_SERVICEGROUP_SVC_DOWNTIME", &ExternalCommand::ScheduleServicegroupSvcDowntime);
m_Initialized = true;
}
Host::Ptr host = Host::GetByName(arguments[0]);
- DynamicObject::Ptr object;
- BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Service")->GetObjects()) {
- Service::Ptr service = static_pointer_cast<Service>(object);
-
- if (service->GetHost() != host)
- continue;
-
+ BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
Logger::Write(LogInformation, "icinga", "Rescheduling next check for service '" + service->GetName() + "'");
service->SetNextCheck(planned_check);
service->SetForceNextCheck(true);
Host::Ptr host = Host::GetByName(arguments[0]);
- DynamicObject::Ptr object;
- BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Service")->GetObjects()) {
- Service::Ptr service = static_pointer_cast<Service>(object);
-
- if (service->GetHost() != host)
- continue;
-
+ BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
if (planned_check > service->GetNextCheck()) {
Logger::Write(LogInformation, "icinga", "Ignoring reschedule request for service '" +
service->GetName() + "' (next check is already sooner than requested check time)");
Host::Ptr host = Host::GetByName(arguments[0]);
- DynamicObject::Ptr object;
- BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Service")->GetObjects()) {
- Service::Ptr service = static_pointer_cast<Service>(object);
-
- if (service->GetHost() != host)
- continue;
-
+ BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
Logger::Write(LogInformation, "icinga", "Enabling active checks for service '" + service->GetName() + "'");
service->SetEnableActiveChecks(true);
}
Host::Ptr host = Host::GetByName(arguments[0]);
- DynamicObject::Ptr object;
- BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Service")->GetObjects()) {
- Service::Ptr service = static_pointer_cast<Service>(object);
-
- if (service->GetHost() != host)
- continue;
-
+ BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
Logger::Write(LogInformation, "icinga", "Disabling active checks for service '" + service->GetName() + "'");
service->SetEnableActiveChecks(false);
}
if (del)
(void) unlink(file.CStr());
}
+
+void ExternalCommand::ScheduleSvcDowntime(double time, const vector<String>& arguments)
+{
+ if (arguments.size() < 9)
+ throw_exception(invalid_argument("Expected 9 arguments."));
+
+ if (!Service::Exists(arguments[1]))
+ throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist."));
+
+ Service::Ptr service = Service::GetByName(arguments[1]);
+
+ Logger::Write(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
+
+ (void) DowntimeProcessor::AddDowntime(service, arguments[7], arguments[8],
+ Convert::ToDouble(arguments[2]), Convert::ToDouble(arguments[3]),
+ Convert::ToBool(arguments[4]), Convert::ToLong(arguments[5]), Convert::ToDouble(arguments[6]));
+}
+
+void ExternalCommand::DelSvcDowntime(double time, const vector<String>& arguments)
+{
+ if (arguments.size() < 1)
+ throw_exception(invalid_argument("Expected 1 argument."));
+
+ String id = arguments[0];
+ Logger::Write(LogInformation, "icinga", "Removing downtime ID " + id);
+ DowntimeProcessor::RemoveDowntime(Convert::ToLong(id));
+}
+
+void ExternalCommand::ScheduleHostDowntime(double time, const vector<String>& arguments)
+{
+ if (arguments.size() < 8)
+ throw_exception(invalid_argument("Expected 8 arguments."));
+
+ if (!Host::Exists(arguments[0]))
+ throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist."));
+
+ Host::Ptr host = Host::GetByName(arguments[0]);
+
+ Logger::Write(LogInformation, "icinga", "Creating downtime for host " + host->GetName());
+
+ (void) DowntimeProcessor::AddDowntime(host, arguments[6], arguments[7],
+ Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
+ Convert::ToBool(arguments[3]), Convert::ToLong(arguments[4]), Convert::ToDouble(arguments[5]));
+}
+
+void ExternalCommand::DelHostDowntime(double time, const vector<String>& arguments)
+{
+ if (arguments.size() < 1)
+ throw_exception(invalid_argument("Expected 1 argument."));
+
+ String id = arguments[0];
+ Logger::Write(LogInformation, "icinga", "Removing downtime ID " + id);
+ DowntimeProcessor::RemoveDowntime(Convert::ToLong(id));
+}
+
+void ExternalCommand::ScheduleHostSvcDowntime(double time, const vector<String>& arguments)
+{
+ if (arguments.size() < 8)
+ throw_exception(invalid_argument("Expected 8 argument."));
+
+ if (!Host::Exists(arguments[0]))
+ throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist."));
+
+ Host::Ptr host = Host::GetByName(arguments[0]);
+
+ Logger::Write(LogInformation, "icinga", "Creating downtime for host " + host->GetName());
+ (void) DowntimeProcessor::AddDowntime(host, arguments[6], arguments[7],
+ Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
+ Convert::ToBool(arguments[3]), Convert::ToLong(arguments[4]), Convert::ToDouble(arguments[5]));
+
+ BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
+ Logger::Write(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
+ (void) DowntimeProcessor::AddDowntime(service, arguments[6], arguments[7],
+ Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
+ Convert::ToBool(arguments[3]), Convert::ToLong(arguments[4]), Convert::ToDouble(arguments[5]));
+ }
+}
+
+void ExternalCommand::ScheduleHostgroupHostDowntime(double time, const vector<String>& arguments)
+{
+ if (arguments.size() < 8)
+ throw_exception(invalid_argument("Expected 8 arguments."));
+
+ if (!HostGroup::Exists(arguments[0]))
+ throw_exception(invalid_argument("The host group '" + arguments[0] + "' does not exist."));
+
+ HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
+
+ BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
+ Logger::Write(LogInformation, "icinga", "Creating downtime for host " + host->GetName());
+ (void) DowntimeProcessor::AddDowntime(host, arguments[6], arguments[7],
+ Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
+ Convert::ToBool(arguments[3]), Convert::ToLong(arguments[4]), Convert::ToDouble(arguments[5]));
+ }
+}
+
+void ExternalCommand::ScheduleHostgroupSvcDowntime(double time, const vector<String>& arguments)
+{
+ // TODO: implement (#3582)
+}
+
+void ExternalCommand::ScheduleServicegroupHostDowntime(double time, const vector<String>& arguments)
+{
+ // TODO: implement (#3582)
+}
+
+void ExternalCommand::ScheduleServicegroupSvcDowntime(double time, const vector<String>& arguments)
+{
+ if (arguments.size() < 8)
+ throw_exception(invalid_argument("Expected 8 arguments."));
+
+ if (!ServiceGroup::Exists(arguments[0]))
+ throw_exception(invalid_argument("The host group '" + arguments[0] + "' does not exist."));
+
+ ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
+
+ BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
+ Logger::Write(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
+ (void) DowntimeProcessor::AddDowntime(service, arguments[6], arguments[7],
+ Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
+ Convert::ToBool(arguments[3]), Convert::ToLong(arguments[4]), Convert::ToDouble(arguments[5]));
+ }
+}
+
{ "enable_passive_checks", Attribute_Replicated },
{ "force_next_check", Attribute_Replicated },
{ "acknowledgement", Attribute_Replicated },
- { "acknowledgement_expiry", Attribute_Replicated }
+ { "acknowledgement_expiry", Attribute_Replicated },
+ { "downtimes", Attribute_Replicated }
};
REGISTER_TYPE(Service, serviceAttributes);
{
ServiceGroup::InvalidateMembersCache();
Host::InvalidateServicesCache();
+ DowntimeProcessor::InvalidateDowntimeCache();
}
Service::~Service(void)
{
ServiceGroup::InvalidateMembersCache();
Host::InvalidateServicesCache();
+ DowntimeProcessor::InvalidateDowntimeCache();
}
String Service::GetAlias(void) const
return Get("macros");
}
+Dictionary::Ptr Service::GetDowntimes(void) const
+{
+ return Get("downtimes");
+}
+
String Service::GetCheckCommand(void) const
{
return Get("check_command");
return true;
}
+bool Service::IsInDowntime(void) const
+{
+ Dictionary::Ptr downtimes = GetDowntimes();
+
+ if (!downtimes)
+ return false;
+
+ Dictionary::Ptr downtime;
+ BOOST_FOREACH(tie(tuples::ignore, downtime), downtimes) {
+ if (DowntimeProcessor::IsDowntimeActive(downtime))
+ return true;
+ }
+
+ return false;
+}
+
void Service::SetSchedulingOffset(long offset)
{
Set("scheduling_offset", offset);
ServiceGroup::InvalidateMembersCache();
else if (name == "host_name")
Host::InvalidateServicesCache();
+ else if (name == "downtimes")
+ DowntimeProcessor::InvalidateDowntimeCache();
}
void Service::BeginExecuteCheck(const function<void (void)>& callback)