diff --git a/doc/22-appendix.md b/doc/22-appendix.md index aaea1e573..48a2efb45 100644 --- a/doc/22-appendix.md +++ b/doc/22-appendix.md @@ -49,6 +49,7 @@ Additional details can be found in the [Icinga 1.x Documentation](http://docs.ic DEL_SVC_DOWNTIME | ;<downtime_id> (1) | - SCHEDULE_HOST_DOWNTIME | ;<host_name>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment> (8) | - DEL_HOST_DOWNTIME | ;<downtime_id> (1) | - + DEL_DOWNTIME_BY_HOST_NAME | ;<host_name>[;<service_name;>[;<start_time;>[;<comment_text;>]]] (1) | - SCHEDULE_HOST_SVC_DOWNTIME | ;<host_name>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment> (8) | - SCHEDULE_HOSTGROUP_HOST_DOWNTIME | ;<hostgroup_name>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment> (8) | - SCHEDULE_HOSTGROUP_SVC_DOWNTIME | ;<hostgroup_name>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment> (8) | - diff --git a/lib/icinga/externalcommandprocessor.cpp b/lib/icinga/externalcommandprocessor.cpp index 6eb7af0d2..06ee7361c 100644 --- a/lib/icinga/externalcommandprocessor.cpp +++ b/lib/icinga/externalcommandprocessor.cpp @@ -215,6 +215,7 @@ void ExternalCommandProcessor::StaticInitialize(void) RegisterCommand("DEL_SVC_DOWNTIME", &ExternalCommandProcessor::DelSvcDowntime, 1); RegisterCommand("SCHEDULE_HOST_DOWNTIME", &ExternalCommandProcessor::ScheduleHostDowntime, 8); RegisterCommand("DEL_HOST_DOWNTIME", &ExternalCommandProcessor::DelHostDowntime, 1); + RegisterCommand("DEL_DOWNTIME_BY_HOST_NAME", &ExternalCommandProcessor::DelDowntimeByHostName, 1); RegisterCommand("SCHEDULE_HOST_SVC_DOWNTIME", &ExternalCommandProcessor::ScheduleHostSvcDowntime, 8); RegisterCommand("SCHEDULE_HOSTGROUP_HOST_DOWNTIME", &ExternalCommandProcessor::ScheduleHostgroupHostDowntime, 8); RegisterCommand("SCHEDULE_HOSTGROUP_SVC_DOWNTIME", &ExternalCommandProcessor::ScheduleHostgroupSvcDowntime, 8); @@ -1077,6 +1078,67 @@ void ExternalCommandProcessor::DelHostDowntime(double, const std::vector Service::RemoveDowntime(rid, true); } +void ExternalCommandProcessor::DelDowntimeByHostName(double, const std::vector& arguments) +{ + Host::Ptr host = Host::GetByName(arguments[0]); + + if (!host) + BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot schedule host services downtime for non-existent host '" + arguments[0] + "'")); + + String serviceName; + if (arguments.size() >= 2) + serviceName = arguments[1]; + + String startTime; + if (arguments.size() >= 3) + startTime = arguments[2]; + + String commentString; + if (arguments.size() >= 4) + commentString = arguments[3]; + + if (arguments.size() > 5) + Log(LogWarning, "ExternalCommandProcessor") + << ("Ignoring additional parameters for host '" + arguments[0] + "' downtime deletion."); + + std::vector ids; + + Dictionary::Ptr hostDowntimes = host->GetDowntimes(); + { + ObjectLock dhlock(hostDowntimes); + BOOST_FOREACH(const Dictionary::Pair& kv, hostDowntimes) { + ids.push_back(kv.first); + } + } + + BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) { + if (!serviceName.IsEmpty() && serviceName != service->GetName()) + continue; + + Dictionary::Ptr serviceDowntimes = service->GetDowntimes(); + { + ObjectLock dslock(serviceDowntimes); + BOOST_FOREACH(const Dictionary::Pair& kv, serviceDowntimes) { + ids.push_back(kv.first); + } + } + } + + BOOST_FOREACH(const String& id, ids) { + Downtime::Ptr downtime = Service::GetDowntimeByID(id); + + if (!startTime.IsEmpty() && downtime->GetStartTime() != Convert::ToDouble(startTime)) + continue; + + if (!commentString.IsEmpty() && downtime->GetComment() != commentString) + continue; + + Log(LogNotice, "ExternalCommandProcessor") + << "Removing downtime ID " << id; + Service::RemoveDowntime(id, true); + } +} + void ExternalCommandProcessor::ScheduleHostSvcDowntime(double, const std::vector& arguments) { Host::Ptr host = Host::GetByName(arguments[0]); diff --git a/lib/icinga/externalcommandprocessor.hpp b/lib/icinga/externalcommandprocessor.hpp index cebb90f4e..72072bf87 100644 --- a/lib/icinga/externalcommandprocessor.hpp +++ b/lib/icinga/externalcommandprocessor.hpp @@ -81,6 +81,7 @@ private: static void DelSvcDowntime(double time, const std::vector& arguments); static void ScheduleHostDowntime(double time, const std::vector& arguments); static void DelHostDowntime(double time, const std::vector& arguments); + static void DelDowntimeByHostName(double, const std::vector& arguments); static void ScheduleHostSvcDowntime(double time, const std::vector& arguments); static void ScheduleHostgroupHostDowntime(double time, const std::vector& arguments); static void ScheduleHostgroupSvcDowntime(double time, const std::vector& arguments);