Implement external command DEL_DOWNTIME_BY_HOST_NAME

Required by Classic UI 1.x, this will hopefully reduce
the noise on non-working commands with the old legacy stuff.

fixes #8979
This commit is contained in:
Michael Friedrich 2015-07-31 14:46:38 +02:00
parent 1314cba61b
commit 766e2d73f4
3 changed files with 64 additions and 0 deletions

View File

@ -49,6 +49,7 @@ Additional details can be found in the [Icinga 1.x Documentation](http://docs.ic
DEL_SVC_DOWNTIME | ;<downtime_id> (1) | - DEL_SVC_DOWNTIME | ;<downtime_id> (1) | -
SCHEDULE_HOST_DOWNTIME | ;<host_name>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment> (8) | - SCHEDULE_HOST_DOWNTIME | ;<host_name>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment> (8) | -
DEL_HOST_DOWNTIME | ;<downtime_id> (1) | - 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_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_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) | - SCHEDULE_HOSTGROUP_SVC_DOWNTIME | ;<hostgroup_name>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment> (8) | -

View File

@ -215,6 +215,7 @@ void ExternalCommandProcessor::StaticInitialize(void)
RegisterCommand("DEL_SVC_DOWNTIME", &ExternalCommandProcessor::DelSvcDowntime, 1); RegisterCommand("DEL_SVC_DOWNTIME", &ExternalCommandProcessor::DelSvcDowntime, 1);
RegisterCommand("SCHEDULE_HOST_DOWNTIME", &ExternalCommandProcessor::ScheduleHostDowntime, 8); RegisterCommand("SCHEDULE_HOST_DOWNTIME", &ExternalCommandProcessor::ScheduleHostDowntime, 8);
RegisterCommand("DEL_HOST_DOWNTIME", &ExternalCommandProcessor::DelHostDowntime, 1); 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_HOST_SVC_DOWNTIME", &ExternalCommandProcessor::ScheduleHostSvcDowntime, 8);
RegisterCommand("SCHEDULE_HOSTGROUP_HOST_DOWNTIME", &ExternalCommandProcessor::ScheduleHostgroupHostDowntime, 8); RegisterCommand("SCHEDULE_HOSTGROUP_HOST_DOWNTIME", &ExternalCommandProcessor::ScheduleHostgroupHostDowntime, 8);
RegisterCommand("SCHEDULE_HOSTGROUP_SVC_DOWNTIME", &ExternalCommandProcessor::ScheduleHostgroupSvcDowntime, 8); RegisterCommand("SCHEDULE_HOSTGROUP_SVC_DOWNTIME", &ExternalCommandProcessor::ScheduleHostgroupSvcDowntime, 8);
@ -1077,6 +1078,67 @@ void ExternalCommandProcessor::DelHostDowntime(double, const std::vector<String>
Service::RemoveDowntime(rid, true); Service::RemoveDowntime(rid, true);
} }
void ExternalCommandProcessor::DelDowntimeByHostName(double, const std::vector<String>& 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<String> 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<String>& arguments) void ExternalCommandProcessor::ScheduleHostSvcDowntime(double, const std::vector<String>& arguments)
{ {
Host::Ptr host = Host::GetByName(arguments[0]); Host::Ptr host = Host::GetByName(arguments[0]);

View File

@ -81,6 +81,7 @@ private:
static void DelSvcDowntime(double time, const std::vector<String>& arguments); static void DelSvcDowntime(double time, const std::vector<String>& arguments);
static void ScheduleHostDowntime(double time, const std::vector<String>& arguments); static void ScheduleHostDowntime(double time, const std::vector<String>& arguments);
static void DelHostDowntime(double time, const std::vector<String>& arguments); static void DelHostDowntime(double time, const std::vector<String>& arguments);
static void DelDowntimeByHostName(double, const std::vector<String>& arguments);
static void ScheduleHostSvcDowntime(double time, const std::vector<String>& arguments); static void ScheduleHostSvcDowntime(double time, const std::vector<String>& arguments);
static void ScheduleHostgroupHostDowntime(double time, const std::vector<String>& arguments); static void ScheduleHostgroupHostDowntime(double time, const std::vector<String>& arguments);
static void ScheduleHostgroupSvcDowntime(double time, const std::vector<String>& arguments); static void ScheduleHostgroupSvcDowntime(double time, const std::vector<String>& arguments);