1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
3 #include "icinga/externalcommandprocessor.hpp"
4 #include "icinga/host.hpp"
5 #include "icinga/service.hpp"
6 #include "icinga/user.hpp"
7 #include "icinga/hostgroup.hpp"
8 #include "icinga/servicegroup.hpp"
9 #include "icinga/pluginutility.hpp"
10 #include "icinga/icingaapplication.hpp"
11 #include "icinga/checkcommand.hpp"
12 #include "icinga/eventcommand.hpp"
13 #include "icinga/notificationcommand.hpp"
14 #include "icinga/compatutility.hpp"
15 #include "remote/apifunction.hpp"
16 #include "base/convert.hpp"
17 #include "base/logger.hpp"
18 #include "base/objectlock.hpp"
19 #include "base/application.hpp"
20 #include "base/utility.hpp"
21 #include "base/exception.hpp"
23 #include <boost/thread/once.hpp>
25 using namespace icinga;
27 boost::signals2::signal<void(double, const String&, const std::vector<String>&)> ExternalCommandProcessor::OnNewExternalCommand;
29 void ExternalCommandProcessor::Execute(const String& line)
35 BOOST_THROW_EXCEPTION(std::invalid_argument("Missing timestamp in command: " + line));
37 size_t pos = line.FindFirstOf("]");
39 if (pos == String::NPos)
40 BOOST_THROW_EXCEPTION(std::invalid_argument("Missing timestamp in command: " + line));
42 String timestamp = line.SubStr(1, pos - 1);
43 String args = line.SubStr(pos + 2, String::NPos);
45 double ts = Convert::ToDouble(timestamp);
48 BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid timestamp in command: " + line));
50 std::vector<String> argv = args.Split(";");
53 BOOST_THROW_EXCEPTION(std::invalid_argument("Missing arguments in command: " + line));
55 std::vector<String> argvExtra(argv.begin() + 1, argv.end());
56 Execute(ts, argv[0], argvExtra);
59 void ExternalCommandProcessor::Execute(double time, const String& command, const std::vector<String>& arguments)
61 ExternalCommandInfo eci;
63 static boost::once_flag once = BOOST_ONCE_INIT;
65 boost::call_once(once, []() {
70 boost::mutex::scoped_lock lock(GetMutex());
72 auto it = GetCommands().find(command);
74 if (it == GetCommands().end())
75 BOOST_THROW_EXCEPTION(std::invalid_argument("The external command '" + command + "' does not exist."));
80 if (arguments.size() < eci.MinArgs)
81 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected " + Convert::ToString(eci.MinArgs) + " arguments"));
83 size_t argnum = std::min(arguments.size(), eci.MaxArgs);
85 std::vector<String> realArguments;
86 realArguments.resize(argnum);
89 std::copy(arguments.begin(), arguments.begin() + argnum - 1, realArguments.begin());
92 for (std::vector<String>::size_type i = argnum - 1; i < arguments.size(); i++) {
93 if (!last_argument.IsEmpty())
96 last_argument += arguments[i];
99 realArguments[argnum - 1] = last_argument;
102 OnNewExternalCommand(time, command, realArguments);
104 eci.Callback(time, realArguments);
107 void ExternalCommandProcessor::RegisterCommand(const String& command, const ExternalCommandCallback& callback, size_t minArgs, size_t maxArgs)
109 boost::mutex::scoped_lock lock(GetMutex());
110 ExternalCommandInfo eci;
111 eci.Callback = callback;
112 eci.MinArgs = minArgs;
113 eci.MaxArgs = (maxArgs == UINT_MAX) ? minArgs : maxArgs;
114 GetCommands()[command] = eci;
117 void ExternalCommandProcessor::RegisterCommands()
119 RegisterCommand("PROCESS_HOST_CHECK_RESULT", &ExternalCommandProcessor::ProcessHostCheckResult, 3);
120 RegisterCommand("PROCESS_SERVICE_CHECK_RESULT", &ExternalCommandProcessor::ProcessServiceCheckResult, 4);
121 RegisterCommand("SCHEDULE_HOST_CHECK", &ExternalCommandProcessor::ScheduleHostCheck, 2);
122 RegisterCommand("SCHEDULE_FORCED_HOST_CHECK", &ExternalCommandProcessor::ScheduleForcedHostCheck, 2);
123 RegisterCommand("SCHEDULE_SVC_CHECK", &ExternalCommandProcessor::ScheduleSvcCheck, 3);
124 RegisterCommand("SCHEDULE_FORCED_SVC_CHECK", &ExternalCommandProcessor::ScheduleForcedSvcCheck, 3);
125 RegisterCommand("ENABLE_HOST_CHECK", &ExternalCommandProcessor::EnableHostCheck, 1);
126 RegisterCommand("DISABLE_HOST_CHECK", &ExternalCommandProcessor::DisableHostCheck, 1);
127 RegisterCommand("ENABLE_SVC_CHECK", &ExternalCommandProcessor::EnableSvcCheck, 2);
128 RegisterCommand("DISABLE_SVC_CHECK", &ExternalCommandProcessor::DisableSvcCheck, 2);
129 RegisterCommand("SHUTDOWN_PROCESS", &ExternalCommandProcessor::ShutdownProcess);
130 RegisterCommand("RESTART_PROCESS", &ExternalCommandProcessor::RestartProcess);
131 RegisterCommand("SCHEDULE_FORCED_HOST_SVC_CHECKS", &ExternalCommandProcessor::ScheduleForcedHostSvcChecks, 2);
132 RegisterCommand("SCHEDULE_HOST_SVC_CHECKS", &ExternalCommandProcessor::ScheduleHostSvcChecks, 2);
133 RegisterCommand("ENABLE_HOST_SVC_CHECKS", &ExternalCommandProcessor::EnableHostSvcChecks, 1);
134 RegisterCommand("DISABLE_HOST_SVC_CHECKS", &ExternalCommandProcessor::DisableHostSvcChecks, 1);
135 RegisterCommand("ACKNOWLEDGE_SVC_PROBLEM", &ExternalCommandProcessor::AcknowledgeSvcProblem, 7);
136 RegisterCommand("ACKNOWLEDGE_SVC_PROBLEM_EXPIRE", &ExternalCommandProcessor::AcknowledgeSvcProblemExpire, 8);
137 RegisterCommand("REMOVE_SVC_ACKNOWLEDGEMENT", &ExternalCommandProcessor::RemoveSvcAcknowledgement, 2);
138 RegisterCommand("ACKNOWLEDGE_HOST_PROBLEM", &ExternalCommandProcessor::AcknowledgeHostProblem, 6);
139 RegisterCommand("ACKNOWLEDGE_HOST_PROBLEM_EXPIRE", &ExternalCommandProcessor::AcknowledgeHostProblemExpire, 7);
140 RegisterCommand("REMOVE_HOST_ACKNOWLEDGEMENT", &ExternalCommandProcessor::RemoveHostAcknowledgement, 1);
141 RegisterCommand("DISABLE_HOST_FLAP_DETECTION", &ExternalCommandProcessor::DisableHostFlapping, 1);
142 RegisterCommand("ENABLE_HOST_FLAP_DETECTION", &ExternalCommandProcessor::EnableHostFlapping, 1);
143 RegisterCommand("DISABLE_SVC_FLAP_DETECTION", &ExternalCommandProcessor::DisableSvcFlapping, 2);
144 RegisterCommand("ENABLE_SVC_FLAP_DETECTION", &ExternalCommandProcessor::EnableSvcFlapping, 2);
145 RegisterCommand("ENABLE_HOSTGROUP_SVC_CHECKS", &ExternalCommandProcessor::EnableHostgroupSvcChecks, 1);
146 RegisterCommand("DISABLE_HOSTGROUP_SVC_CHECKS", &ExternalCommandProcessor::DisableHostgroupSvcChecks, 1);
147 RegisterCommand("ENABLE_SERVICEGROUP_SVC_CHECKS", &ExternalCommandProcessor::EnableServicegroupSvcChecks, 1);
148 RegisterCommand("DISABLE_SERVICEGROUP_SVC_CHECKS", &ExternalCommandProcessor::DisableServicegroupSvcChecks, 1);
149 RegisterCommand("ENABLE_PASSIVE_HOST_CHECKS", &ExternalCommandProcessor::EnablePassiveHostChecks, 1);
150 RegisterCommand("DISABLE_PASSIVE_HOST_CHECKS", &ExternalCommandProcessor::DisablePassiveHostChecks, 1);
151 RegisterCommand("ENABLE_PASSIVE_SVC_CHECKS", &ExternalCommandProcessor::EnablePassiveSvcChecks, 2);
152 RegisterCommand("DISABLE_PASSIVE_SVC_CHECKS", &ExternalCommandProcessor::DisablePassiveSvcChecks, 2);
153 RegisterCommand("ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS", &ExternalCommandProcessor::EnableServicegroupPassiveSvcChecks, 1);
154 RegisterCommand("DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS", &ExternalCommandProcessor::DisableServicegroupPassiveSvcChecks, 1);
155 RegisterCommand("ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS", &ExternalCommandProcessor::EnableHostgroupPassiveSvcChecks, 1);
156 RegisterCommand("DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS", &ExternalCommandProcessor::DisableHostgroupPassiveSvcChecks, 1);
157 RegisterCommand("PROCESS_FILE", &ExternalCommandProcessor::ProcessFile, 2);
158 RegisterCommand("SCHEDULE_SVC_DOWNTIME", &ExternalCommandProcessor::ScheduleSvcDowntime, 9);
159 RegisterCommand("DEL_SVC_DOWNTIME", &ExternalCommandProcessor::DelSvcDowntime, 1);
160 RegisterCommand("SCHEDULE_HOST_DOWNTIME", &ExternalCommandProcessor::ScheduleHostDowntime, 8);
161 RegisterCommand("SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME", &ExternalCommandProcessor::ScheduleAndPropagateHostDowntime, 8);
162 RegisterCommand("SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME", &ExternalCommandProcessor::ScheduleAndPropagateTriggeredHostDowntime, 8);
163 RegisterCommand("DEL_HOST_DOWNTIME", &ExternalCommandProcessor::DelHostDowntime, 1);
164 RegisterCommand("DEL_DOWNTIME_BY_HOST_NAME", &ExternalCommandProcessor::DelDowntimeByHostName, 1, 4);
165 RegisterCommand("SCHEDULE_HOST_SVC_DOWNTIME", &ExternalCommandProcessor::ScheduleHostSvcDowntime, 8);
166 RegisterCommand("SCHEDULE_HOSTGROUP_HOST_DOWNTIME", &ExternalCommandProcessor::ScheduleHostgroupHostDowntime, 8);
167 RegisterCommand("SCHEDULE_HOSTGROUP_SVC_DOWNTIME", &ExternalCommandProcessor::ScheduleHostgroupSvcDowntime, 8);
168 RegisterCommand("SCHEDULE_SERVICEGROUP_HOST_DOWNTIME", &ExternalCommandProcessor::ScheduleServicegroupHostDowntime, 8);
169 RegisterCommand("SCHEDULE_SERVICEGROUP_SVC_DOWNTIME", &ExternalCommandProcessor::ScheduleServicegroupSvcDowntime, 8);
170 RegisterCommand("ADD_HOST_COMMENT", &ExternalCommandProcessor::AddHostComment, 4);
171 RegisterCommand("DEL_HOST_COMMENT", &ExternalCommandProcessor::DelHostComment, 1);
172 RegisterCommand("ADD_SVC_COMMENT", &ExternalCommandProcessor::AddSvcComment, 5);
173 RegisterCommand("DEL_SVC_COMMENT", &ExternalCommandProcessor::DelSvcComment, 1);
174 RegisterCommand("DEL_ALL_HOST_COMMENTS", &ExternalCommandProcessor::DelAllHostComments, 1);
175 RegisterCommand("DEL_ALL_SVC_COMMENTS", &ExternalCommandProcessor::DelAllSvcComments, 2);
176 RegisterCommand("SEND_CUSTOM_HOST_NOTIFICATION", &ExternalCommandProcessor::SendCustomHostNotification, 4);
177 RegisterCommand("SEND_CUSTOM_SVC_NOTIFICATION", &ExternalCommandProcessor::SendCustomSvcNotification, 5);
178 RegisterCommand("DELAY_HOST_NOTIFICATION", &ExternalCommandProcessor::DelayHostNotification, 2);
179 RegisterCommand("DELAY_SVC_NOTIFICATION", &ExternalCommandProcessor::DelaySvcNotification, 3);
180 RegisterCommand("ENABLE_HOST_NOTIFICATIONS", &ExternalCommandProcessor::EnableHostNotifications, 1);
181 RegisterCommand("DISABLE_HOST_NOTIFICATIONS", &ExternalCommandProcessor::DisableHostNotifications, 1);
182 RegisterCommand("ENABLE_SVC_NOTIFICATIONS", &ExternalCommandProcessor::EnableSvcNotifications, 2);
183 RegisterCommand("DISABLE_SVC_NOTIFICATIONS", &ExternalCommandProcessor::DisableSvcNotifications, 2);
184 RegisterCommand("ENABLE_HOST_SVC_NOTIFICATIONS", &ExternalCommandProcessor::EnableHostSvcNotifications, 1);
185 RegisterCommand("DISABLE_HOST_SVC_NOTIFICATIONS", &ExternalCommandProcessor::DisableHostSvcNotifications, 1);
186 RegisterCommand("DISABLE_HOSTGROUP_HOST_CHECKS", &ExternalCommandProcessor::DisableHostgroupHostChecks, 1);
187 RegisterCommand("DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS", &ExternalCommandProcessor::DisableHostgroupPassiveHostChecks, 1);
188 RegisterCommand("DISABLE_SERVICEGROUP_HOST_CHECKS", &ExternalCommandProcessor::DisableServicegroupHostChecks, 1);
189 RegisterCommand("DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS", &ExternalCommandProcessor::DisableServicegroupPassiveHostChecks, 1);
190 RegisterCommand("ENABLE_HOSTGROUP_HOST_CHECKS", &ExternalCommandProcessor::EnableHostgroupHostChecks, 1);
191 RegisterCommand("ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS", &ExternalCommandProcessor::EnableHostgroupPassiveHostChecks, 1);
192 RegisterCommand("ENABLE_SERVICEGROUP_HOST_CHECKS", &ExternalCommandProcessor::EnableServicegroupHostChecks, 1);
193 RegisterCommand("ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS", &ExternalCommandProcessor::EnableServicegroupPassiveHostChecks, 1);
194 RegisterCommand("ENABLE_NOTIFICATIONS", &ExternalCommandProcessor::EnableNotifications);
195 RegisterCommand("DISABLE_NOTIFICATIONS", &ExternalCommandProcessor::DisableNotifications);
196 RegisterCommand("ENABLE_FLAP_DETECTION", &ExternalCommandProcessor::EnableFlapDetection);
197 RegisterCommand("DISABLE_FLAP_DETECTION", &ExternalCommandProcessor::DisableFlapDetection);
198 RegisterCommand("ENABLE_EVENT_HANDLERS", &ExternalCommandProcessor::EnableEventHandlers);
199 RegisterCommand("DISABLE_EVENT_HANDLERS", &ExternalCommandProcessor::DisableEventHandlers);
200 RegisterCommand("ENABLE_PERFORMANCE_DATA", &ExternalCommandProcessor::EnablePerformanceData);
201 RegisterCommand("DISABLE_PERFORMANCE_DATA", &ExternalCommandProcessor::DisablePerformanceData);
202 RegisterCommand("START_EXECUTING_SVC_CHECKS", &ExternalCommandProcessor::StartExecutingSvcChecks);
203 RegisterCommand("STOP_EXECUTING_SVC_CHECKS", &ExternalCommandProcessor::StopExecutingSvcChecks);
204 RegisterCommand("START_EXECUTING_HOST_CHECKS", &ExternalCommandProcessor::StartExecutingHostChecks);
205 RegisterCommand("STOP_EXECUTING_HOST_CHECKS", &ExternalCommandProcessor::StopExecutingHostChecks);
206 RegisterCommand("CHANGE_NORMAL_SVC_CHECK_INTERVAL", &ExternalCommandProcessor::ChangeNormalSvcCheckInterval, 3);
207 RegisterCommand("CHANGE_NORMAL_HOST_CHECK_INTERVAL", &ExternalCommandProcessor::ChangeNormalHostCheckInterval, 2);
208 RegisterCommand("CHANGE_RETRY_SVC_CHECK_INTERVAL", &ExternalCommandProcessor::ChangeRetrySvcCheckInterval, 3);
209 RegisterCommand("CHANGE_RETRY_HOST_CHECK_INTERVAL", &ExternalCommandProcessor::ChangeRetryHostCheckInterval, 2);
210 RegisterCommand("ENABLE_HOST_EVENT_HANDLER", &ExternalCommandProcessor::EnableHostEventHandler, 1);
211 RegisterCommand("DISABLE_HOST_EVENT_HANDLER", &ExternalCommandProcessor::DisableHostEventHandler, 1);
212 RegisterCommand("ENABLE_SVC_EVENT_HANDLER", &ExternalCommandProcessor::EnableSvcEventHandler, 2);
213 RegisterCommand("DISABLE_SVC_EVENT_HANDLER", &ExternalCommandProcessor::DisableSvcEventHandler, 2);
214 RegisterCommand("CHANGE_HOST_EVENT_HANDLER", &ExternalCommandProcessor::ChangeHostEventHandler, 2);
215 RegisterCommand("CHANGE_SVC_EVENT_HANDLER", &ExternalCommandProcessor::ChangeSvcEventHandler, 3);
216 RegisterCommand("CHANGE_HOST_CHECK_COMMAND", &ExternalCommandProcessor::ChangeHostCheckCommand, 2);
217 RegisterCommand("CHANGE_SVC_CHECK_COMMAND", &ExternalCommandProcessor::ChangeSvcCheckCommand, 3);
218 RegisterCommand("CHANGE_MAX_HOST_CHECK_ATTEMPTS", &ExternalCommandProcessor::ChangeMaxHostCheckAttempts, 2);
219 RegisterCommand("CHANGE_MAX_SVC_CHECK_ATTEMPTS", &ExternalCommandProcessor::ChangeMaxSvcCheckAttempts, 3);
220 RegisterCommand("CHANGE_HOST_CHECK_TIMEPERIOD", &ExternalCommandProcessor::ChangeHostCheckTimeperiod, 2);
221 RegisterCommand("CHANGE_SVC_CHECK_TIMEPERIOD", &ExternalCommandProcessor::ChangeSvcCheckTimeperiod, 3);
222 RegisterCommand("CHANGE_CUSTOM_HOST_VAR", &ExternalCommandProcessor::ChangeCustomHostVar, 3);
223 RegisterCommand("CHANGE_CUSTOM_SVC_VAR", &ExternalCommandProcessor::ChangeCustomSvcVar, 4);
224 RegisterCommand("CHANGE_CUSTOM_USER_VAR", &ExternalCommandProcessor::ChangeCustomUserVar, 3);
225 RegisterCommand("CHANGE_CUSTOM_CHECKCOMMAND_VAR", &ExternalCommandProcessor::ChangeCustomCheckcommandVar, 3);
226 RegisterCommand("CHANGE_CUSTOM_EVENTCOMMAND_VAR", &ExternalCommandProcessor::ChangeCustomEventcommandVar, 3);
227 RegisterCommand("CHANGE_CUSTOM_NOTIFICATIONCOMMAND_VAR", &ExternalCommandProcessor::ChangeCustomNotificationcommandVar, 3);
229 RegisterCommand("ENABLE_HOSTGROUP_HOST_NOTIFICATIONS", &ExternalCommandProcessor::EnableHostgroupHostNotifications, 1);
230 RegisterCommand("ENABLE_HOSTGROUP_SVC_NOTIFICATIONS", &ExternalCommandProcessor::EnableHostgroupSvcNotifications, 1);
231 RegisterCommand("DISABLE_HOSTGROUP_HOST_NOTIFICATIONS", &ExternalCommandProcessor::DisableHostgroupHostNotifications, 1);
232 RegisterCommand("DISABLE_HOSTGROUP_SVC_NOTIFICATIONS", &ExternalCommandProcessor::DisableHostgroupSvcNotifications, 1);
233 RegisterCommand("ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS", &ExternalCommandProcessor::EnableServicegroupHostNotifications, 1);
234 RegisterCommand("DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS", &ExternalCommandProcessor::DisableServicegroupHostNotifications, 1);
235 RegisterCommand("ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS", &ExternalCommandProcessor::EnableServicegroupSvcNotifications, 1);
236 RegisterCommand("DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS", &ExternalCommandProcessor::DisableServicegroupSvcNotifications, 1);
239 void ExternalCommandProcessor::ExecuteFromFile(const String& line, std::deque< std::vector<String> >& file_queue)
245 BOOST_THROW_EXCEPTION(std::invalid_argument("Missing timestamp in command: " + line));
247 size_t pos = line.FindFirstOf("]");
249 if (pos == String::NPos)
250 BOOST_THROW_EXCEPTION(std::invalid_argument("Missing timestamp in command: " + line));
252 String timestamp = line.SubStr(1, pos - 1);
253 String args = line.SubStr(pos + 2, String::NPos);
255 double ts = Convert::ToDouble(timestamp);
258 BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid timestamp in command: " + line));
260 std::vector<String> argv = args.Split(";");
263 BOOST_THROW_EXCEPTION(std::invalid_argument("Missing arguments in command: " + line));
265 std::vector<String> argvExtra(argv.begin() + 1, argv.end());
267 if (argv[0] == "PROCESS_FILE") {
268 Log(LogDebug, "ExternalCommandProcessor")
269 << "Enqueing external command file " << argvExtra[0];
270 file_queue.push_back(argvExtra);
272 Execute(ts, argv[0], argvExtra);
276 void ExternalCommandProcessor::ProcessHostCheckResult(double time, const std::vector<String>& arguments)
278 Host::Ptr host = Host::GetByName(arguments[0]);
281 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot process passive host check result for non-existent host '" + arguments[0] + "'"));
283 if (!host->GetEnablePassiveChecks())
284 BOOST_THROW_EXCEPTION(std::invalid_argument("Got passive check result for host '" + arguments[0] + "' which has passive checks disabled."));
286 int exitStatus = Convert::ToDouble(arguments[1]);
287 CheckResult::Ptr result = new CheckResult();
288 std::pair<String, String> co = PluginUtility::ParseCheckOutput(arguments[2]);
289 result->SetOutput(co.first);
290 result->SetPerformanceData(PluginUtility::SplitPerfdata(co.second));
296 else if (exitStatus == 1)
297 state = ServiceCritical;
299 BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid status code: " + arguments[1]));
301 result->SetState(state);
303 result->SetScheduleStart(time);
304 result->SetScheduleEnd(time);
305 result->SetExecutionStart(time);
306 result->SetExecutionEnd(time);
308 /* Mark this check result as passive. */
309 result->SetActive(false);
311 Log(LogNotice, "ExternalCommandProcessor")
312 << "Processing passive check result for host '" << arguments[0] << "'";
314 host->ProcessCheckResult(result);
317 void ExternalCommandProcessor::ProcessServiceCheckResult(double time, const std::vector<String>& arguments)
319 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
322 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot process passive service check result for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
324 if (!service->GetEnablePassiveChecks())
325 BOOST_THROW_EXCEPTION(std::invalid_argument("Got passive check result for service '" + arguments[1] + "' which has passive checks disabled."));
327 int exitStatus = Convert::ToDouble(arguments[2]);
328 CheckResult::Ptr result = new CheckResult();
329 String output = CompatUtility::UnEscapeString(arguments[3]);
330 std::pair<String, String> co = PluginUtility::ParseCheckOutput(output);
331 result->SetOutput(co.first);
332 result->SetPerformanceData(PluginUtility::SplitPerfdata(co.second));
333 result->SetState(PluginUtility::ExitStatusToState(exitStatus));
335 result->SetScheduleStart(time);
336 result->SetScheduleEnd(time);
337 result->SetExecutionStart(time);
338 result->SetExecutionEnd(time);
340 /* Mark this check result as passive. */
341 result->SetActive(false);
343 Log(LogNotice, "ExternalCommandProcessor")
344 << "Processing passive check result for service '" << arguments[1] << "'";
346 service->ProcessCheckResult(result);
349 void ExternalCommandProcessor::ScheduleHostCheck(double, const std::vector<String>& arguments)
351 Host::Ptr host = Host::GetByName(arguments[0]);
354 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot reschedule host check for non-existent host '" + arguments[0] + "'"));
356 double planned_check = Convert::ToDouble(arguments[1]);
358 if (planned_check > host->GetNextCheck()) {
359 Log(LogNotice, "ExternalCommandProcessor")
360 << "Ignoring reschedule request for host '"
361 << arguments[0] << "' (next check is already sooner than requested check time)";
365 Log(LogNotice, "ExternalCommandProcessor")
366 << "Rescheduling next check for host '" << arguments[0] << "'";
368 if (planned_check < Utility::GetTime())
369 planned_check = Utility::GetTime();
371 host->SetNextCheck(planned_check);
373 /* trigger update event for DB IDO */
374 Checkable::OnNextCheckUpdated(host);
377 void ExternalCommandProcessor::ScheduleForcedHostCheck(double, const std::vector<String>& arguments)
379 Host::Ptr host = Host::GetByName(arguments[0]);
382 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot reschedule forced host check for non-existent host '" + arguments[0] + "'"));
384 Log(LogNotice, "ExternalCommandProcessor")
385 << "Rescheduling next check for host '" << arguments[0] << "'";
387 host->SetForceNextCheck(true);
388 host->SetNextCheck(Convert::ToDouble(arguments[1]));
390 /* trigger update event for DB IDO */
391 Checkable::OnNextCheckUpdated(host);
394 void ExternalCommandProcessor::ScheduleSvcCheck(double, const std::vector<String>& arguments)
396 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
399 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot reschedule service check for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
401 double planned_check = Convert::ToDouble(arguments[2]);
403 if (planned_check > service->GetNextCheck()) {
404 Log(LogNotice, "ExternalCommandProcessor")
405 << "Ignoring reschedule request for service '"
406 << arguments[1] << "' (next check is already sooner than requested check time)";
410 Log(LogNotice, "ExternalCommandProcessor")
411 << "Rescheduling next check for service '" << arguments[1] << "'";
413 if (planned_check < Utility::GetTime())
414 planned_check = Utility::GetTime();
416 service->SetNextCheck(planned_check);
418 /* trigger update event for DB IDO */
419 Checkable::OnNextCheckUpdated(service);
422 void ExternalCommandProcessor::ScheduleForcedSvcCheck(double, const std::vector<String>& arguments)
424 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
427 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot reschedule forced service check for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
429 Log(LogNotice, "ExternalCommandProcessor")
430 << "Rescheduling next check for service '" << arguments[1] << "'";
432 service->SetForceNextCheck(true);
433 service->SetNextCheck(Convert::ToDouble(arguments[2]));
435 /* trigger update event for DB IDO */
436 Checkable::OnNextCheckUpdated(service);
439 void ExternalCommandProcessor::EnableHostCheck(double, const std::vector<String>& arguments)
441 Host::Ptr host = Host::GetByName(arguments[0]);
444 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable host checks for non-existent host '" + arguments[0] + "'"));
446 Log(LogNotice, "ExternalCommandProcessor")
447 << "Enabling active checks for host '" << arguments[0] << "'";
449 host->ModifyAttribute("enable_active_checks", true);
452 void ExternalCommandProcessor::DisableHostCheck(double, const std::vector<String>& arguments)
454 Host::Ptr host = Host::GetByName(arguments[0]);
457 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable host check non-existent host '" + arguments[0] + "'"));
459 Log(LogNotice, "ExternalCommandProcessor")
460 << "Disabling active checks for host '" << arguments[0] << "'";
462 host->ModifyAttribute("enable_active_checks", false);
465 void ExternalCommandProcessor::EnableSvcCheck(double, const std::vector<String>& arguments)
467 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
470 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable service check for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
472 Log(LogNotice, "ExternalCommandProcessor")
473 << "Enabling active checks for service '" << arguments[1] << "'";
475 service->ModifyAttribute("enable_active_checks", true);
478 void ExternalCommandProcessor::DisableSvcCheck(double, const std::vector<String>& arguments)
480 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
483 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable service check for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
485 Log(LogNotice, "ExternalCommandProcessor")
486 << "Disabling active checks for service '" << arguments[1] << "'";
488 service->ModifyAttribute("enable_active_checks", false);
491 void ExternalCommandProcessor::ShutdownProcess(double, const std::vector<String>&)
493 Log(LogNotice, "ExternalCommandProcessor", "Shutting down Icinga via external command.");
494 Application::RequestShutdown();
497 void ExternalCommandProcessor::RestartProcess(double, const std::vector<String>&)
499 Log(LogNotice, "ExternalCommandProcessor", "Restarting Icinga via external command.");
500 Application::RequestRestart();
503 void ExternalCommandProcessor::ScheduleForcedHostSvcChecks(double, const std::vector<String>& arguments)
505 double planned_check = Convert::ToDouble(arguments[1]);
507 Host::Ptr host = Host::GetByName(arguments[0]);
510 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot reschedule forced host service checks for non-existent host '" + arguments[0] + "'"));
512 for (const Service::Ptr& service : host->GetServices()) {
513 Log(LogNotice, "ExternalCommandProcessor")
514 << "Rescheduling next check for service '" << service->GetName() << "'";
516 service->SetNextCheck(planned_check);
517 service->SetForceNextCheck(true);
519 /* trigger update event for DB IDO */
520 Checkable::OnNextCheckUpdated(service);
524 void ExternalCommandProcessor::ScheduleHostSvcChecks(double, const std::vector<String>& arguments)
526 double planned_check = Convert::ToDouble(arguments[1]);
528 Host::Ptr host = Host::GetByName(arguments[0]);
531 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot reschedule host service checks for non-existent host '" + arguments[0] + "'"));
533 if (planned_check < Utility::GetTime())
534 planned_check = Utility::GetTime();
536 for (const Service::Ptr& service : host->GetServices()) {
537 if (planned_check > service->GetNextCheck()) {
538 Log(LogNotice, "ExternalCommandProcessor")
539 << "Ignoring reschedule request for service '"
540 << service->GetName() << "' (next check is already sooner than requested check time)";
544 Log(LogNotice, "ExternalCommandProcessor")
545 << "Rescheduling next check for service '" << service->GetName() << "'";
547 service->SetNextCheck(planned_check);
549 /* trigger update event for DB IDO */
550 Checkable::OnNextCheckUpdated(service);
554 void ExternalCommandProcessor::EnableHostSvcChecks(double, const std::vector<String>& arguments)
556 Host::Ptr host = Host::GetByName(arguments[0]);
559 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable host service checks for non-existent host '" + arguments[0] + "'"));
561 for (const Service::Ptr& service : host->GetServices()) {
562 Log(LogNotice, "ExternalCommandProcessor")
563 << "Enabling active checks for service '" << service->GetName() << "'";
565 service->ModifyAttribute("enable_active_checks", true);
569 void ExternalCommandProcessor::DisableHostSvcChecks(double, const std::vector<String>& arguments)
571 Host::Ptr host = Host::GetByName(arguments[0]);
574 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable host service checks for non-existent host '" + arguments[0] + "'"));
576 for (const Service::Ptr& service : host->GetServices()) {
577 Log(LogNotice, "ExternalCommandProcessor")
578 << "Disabling active checks for service '" << service->GetName() << "'";
580 service->ModifyAttribute("enable_active_checks", false);
584 void ExternalCommandProcessor::AcknowledgeSvcProblem(double, const std::vector<String>& arguments)
586 bool sticky = (Convert::ToLong(arguments[2]) == 2 ? true : false);
587 bool notify = (Convert::ToLong(arguments[3]) > 0 ? true : false);
588 bool persistent = (Convert::ToLong(arguments[4]) > 0 ? true : false);
590 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
593 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot acknowledge service problem for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
595 if (service->GetState() == ServiceOK)
596 BOOST_THROW_EXCEPTION(std::invalid_argument("The service '" + arguments[1] + "' is OK."));
598 Log(LogNotice, "ExternalCommandProcessor")
599 << "Setting acknowledgement for service '" << service->GetName() << "'" << (notify ? "" : ". Disabled notification");
601 Comment::AddComment(service, CommentAcknowledgement, arguments[5], arguments[6], persistent, 0);
602 service->AcknowledgeProblem(arguments[5], arguments[6], sticky ? AcknowledgementSticky : AcknowledgementNormal, notify, persistent);
605 void ExternalCommandProcessor::AcknowledgeSvcProblemExpire(double, const std::vector<String>& arguments)
607 bool sticky = (Convert::ToLong(arguments[2]) == 2 ? true : false);
608 bool notify = (Convert::ToLong(arguments[3]) > 0 ? true : false);
609 bool persistent = (Convert::ToLong(arguments[4]) > 0 ? true : false);
610 double timestamp = Convert::ToDouble(arguments[5]);
612 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
615 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot acknowledge service problem with expire time for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
617 if (service->GetState() == ServiceOK)
618 BOOST_THROW_EXCEPTION(std::invalid_argument("The service '" + arguments[1] + "' is OK."));
620 if (timestamp != 0 && timestamp <= Utility::GetTime())
621 BOOST_THROW_EXCEPTION(std::invalid_argument("Acknowledgement expire time must be in the future for service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
623 Log(LogNotice, "ExternalCommandProcessor")
624 << "Setting timed acknowledgement for service '" << service->GetName() << "'" << (notify ? "" : ". Disabled notification");
626 Comment::AddComment(service, CommentAcknowledgement, arguments[6], arguments[7], persistent, timestamp);
627 service->AcknowledgeProblem(arguments[6], arguments[7], sticky ? AcknowledgementSticky : AcknowledgementNormal, notify, persistent, timestamp);
630 void ExternalCommandProcessor::RemoveSvcAcknowledgement(double, const std::vector<String>& arguments)
632 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
635 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot remove service acknowledgement for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
637 Log(LogNotice, "ExternalCommandProcessor")
638 << "Removing acknowledgement for service '" << service->GetName() << "'";
641 ObjectLock olock(service);
642 service->ClearAcknowledgement();
645 service->RemoveCommentsByType(CommentAcknowledgement);
648 void ExternalCommandProcessor::AcknowledgeHostProblem(double, const std::vector<String>& arguments)
650 bool sticky = (Convert::ToLong(arguments[1]) == 2 ? true : false);
651 bool notify = (Convert::ToLong(arguments[2]) > 0 ? true : false);
652 bool persistent = (Convert::ToLong(arguments[3]) > 0 ? true : false);
654 Host::Ptr host = Host::GetByName(arguments[0]);
657 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot acknowledge host problem for non-existent host '" + arguments[0] + "'"));
659 Log(LogNotice, "ExternalCommandProcessor")
660 << "Setting acknowledgement for host '" << host->GetName() << "'" << (notify ? "" : ". Disabled notification");
662 if (host->GetState() == HostUp)
663 BOOST_THROW_EXCEPTION(std::invalid_argument("The host '" + arguments[0] + "' is OK."));
665 Comment::AddComment(host, CommentAcknowledgement, arguments[4], arguments[5], persistent, 0);
666 host->AcknowledgeProblem(arguments[4], arguments[5], sticky ? AcknowledgementSticky : AcknowledgementNormal, notify, persistent);
669 void ExternalCommandProcessor::AcknowledgeHostProblemExpire(double, const std::vector<String>& arguments)
671 bool sticky = (Convert::ToLong(arguments[1]) == 2 ? true : false);
672 bool notify = (Convert::ToLong(arguments[2]) > 0 ? true : false);
673 bool persistent = (Convert::ToLong(arguments[3]) > 0 ? true : false);
674 double timestamp = Convert::ToDouble(arguments[4]);
676 Host::Ptr host = Host::GetByName(arguments[0]);
679 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot acknowledge host problem with expire time for non-existent host '" + arguments[0] + "'"));
681 Log(LogNotice, "ExternalCommandProcessor")
682 << "Setting timed acknowledgement for host '" << host->GetName() << "'" << (notify ? "" : ". Disabled notification");
684 if (host->GetState() == HostUp)
685 BOOST_THROW_EXCEPTION(std::invalid_argument("The host '" + arguments[0] + "' is OK."));
687 if (timestamp != 0 && timestamp <= Utility::GetTime())
688 BOOST_THROW_EXCEPTION(std::invalid_argument("Acknowledgement expire time must be in the future for host '" + arguments[0] + "'"));
690 Comment::AddComment(host, CommentAcknowledgement, arguments[5], arguments[6], persistent, timestamp);
691 host->AcknowledgeProblem(arguments[5], arguments[6], sticky ? AcknowledgementSticky : AcknowledgementNormal, notify, persistent, timestamp);
694 void ExternalCommandProcessor::RemoveHostAcknowledgement(double, const std::vector<String>& arguments)
696 Host::Ptr host = Host::GetByName(arguments[0]);
699 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot remove acknowledgement for non-existent host '" + arguments[0] + "'"));
701 Log(LogNotice, "ExternalCommandProcessor")
702 << "Removing acknowledgement for host '" << host->GetName() << "'";
705 ObjectLock olock(host);
706 host->ClearAcknowledgement();
708 host->RemoveCommentsByType(CommentAcknowledgement);
711 void ExternalCommandProcessor::EnableHostgroupSvcChecks(double, const std::vector<String>& arguments)
713 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
716 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable hostgroup service checks for non-existent hostgroup '" + arguments[0] + "'"));
718 for (const Host::Ptr& host : hg->GetMembers()) {
719 for (const Service::Ptr& service : host->GetServices()) {
720 Log(LogNotice, "ExternalCommandProcessor")
721 << "Enabling active checks for service '" << service->GetName() << "'";
723 service->ModifyAttribute("enable_active_checks", true);
728 void ExternalCommandProcessor::DisableHostgroupSvcChecks(double, const std::vector<String>& arguments)
730 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
733 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable hostgroup service checks for non-existent hostgroup '" + arguments[0] + "'"));
735 for (const Host::Ptr& host : hg->GetMembers()) {
736 for (const Service::Ptr& service : host->GetServices()) {
737 Log(LogNotice, "ExternalCommandProcessor")
738 << "Disabling active checks for service '" << service->GetName() << "'";
740 service->ModifyAttribute("enable_active_checks", false);
745 void ExternalCommandProcessor::EnableServicegroupSvcChecks(double, const std::vector<String>& arguments)
747 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
750 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable servicegroup service checks for non-existent servicegroup '" + arguments[0] + "'"));
752 for (const Service::Ptr& service : sg->GetMembers()) {
753 Log(LogNotice, "ExternalCommandProcessor")
754 << "Enabling active checks for service '" << service->GetName() << "'";
756 service->ModifyAttribute("enable_active_checks", true);
760 void ExternalCommandProcessor::DisableServicegroupSvcChecks(double, const std::vector<String>& arguments)
762 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
765 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable servicegroup service checks for non-existent servicegroup '" + arguments[0] + "'"));
767 for (const Service::Ptr& service : sg->GetMembers()) {
768 Log(LogNotice, "ExternalCommandProcessor")
769 << "Disabling active checks for service '" << service->GetName() << "'";
771 service->ModifyAttribute("enable_active_checks", false);
775 void ExternalCommandProcessor::EnablePassiveHostChecks(double, const std::vector<String>& arguments)
777 Host::Ptr host = Host::GetByName(arguments[0]);
780 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable passive host checks for non-existent host '" + arguments[0] + "'"));
782 Log(LogNotice, "ExternalCommandProcessor")
783 << "Enabling passive checks for host '" << arguments[0] << "'";
785 host->ModifyAttribute("enable_passive_checks", true);
788 void ExternalCommandProcessor::DisablePassiveHostChecks(double, const std::vector<String>& arguments)
790 Host::Ptr host = Host::GetByName(arguments[0]);
793 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable passive host checks for non-existent host '" + arguments[0] + "'"));
795 Log(LogNotice, "ExternalCommandProcessor")
796 << "Disabling passive checks for host '" << arguments[0] << "'";
798 host->ModifyAttribute("enable_passive_checks", false);
801 void ExternalCommandProcessor::EnablePassiveSvcChecks(double, const std::vector<String>& arguments)
803 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
806 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable service checks for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
808 Log(LogNotice, "ExternalCommandProcessor")
809 << "Enabling passive checks for service '" << arguments[1] << "'";
811 service->ModifyAttribute("enable_passive_checks", true);
814 void ExternalCommandProcessor::DisablePassiveSvcChecks(double, const std::vector<String>& arguments)
816 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
819 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable service checks for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
821 Log(LogNotice, "ExternalCommandProcessor")
822 << "Disabling passive checks for service '" << arguments[1] << "'";
824 service->ModifyAttribute("enable_passive_checks", false);
827 void ExternalCommandProcessor::EnableServicegroupPassiveSvcChecks(double, const std::vector<String>& arguments)
829 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
832 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable servicegroup passive service checks for non-existent servicegroup '" + arguments[0] + "'"));
834 for (const Service::Ptr& service : sg->GetMembers()) {
835 Log(LogNotice, "ExternalCommandProcessor")
836 << "Enabling passive checks for service '" << service->GetName() << "'";
838 service->ModifyAttribute("enable_passive_checks", true);
842 void ExternalCommandProcessor::DisableServicegroupPassiveSvcChecks(double, const std::vector<String>& arguments)
844 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
847 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable servicegroup passive service checks for non-existent servicegroup '" + arguments[0] + "'"));
849 for (const Service::Ptr& service : sg->GetMembers()) {
850 Log(LogNotice, "ExternalCommandProcessor")
851 << "Disabling passive checks for service '" << service->GetName() << "'";
853 service->ModifyAttribute("enable_passive_checks", false);
857 void ExternalCommandProcessor::EnableHostgroupPassiveSvcChecks(double, const std::vector<String>& arguments)
859 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
862 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable hostgroup passive service checks for non-existent hostgroup '" + arguments[0] + "'"));
864 for (const Host::Ptr& host : hg->GetMembers()) {
865 for (const Service::Ptr& service : host->GetServices()) {
866 Log(LogNotice, "ExternalCommandProcessor")
867 << "Enabling passive checks for service '" << service->GetName() << "'";
869 service->ModifyAttribute("enable_passive_checks", true);
874 void ExternalCommandProcessor::DisableHostgroupPassiveSvcChecks(double, const std::vector<String>& arguments)
876 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
879 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable hostgroup passive service checks for non-existent hostgroup '" + arguments[0] + "'"));
881 for (const Host::Ptr& host : hg->GetMembers()) {
882 for (const Service::Ptr& service : host->GetServices()) {
883 Log(LogNotice, "ExternalCommandProcessor")
884 << "Disabling passive checks for service '" << service->GetName() << "'";
886 service->ModifyAttribute("enable_passive_checks", false);
891 void ExternalCommandProcessor::ProcessFile(double, const std::vector<String>& arguments)
893 std::deque< std::vector<String> > file_queue;
894 file_queue.push_back(arguments);
896 while (!file_queue.empty()) {
897 std::vector<String> argument = file_queue.front();
898 file_queue.pop_front();
900 String file = argument[0];
901 int to_delete = Convert::ToLong(argument[1]);
904 ifp.exceptions(std::ifstream::badbit);
906 ifp.open(file.CStr(), std::ifstream::in);
910 std::getline(ifp, line);
913 Log(LogNotice, "compat")
914 << "Executing external command: " << line;
916 ExecuteFromFile(line, file_queue);
917 } catch (const std::exception& ex) {
918 Log(LogWarning, "ExternalCommandProcessor")
919 << "External command failed: " << DiagnosticInformation(ex);
926 (void) unlink(file.CStr());
930 void ExternalCommandProcessor::ScheduleSvcDowntime(double, const std::vector<String>& arguments)
932 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
935 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot schedule service downtime for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
938 int triggeredByLegacy = Convert::ToLong(arguments[5]);
939 int is_fixed = Convert::ToLong(arguments[4]);
940 if (triggeredByLegacy != 0)
941 triggeredBy = Downtime::GetDowntimeIDFromLegacyID(triggeredByLegacy);
943 Log(LogNotice, "ExternalCommandProcessor")
944 << "Creating downtime for service " << service->GetName();
945 (void) Downtime::AddDowntime(service, arguments[7], arguments[8],
946 Convert::ToDouble(arguments[2]), Convert::ToDouble(arguments[3]),
947 Convert::ToBool(is_fixed), triggeredBy, Convert::ToDouble(arguments[6]));
950 void ExternalCommandProcessor::DelSvcDowntime(double, const std::vector<String>& arguments)
952 int id = Convert::ToLong(arguments[0]);
953 Log(LogNotice, "ExternalCommandProcessor")
954 << "Removing downtime ID " << arguments[0];
955 String rid = Downtime::GetDowntimeIDFromLegacyID(id);
956 Downtime::RemoveDowntime(rid, true);
959 void ExternalCommandProcessor::ScheduleHostDowntime(double, const std::vector<String>& arguments)
961 Host::Ptr host = Host::GetByName(arguments[0]);
964 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot schedule host downtime for non-existent host '" + arguments[0] + "'"));
967 int triggeredByLegacy = Convert::ToLong(arguments[4]);
968 int is_fixed = Convert::ToLong(arguments[3]);
969 if (triggeredByLegacy != 0)
970 triggeredBy = Downtime::GetDowntimeIDFromLegacyID(triggeredByLegacy);
972 Log(LogNotice, "ExternalCommandProcessor")
973 << "Creating downtime for host " << host->GetName();
975 (void) Downtime::AddDowntime(host, arguments[6], arguments[7],
976 Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
977 Convert::ToBool(is_fixed), triggeredBy, Convert::ToDouble(arguments[5]));
980 void ExternalCommandProcessor::ScheduleAndPropagateHostDowntime(double, const std::vector<String>& arguments)
982 Host::Ptr host = Host::GetByName(arguments[0]);
985 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot schedule and propagate host downtime for non-existent host '" + arguments[0] + "'"));
988 int triggeredByLegacy = Convert::ToLong(arguments[4]);
989 int is_fixed = Convert::ToLong(arguments[3]);
990 if (triggeredByLegacy != 0)
991 triggeredBy = Downtime::GetDowntimeIDFromLegacyID(triggeredByLegacy);
993 Log(LogNotice, "ExternalCommandProcessor")
994 << "Creating downtime for host " << host->GetName();
996 (void) Downtime::AddDowntime(host, arguments[6], arguments[7],
997 Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
998 Convert::ToBool(is_fixed), triggeredBy, Convert::ToDouble(arguments[5]));
1000 /* Schedule downtime for all child hosts */
1001 for (const Checkable::Ptr& child : host->GetAllChildren()) {
1003 Service::Ptr service;
1004 tie(host, service) = GetHostService(child);
1006 /* ignore all service children */
1010 (void) Downtime::AddDowntime(child, arguments[6], arguments[7],
1011 Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
1012 Convert::ToBool(is_fixed), triggeredBy, Convert::ToDouble(arguments[5]));
1016 void ExternalCommandProcessor::ScheduleAndPropagateTriggeredHostDowntime(double, const std::vector<String>& arguments)
1018 Host::Ptr host = Host::GetByName(arguments[0]);
1021 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot schedule and propagate triggered host downtime for non-existent host '" + arguments[0] + "'"));
1024 int triggeredByLegacy = Convert::ToLong(arguments[4]);
1025 int is_fixed = Convert::ToLong(arguments[3]);
1026 if (triggeredByLegacy != 0)
1027 triggeredBy = Downtime::GetDowntimeIDFromLegacyID(triggeredByLegacy);
1029 Log(LogNotice, "ExternalCommandProcessor")
1030 << "Creating downtime for host " << host->GetName();
1032 String parentDowntime = Downtime::AddDowntime(host, arguments[6], arguments[7],
1033 Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
1034 Convert::ToBool(is_fixed), triggeredBy, Convert::ToDouble(arguments[5]));
1036 /* Schedule downtime for all child hosts and explicitely trigger them through the parent host's downtime */
1037 for (const Checkable::Ptr& child : host->GetAllChildren()) {
1039 Service::Ptr service;
1040 tie(host, service) = GetHostService(child);
1042 /* ignore all service children */
1046 (void) Downtime::AddDowntime(child, arguments[6], arguments[7],
1047 Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
1048 Convert::ToBool(is_fixed), parentDowntime, Convert::ToDouble(arguments[5]));
1052 void ExternalCommandProcessor::DelHostDowntime(double, const std::vector<String>& arguments)
1054 int id = Convert::ToLong(arguments[0]);
1055 Log(LogNotice, "ExternalCommandProcessor")
1056 << "Removing downtime ID " << arguments[0];
1057 String rid = Downtime::GetDowntimeIDFromLegacyID(id);
1058 Downtime::RemoveDowntime(rid, true);
1061 void ExternalCommandProcessor::DelDowntimeByHostName(double, const std::vector<String>& arguments)
1063 Host::Ptr host = Host::GetByName(arguments[0]);
1066 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot schedule host services downtime for non-existent host '" + arguments[0] + "'"));
1069 if (arguments.size() >= 2)
1070 serviceName = arguments[1];
1073 if (arguments.size() >= 3)
1074 startTime = arguments[2];
1076 String commentString;
1077 if (arguments.size() >= 4)
1078 commentString = arguments[3];
1080 if (arguments.size() > 5)
1081 Log(LogWarning, "ExternalCommandProcessor")
1082 << ("Ignoring additional parameters for host '" + arguments[0] + "' downtime deletion.");
1084 for (const Downtime::Ptr& downtime : host->GetDowntimes()) {
1085 Log(LogNotice, "ExternalCommandProcessor")
1086 << "Removing downtime '" << downtime->GetName() << "'.";
1088 Downtime::RemoveDowntime(downtime->GetName(), true);
1091 for (const Service::Ptr& service : host->GetServices()) {
1092 if (!serviceName.IsEmpty() && serviceName != service->GetName())
1095 for (const Downtime::Ptr& downtime : service->GetDowntimes()) {
1096 if (!startTime.IsEmpty() && downtime->GetStartTime() != Convert::ToDouble(startTime))
1099 if (!commentString.IsEmpty() && downtime->GetComment() != commentString)
1102 Log(LogNotice, "ExternalCommandProcessor")
1103 << "Removing downtime '" << downtime->GetName() << "'.";
1105 Downtime::RemoveDowntime(downtime->GetName(), true);
1110 void ExternalCommandProcessor::ScheduleHostSvcDowntime(double, const std::vector<String>& arguments)
1112 Host::Ptr host = Host::GetByName(arguments[0]);
1115 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot schedule host services downtime for non-existent host '" + arguments[0] + "'"));
1118 int triggeredByLegacy = Convert::ToLong(arguments[4]);
1119 int is_fixed = Convert::ToLong(arguments[3]);
1120 if (triggeredByLegacy != 0)
1121 triggeredBy = Downtime::GetDowntimeIDFromLegacyID(triggeredByLegacy);
1123 Log(LogNotice, "ExternalCommandProcessor")
1124 << "Creating downtime for host " << host->GetName();
1126 (void) Downtime::AddDowntime(host, arguments[6], arguments[7],
1127 Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
1128 Convert::ToBool(is_fixed), triggeredBy, Convert::ToDouble(arguments[5]));
1130 for (const Service::Ptr& service : host->GetServices()) {
1131 Log(LogNotice, "ExternalCommandProcessor")
1132 << "Creating downtime for service " << service->GetName();
1133 (void) Downtime::AddDowntime(service, arguments[6], arguments[7],
1134 Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
1135 Convert::ToBool(is_fixed), triggeredBy, Convert::ToDouble(arguments[5]));
1139 void ExternalCommandProcessor::ScheduleHostgroupHostDowntime(double, const std::vector<String>& arguments)
1141 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
1144 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot schedule hostgroup host downtime for non-existent hostgroup '" + arguments[0] + "'"));
1147 int triggeredByLegacy = Convert::ToLong(arguments[4]);
1148 int is_fixed = Convert::ToLong(arguments[3]);
1149 if (triggeredByLegacy != 0)
1150 triggeredBy = Downtime::GetDowntimeIDFromLegacyID(triggeredByLegacy);
1152 for (const Host::Ptr& host : hg->GetMembers()) {
1153 Log(LogNotice, "ExternalCommandProcessor")
1154 << "Creating downtime for host " << host->GetName();
1156 (void) Downtime::AddDowntime(host, arguments[6], arguments[7],
1157 Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
1158 Convert::ToBool(is_fixed), triggeredBy, Convert::ToDouble(arguments[5]));
1162 void ExternalCommandProcessor::ScheduleHostgroupSvcDowntime(double, const std::vector<String>& arguments)
1164 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
1167 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot schedule hostgroup service downtime for non-existent hostgroup '" + arguments[0] + "'"));
1170 int triggeredByLegacy = Convert::ToLong(arguments[4]);
1171 int is_fixed = Convert::ToLong(arguments[3]);
1172 if (triggeredByLegacy != 0)
1173 triggeredBy = Downtime::GetDowntimeIDFromLegacyID(triggeredByLegacy);
1175 /* Note: we can't just directly create downtimes for all the services by iterating
1176 * over all hosts in the host group - otherwise we might end up creating multiple
1177 * downtimes for some services. */
1179 std::set<Service::Ptr> services;
1181 for (const Host::Ptr& host : hg->GetMembers()) {
1182 for (const Service::Ptr& service : host->GetServices()) {
1183 services.insert(service);
1187 for (const Service::Ptr& service : services) {
1188 Log(LogNotice, "ExternalCommandProcessor")
1189 << "Creating downtime for service " << service->GetName();
1190 (void) Downtime::AddDowntime(service, arguments[6], arguments[7],
1191 Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
1192 Convert::ToBool(is_fixed), triggeredBy, Convert::ToDouble(arguments[5]));
1196 void ExternalCommandProcessor::ScheduleServicegroupHostDowntime(double, const std::vector<String>& arguments)
1198 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
1201 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot schedule servicegroup host downtime for non-existent servicegroup '" + arguments[0] + "'"));
1204 int triggeredByLegacy = Convert::ToLong(arguments[4]);
1205 int is_fixed = Convert::ToLong(arguments[3]);
1206 if (triggeredByLegacy != 0)
1207 triggeredBy = Downtime::GetDowntimeIDFromLegacyID(triggeredByLegacy);
1209 /* Note: we can't just directly create downtimes for all the hosts by iterating
1210 * over all services in the service group - otherwise we might end up creating multiple
1211 * downtimes for some hosts. */
1213 std::set<Host::Ptr> hosts;
1215 for (const Service::Ptr& service : sg->GetMembers()) {
1216 Host::Ptr host = service->GetHost();
1220 for (const Host::Ptr& host : hosts) {
1221 Log(LogNotice, "ExternalCommandProcessor")
1222 << "Creating downtime for host " << host->GetName();
1223 (void) Downtime::AddDowntime(host, arguments[6], arguments[7],
1224 Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
1225 Convert::ToBool(is_fixed), triggeredBy, Convert::ToDouble(arguments[5]));
1229 void ExternalCommandProcessor::ScheduleServicegroupSvcDowntime(double, const std::vector<String>& arguments)
1231 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
1234 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot schedule servicegroup service downtime for non-existent servicegroup '" + arguments[0] + "'"));
1237 int triggeredByLegacy = Convert::ToLong(arguments[4]);
1238 int is_fixed = Convert::ToLong(arguments[3]);
1239 if (triggeredByLegacy != 0)
1240 triggeredBy = Downtime::GetDowntimeIDFromLegacyID(triggeredByLegacy);
1242 for (const Service::Ptr& service : sg->GetMembers()) {
1243 Log(LogNotice, "ExternalCommandProcessor")
1244 << "Creating downtime for service " << service->GetName();
1245 (void) Downtime::AddDowntime(service, arguments[6], arguments[7],
1246 Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
1247 Convert::ToBool(is_fixed), triggeredBy, Convert::ToDouble(arguments[5]));
1251 void ExternalCommandProcessor::AddHostComment(double, const std::vector<String>& arguments)
1253 Host::Ptr host = Host::GetByName(arguments[0]);
1256 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot add host comment for non-existent host '" + arguments[0] + "'"));
1258 if (arguments[2].IsEmpty() || arguments[3].IsEmpty())
1259 BOOST_THROW_EXCEPTION(std::invalid_argument("Author and comment must not be empty"));
1261 Log(LogNotice, "ExternalCommandProcessor")
1262 << "Creating comment for host " << host->GetName();
1263 (void) Comment::AddComment(host, CommentUser, arguments[2], arguments[3], false, 0);
1266 void ExternalCommandProcessor::DelHostComment(double, const std::vector<String>& arguments)
1268 int id = Convert::ToLong(arguments[0]);
1269 Log(LogNotice, "ExternalCommandProcessor")
1270 << "Removing comment ID " << arguments[0];
1271 String rid = Comment::GetCommentIDFromLegacyID(id);
1272 Comment::RemoveComment(rid);
1275 void ExternalCommandProcessor::AddSvcComment(double, const std::vector<String>& arguments)
1277 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1280 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot add service comment for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
1282 if (arguments[3].IsEmpty() || arguments[4].IsEmpty())
1283 BOOST_THROW_EXCEPTION(std::invalid_argument("Author and comment must not be empty"));
1285 Log(LogNotice, "ExternalCommandProcessor")
1286 << "Creating comment for service " << service->GetName();
1287 (void) Comment::AddComment(service, CommentUser, arguments[3], arguments[4], false, 0);
1290 void ExternalCommandProcessor::DelSvcComment(double, const std::vector<String>& arguments)
1292 int id = Convert::ToLong(arguments[0]);
1293 Log(LogNotice, "ExternalCommandProcessor")
1294 << "Removing comment ID " << arguments[0];
1296 String rid = Comment::GetCommentIDFromLegacyID(id);
1297 Comment::RemoveComment(rid);
1300 void ExternalCommandProcessor::DelAllHostComments(double, const std::vector<String>& arguments)
1302 Host::Ptr host = Host::GetByName(arguments[0]);
1305 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot delete all host comments for non-existent host '" + arguments[0] + "'"));
1307 Log(LogNotice, "ExternalCommandProcessor")
1308 << "Removing all comments for host " << host->GetName();
1309 host->RemoveAllComments();
1312 void ExternalCommandProcessor::DelAllSvcComments(double, const std::vector<String>& arguments)
1314 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1317 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot delete all service comments for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
1319 Log(LogNotice, "ExternalCommandProcessor")
1320 << "Removing all comments for service " << service->GetName();
1321 service->RemoveAllComments();
1324 void ExternalCommandProcessor::SendCustomHostNotification(double, const std::vector<String>& arguments)
1326 Host::Ptr host = Host::GetByName(arguments[0]);
1329 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot send custom host notification for non-existent host '" + arguments[0] + "'"));
1331 int options = Convert::ToLong(arguments[1]);
1333 Log(LogNotice, "ExternalCommandProcessor")
1334 << "Sending custom notification for host " << host->GetName();
1336 host->SetForceNextNotification(true);
1339 Checkable::OnNotificationsRequested(host, NotificationCustom,
1340 host->GetLastCheckResult(), arguments[2], arguments[3], nullptr);
1343 void ExternalCommandProcessor::SendCustomSvcNotification(double, const std::vector<String>& arguments)
1345 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1348 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot send custom service notification for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
1350 int options = Convert::ToLong(arguments[2]);
1352 Log(LogNotice, "ExternalCommandProcessor")
1353 << "Sending custom notification for service " << service->GetName();
1356 service->SetForceNextNotification(true);
1359 Service::OnNotificationsRequested(service, NotificationCustom,
1360 service->GetLastCheckResult(), arguments[3], arguments[4], nullptr);
1363 void ExternalCommandProcessor::DelayHostNotification(double, const std::vector<String>& arguments)
1365 Host::Ptr host = Host::GetByName(arguments[0]);
1368 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot delay host notification for non-existent host '" + arguments[0] + "'"));
1370 Log(LogNotice, "ExternalCommandProcessor")
1371 << "Delaying notifications for host '" << host->GetName() << "'";
1373 for (const Notification::Ptr& notification : host->GetNotifications()) {
1374 notification->SetNextNotification(Convert::ToDouble(arguments[1]));
1378 void ExternalCommandProcessor::DelaySvcNotification(double, const std::vector<String>& arguments)
1380 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1383 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot delay service notification for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
1385 Log(LogNotice, "ExternalCommandProcessor")
1386 << "Delaying notifications for service " << service->GetName();
1388 for (const Notification::Ptr& notification : service->GetNotifications()) {
1389 notification->SetNextNotification(Convert::ToDouble(arguments[2]));
1393 void ExternalCommandProcessor::EnableHostNotifications(double, const std::vector<String>& arguments)
1395 Host::Ptr host = Host::GetByName(arguments[0]);
1398 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable host notifications for non-existent host '" + arguments[0] + "'"));
1400 Log(LogNotice, "ExternalCommandProcessor")
1401 << "Enabling notifications for host '" << arguments[0] << "'";
1403 host->ModifyAttribute("enable_notifications", true);
1406 void ExternalCommandProcessor::DisableHostNotifications(double, const std::vector<String>& arguments)
1408 Host::Ptr host = Host::GetByName(arguments[0]);
1411 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable host notifications for non-existent host '" + arguments[0] + "'"));
1413 Log(LogNotice, "ExternalCommandProcessor")
1414 << "Disabling notifications for host '" << arguments[0] << "'";
1416 host->ModifyAttribute("enable_notifications", false);
1419 void ExternalCommandProcessor::EnableSvcNotifications(double, const std::vector<String>& arguments)
1421 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1424 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable service notifications for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
1426 Log(LogNotice, "ExternalCommandProcessor")
1427 << "Enabling notifications for service '" << arguments[1] << "'";
1429 service->ModifyAttribute("enable_notifications", true);
1432 void ExternalCommandProcessor::DisableSvcNotifications(double, const std::vector<String>& arguments)
1434 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1437 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable service notifications for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
1439 Log(LogNotice, "ExternalCommandProcessor")
1440 << "Disabling notifications for service '" << arguments[1] << "'";
1442 service->ModifyAttribute("enable_notifications", false);
1445 void ExternalCommandProcessor::EnableHostSvcNotifications(double, const std::vector<String>& arguments)
1447 Host::Ptr host = Host::GetByName(arguments[0]);
1450 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable notifications for all services for non-existent host '" + arguments[0] + "'"));
1452 Log(LogNotice, "ExternalCommandProcessor")
1453 << "Enabling notifications for all services on host '" << arguments[0] << "'";
1455 for (const Service::Ptr& service : host->GetServices()) {
1456 Log(LogNotice, "ExternalCommandProcessor")
1457 << "Enabling notifications for service '" << service->GetName() << "'";
1459 service->ModifyAttribute("enable_notifications", true);
1463 void ExternalCommandProcessor::DisableHostSvcNotifications(double, const std::vector<String>& arguments)
1465 Host::Ptr host = Host::GetByName(arguments[0]);
1468 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable notifications for all services for non-existent host '" + arguments[0] + "'"));
1470 Log(LogNotice, "ExternalCommandProcessor")
1471 << "Disabling notifications for all services on host '" << arguments[0] << "'";
1473 for (const Service::Ptr& service : host->GetServices()) {
1474 Log(LogNotice, "ExternalCommandProcessor")
1475 << "Disabling notifications for service '" << service->GetName() << "'";
1477 service->ModifyAttribute("enable_notifications", false);
1481 void ExternalCommandProcessor::DisableHostgroupHostChecks(double, const std::vector<String>& arguments)
1483 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
1486 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable hostgroup host checks for non-existent hostgroup '" + arguments[0] + "'"));
1488 for (const Host::Ptr& host : hg->GetMembers()) {
1489 Log(LogNotice, "ExternalCommandProcessor")
1490 << "Disabling active checks for host '" << host->GetName() << "'";
1492 host->ModifyAttribute("enable_active_checks", false);
1496 void ExternalCommandProcessor::DisableHostgroupPassiveHostChecks(double, const std::vector<String>& arguments)
1498 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
1501 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable hostgroup passive host checks for non-existent hostgroup '" + arguments[0] + "'"));
1503 for (const Host::Ptr& host : hg->GetMembers()) {
1504 Log(LogNotice, "ExternalCommandProcessor")
1505 << "Disabling passive checks for host '" << host->GetName() << "'";
1507 host->ModifyAttribute("enable_passive_checks", false);
1511 void ExternalCommandProcessor::DisableServicegroupHostChecks(double, const std::vector<String>& arguments)
1513 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
1516 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable servicegroup host checks for non-existent servicegroup '" + arguments[0] + "'"));
1518 for (const Service::Ptr& service : sg->GetMembers()) {
1519 Host::Ptr host = service->GetHost();
1521 Log(LogNotice, "ExternalCommandProcessor")
1522 << "Disabling active checks for host '" << host->GetName() << "'";
1524 host->ModifyAttribute("enable_active_checks", false);
1528 void ExternalCommandProcessor::DisableServicegroupPassiveHostChecks(double, const std::vector<String>& arguments)
1530 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
1533 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable servicegroup passive host checks for non-existent servicegroup '" + arguments[0] + "'"));
1535 for (const Service::Ptr& service : sg->GetMembers()) {
1536 Host::Ptr host = service->GetHost();
1538 Log(LogNotice, "ExternalCommandProcessor")
1539 << "Disabling passive checks for host '" << host->GetName() << "'";
1541 host->ModifyAttribute("enable_passive_checks", false);
1545 void ExternalCommandProcessor::EnableHostgroupHostChecks(double, const std::vector<String>& arguments)
1547 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
1550 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable hostgroup host checks for non-existent hostgroup '" + arguments[0] + "'"));
1552 for (const Host::Ptr& host : hg->GetMembers()) {
1553 Log(LogNotice, "ExternalCommandProcessor")
1554 << "Enabling active checks for host '" << host->GetName() << "'";
1556 host->ModifyAttribute("enable_active_checks", true);
1560 void ExternalCommandProcessor::EnableHostgroupPassiveHostChecks(double, const std::vector<String>& arguments)
1562 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
1565 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable hostgroup passive host checks for non-existent hostgroup '" + arguments[0] + "'"));
1567 for (const Host::Ptr& host : hg->GetMembers()) {
1568 Log(LogNotice, "ExternalCommandProcessor")
1569 << "Enabling passive checks for host '" << host->GetName() << "'";
1571 host->ModifyAttribute("enable_passive_checks", true);
1575 void ExternalCommandProcessor::EnableServicegroupHostChecks(double, const std::vector<String>& arguments)
1577 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
1580 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable servicegroup host checks for non-existent servicegroup '" + arguments[0] + "'"));
1582 for (const Service::Ptr& service : sg->GetMembers()) {
1583 Host::Ptr host = service->GetHost();
1585 Log(LogNotice, "ExternalCommandProcessor")
1586 << "Enabling active checks for host '" << host->GetName() << "'";
1588 host->ModifyAttribute("enable_active_checks", true);
1592 void ExternalCommandProcessor::EnableServicegroupPassiveHostChecks(double, const std::vector<String>& arguments)
1594 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
1597 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable servicegroup passive host checks for non-existent servicegroup '" + arguments[0] + "'"));
1599 for (const Service::Ptr& service : sg->GetMembers()) {
1600 Host::Ptr host = service->GetHost();
1602 Log(LogNotice, "ExternalCommandProcessor")
1603 << "Enabling passive checks for host '" << host->GetName() << "'";
1605 host->ModifyAttribute("enable_passive_checks", true);
1609 void ExternalCommandProcessor::EnableHostFlapping(double, const std::vector<String>& arguments)
1611 Host::Ptr host = Host::GetByName(arguments[0]);
1614 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable host flapping for non-existent host '" + arguments[0] + "'"));
1616 Log(LogNotice, "ExternalCommandProcessor")
1617 << "Enabling flapping detection for host '" << arguments[0] << "'";
1619 host->ModifyAttribute("enable_flapping", true);
1622 void ExternalCommandProcessor::DisableHostFlapping(double, const std::vector<String>& arguments)
1624 Host::Ptr host = Host::GetByName(arguments[0]);
1627 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable host flapping for non-existent host '" + arguments[0] + "'"));
1629 Log(LogNotice, "ExternalCommandProcessor")
1630 << "Disabling flapping detection for host '" << arguments[0] << "'";
1632 host->ModifyAttribute("enable_flapping", false);
1635 void ExternalCommandProcessor::EnableSvcFlapping(double, const std::vector<String>& arguments)
1637 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1640 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable service flapping for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
1642 Log(LogNotice, "ExternalCommandProcessor")
1643 << "Enabling flapping detection for service '" << arguments[1] << "'";
1645 service->ModifyAttribute("enable_flapping", true);
1648 void ExternalCommandProcessor::DisableSvcFlapping(double, const std::vector<String>& arguments)
1650 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1653 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable service flapping for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
1655 Log(LogNotice, "ExternalCommandProcessor")
1656 << "Disabling flapping detection for service '" << arguments[1] << "'";
1658 service->ModifyAttribute("enable_flapping", false);
1661 void ExternalCommandProcessor::EnableNotifications(double, const std::vector<String>&)
1663 Log(LogNotice, "ExternalCommandProcessor", "Globally enabling notifications.");
1665 IcingaApplication::GetInstance()->ModifyAttribute("enable_notifications", true);
1668 void ExternalCommandProcessor::DisableNotifications(double, const std::vector<String>&)
1670 Log(LogNotice, "ExternalCommandProcessor", "Globally disabling notifications.");
1672 IcingaApplication::GetInstance()->ModifyAttribute("enable_notifications", false);
1675 void ExternalCommandProcessor::EnableFlapDetection(double, const std::vector<String>&)
1677 Log(LogNotice, "ExternalCommandProcessor", "Globally enabling flap detection.");
1679 IcingaApplication::GetInstance()->ModifyAttribute("enable_flapping", true);
1682 void ExternalCommandProcessor::DisableFlapDetection(double, const std::vector<String>&)
1684 Log(LogNotice, "ExternalCommandProcessor", "Globally disabling flap detection.");
1686 IcingaApplication::GetInstance()->ModifyAttribute("enable_flapping", false);
1689 void ExternalCommandProcessor::EnableEventHandlers(double, const std::vector<String>&)
1691 Log(LogNotice, "ExternalCommandProcessor", "Globally enabling event handlers.");
1693 IcingaApplication::GetInstance()->ModifyAttribute("enable_event_handlers", true);
1696 void ExternalCommandProcessor::DisableEventHandlers(double, const std::vector<String>&)
1698 Log(LogNotice, "ExternalCommandProcessor", "Globally disabling event handlers.");
1700 IcingaApplication::GetInstance()->ModifyAttribute("enable_event_handlers", false);
1703 void ExternalCommandProcessor::EnablePerformanceData(double, const std::vector<String>&)
1705 Log(LogNotice, "ExternalCommandProcessor", "Globally enabling performance data processing.");
1707 IcingaApplication::GetInstance()->ModifyAttribute("enable_perfdata", true);
1710 void ExternalCommandProcessor::DisablePerformanceData(double, const std::vector<String>&)
1712 Log(LogNotice, "ExternalCommandProcessor", "Globally disabling performance data processing.");
1714 IcingaApplication::GetInstance()->ModifyAttribute("enable_perfdata", false);
1717 void ExternalCommandProcessor::StartExecutingSvcChecks(double, const std::vector<String>&)
1719 Log(LogNotice, "ExternalCommandProcessor", "Globally enabling service checks.");
1721 IcingaApplication::GetInstance()->ModifyAttribute("enable_service_checks", true);
1724 void ExternalCommandProcessor::StopExecutingSvcChecks(double, const std::vector<String>&)
1726 Log(LogNotice, "ExternalCommandProcessor", "Globally disabling service checks.");
1728 IcingaApplication::GetInstance()->ModifyAttribute("enable_service_checks", false);
1731 void ExternalCommandProcessor::StartExecutingHostChecks(double, const std::vector<String>&)
1733 Log(LogNotice, "ExternalCommandProcessor", "Globally enabling host checks.");
1735 IcingaApplication::GetInstance()->ModifyAttribute("enable_host_checks", true);
1738 void ExternalCommandProcessor::StopExecutingHostChecks(double, const std::vector<String>&)
1740 Log(LogNotice, "ExternalCommandProcessor", "Globally disabling host checks.");
1742 IcingaApplication::GetInstance()->ModifyAttribute("enable_host_checks", false);
1745 void ExternalCommandProcessor::ChangeNormalSvcCheckInterval(double, const std::vector<String>& arguments)
1747 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1750 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot update check interval for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
1752 double interval = Convert::ToDouble(arguments[2]);
1754 Log(LogNotice, "ExternalCommandProcessor")
1755 << "Updating check interval for service '" << arguments[1] << "'";
1757 service->ModifyAttribute("check_interval", interval * 60);
1760 void ExternalCommandProcessor::ChangeNormalHostCheckInterval(double, const std::vector<String>& arguments)
1762 Host::Ptr host = Host::GetByName(arguments[0]);
1765 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot update check interval for non-existent host '" + arguments[0] + "'"));
1767 Log(LogNotice, "ExternalCommandProcessor")
1768 << "Updating check interval for host '" << arguments[0] << "'";
1770 double interval = Convert::ToDouble(arguments[1]);
1772 host->ModifyAttribute("check_interval", interval * 60);
1775 void ExternalCommandProcessor::ChangeRetrySvcCheckInterval(double, const std::vector<String>& arguments)
1777 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1780 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot update retry interval for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
1782 double interval = Convert::ToDouble(arguments[2]);
1784 Log(LogNotice, "ExternalCommandProcessor")
1785 << "Updating retry interval for service '" << arguments[1] << "'";
1787 service->ModifyAttribute("retry_interval", interval * 60);
1790 void ExternalCommandProcessor::ChangeRetryHostCheckInterval(double, const std::vector<String>& arguments)
1792 Host::Ptr host = Host::GetByName(arguments[0]);
1795 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot update retry interval for non-existent host '" + arguments[0] + "'"));
1797 Log(LogNotice, "ExternalCommandProcessor")
1798 << "Updating retry interval for host '" << arguments[0] << "'";
1800 double interval = Convert::ToDouble(arguments[1]);
1802 host->ModifyAttribute("retry_interval", interval * 60);
1805 void ExternalCommandProcessor::EnableHostEventHandler(double, const std::vector<String>& arguments)
1807 Host::Ptr host = Host::GetByName(arguments[0]);
1810 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable event handler for non-existent host '" + arguments[0] + "'"));
1812 Log(LogNotice, "ExternalCommandProcessor")
1813 << "Enabling event handler for host '" << arguments[0] << "'";
1815 host->ModifyAttribute("enable_event_handler", true);
1818 void ExternalCommandProcessor::DisableHostEventHandler(double, const std::vector<String>& arguments)
1820 Host::Ptr host = Host::GetByName(arguments[0]);
1823 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable event handler for non-existent host '" + arguments[0] + "'"));
1825 Log(LogNotice, "ExternalCommandProcessor")
1826 << "Disabling event handler for host '" << arguments[0] << "'";
1828 host->ModifyAttribute("enable_event_handler", false);
1831 void ExternalCommandProcessor::EnableSvcEventHandler(double, const std::vector<String>& arguments)
1833 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1836 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable event handler for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
1838 Log(LogNotice, "ExternalCommandProcessor")
1839 << "Enabling event handler for service '" << arguments[1] << "'";
1841 service->ModifyAttribute("enable_event_handler", true);
1844 void ExternalCommandProcessor::DisableSvcEventHandler(double, const std::vector<String>& arguments)
1846 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1849 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable event handler for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
1851 Log(LogNotice, "ExternalCommandProcessor")
1852 << "Disabling event handler for service '" << arguments[1] + "'";
1854 service->ModifyAttribute("enable_event_handler", false);
1857 void ExternalCommandProcessor::ChangeHostEventHandler(double, const std::vector<String>& arguments)
1859 Host::Ptr host = Host::GetByName(arguments[0]);
1862 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change event handler for non-existent host '" + arguments[0] + "'"));
1864 if (arguments[1].IsEmpty()) {
1865 Log(LogNotice, "ExternalCommandProcessor")
1866 << "Unsetting event handler for host '" << arguments[0] << "'";
1868 host->ModifyAttribute("event_command", "");
1870 EventCommand::Ptr command = EventCommand::GetByName(arguments[1]);
1873 BOOST_THROW_EXCEPTION(std::invalid_argument("Event command '" + arguments[1] + "' does not exist."));
1875 Log(LogNotice, "ExternalCommandProcessor")
1876 << "Changing event handler for host '" << arguments[0] << "' to '" << arguments[1] << "'";
1878 host->ModifyAttribute("event_command", command->GetName());
1882 void ExternalCommandProcessor::ChangeSvcEventHandler(double, const std::vector<String>& arguments)
1884 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1887 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change event handler for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
1889 if (arguments[2].IsEmpty()) {
1890 Log(LogNotice, "ExternalCommandProcessor")
1891 << "Unsetting event handler for service '" << arguments[1] << "'";
1893 service->ModifyAttribute("event_command", "");
1895 EventCommand::Ptr command = EventCommand::GetByName(arguments[2]);
1898 BOOST_THROW_EXCEPTION(std::invalid_argument("Event command '" + arguments[2] + "' does not exist."));
1900 Log(LogNotice, "ExternalCommandProcessor")
1901 << "Changing event handler for service '" << arguments[1] << "' to '" << arguments[2] << "'";
1903 service->ModifyAttribute("event_command", command->GetName());
1907 void ExternalCommandProcessor::ChangeHostCheckCommand(double, const std::vector<String>& arguments)
1909 Host::Ptr host = Host::GetByName(arguments[0]);
1912 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change check command for non-existent host '" + arguments[0] + "'"));
1914 CheckCommand::Ptr command = CheckCommand::GetByName(arguments[1]);
1917 BOOST_THROW_EXCEPTION(std::invalid_argument("Check command '" + arguments[1] + "' does not exist."));
1919 Log(LogNotice, "ExternalCommandProcessor")
1920 << "Changing check command for host '" << arguments[0] << "' to '" << arguments[1] << "'";
1922 host->ModifyAttribute("check_command", command->GetName());
1925 void ExternalCommandProcessor::ChangeSvcCheckCommand(double, const std::vector<String>& arguments)
1927 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1930 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change check command for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
1932 CheckCommand::Ptr command = CheckCommand::GetByName(arguments[2]);
1935 BOOST_THROW_EXCEPTION(std::invalid_argument("Check command '" + arguments[2] + "' does not exist."));
1937 Log(LogNotice, "ExternalCommandProcessor")
1938 << "Changing check command for service '" << arguments[1] << "' to '" << arguments[2] << "'";
1940 service->ModifyAttribute("check_command", command->GetName());
1943 void ExternalCommandProcessor::ChangeMaxHostCheckAttempts(double, const std::vector<String>& arguments)
1945 Host::Ptr host = Host::GetByName(arguments[0]);
1948 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change max check attempts for non-existent host '" + arguments[0] + "'"));
1950 int attempts = Convert::ToLong(arguments[1]);
1952 Log(LogNotice, "ExternalCommandProcessor")
1953 << "Changing max check attempts for host '" << arguments[0] << "' to '" << arguments[1] << "'";
1955 host->ModifyAttribute("max_check_attempts", attempts);
1958 void ExternalCommandProcessor::ChangeMaxSvcCheckAttempts(double, const std::vector<String>& arguments)
1960 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1963 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change max check attempts for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
1965 int attempts = Convert::ToLong(arguments[2]);
1967 Log(LogNotice, "ExternalCommandProcessor")
1968 << "Changing max check attempts for service '" << arguments[1] << "' to '" << arguments[2] << "'";
1970 service->ModifyAttribute("max_check_attempts", attempts);
1973 void ExternalCommandProcessor::ChangeHostCheckTimeperiod(double, const std::vector<String>& arguments)
1975 Host::Ptr host = Host::GetByName(arguments[0]);
1978 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change check period for non-existent host '" + arguments[0] + "'"));
1980 TimePeriod::Ptr tp = TimePeriod::GetByName(arguments[1]);
1983 BOOST_THROW_EXCEPTION(std::invalid_argument("Time period '" + arguments[1] + "' does not exist."));
1985 Log(LogNotice, "ExternalCommandProcessor")
1986 << "Changing check period for host '" << arguments[0] << "' to '" << arguments[1] << "'";
1988 host->ModifyAttribute("check_period", tp->GetName());
1991 void ExternalCommandProcessor::ChangeSvcCheckTimeperiod(double, const std::vector<String>& arguments)
1993 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1996 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change check period for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
1998 TimePeriod::Ptr tp = TimePeriod::GetByName(arguments[2]);
2001 BOOST_THROW_EXCEPTION(std::invalid_argument("Time period '" + arguments[2] + "' does not exist."));
2003 Log(LogNotice, "ExternalCommandProcessor")
2004 << "Changing check period for service '" << arguments[1] << "' to '" << arguments[2] << "'";
2006 service->ModifyAttribute("check_period", tp->GetName());
2009 void ExternalCommandProcessor::ChangeCustomHostVar(double, const std::vector<String>& arguments)
2011 Host::Ptr host = Host::GetByName(arguments[0]);
2014 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change custom var for non-existent host '" + arguments[0] + "'"));
2016 Log(LogNotice, "ExternalCommandProcessor")
2017 << "Changing custom var '" << arguments[1] << "' for host '" << arguments[0] << "' to value '" << arguments[2] << "'";
2019 host->ModifyAttribute("vars." + arguments[1], arguments[2]);
2022 void ExternalCommandProcessor::ChangeCustomSvcVar(double, const std::vector<String>& arguments)
2024 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
2027 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change custom var for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
2029 Log(LogNotice, "ExternalCommandProcessor")
2030 << "Changing custom var '" << arguments[2] << "' for service '" << arguments[1] << "' on host '"
2031 << arguments[0] << "' to value '" << arguments[3] << "'";
2033 service->ModifyAttribute("vars." + arguments[2], arguments[3]);
2036 void ExternalCommandProcessor::ChangeCustomUserVar(double, const std::vector<String>& arguments)
2038 User::Ptr user = User::GetByName(arguments[0]);
2041 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change custom var for non-existent user '" + arguments[0] + "'"));
2043 Log(LogNotice, "ExternalCommandProcessor")
2044 << "Changing custom var '" << arguments[1] << "' for user '" << arguments[0] << "' to value '" << arguments[2] << "'";
2046 user->ModifyAttribute("vars." + arguments[1], arguments[2]);
2049 void ExternalCommandProcessor::ChangeCustomCheckcommandVar(double, const std::vector<String>& arguments)
2051 CheckCommand::Ptr command = CheckCommand::GetByName(arguments[0]);
2054 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change custom var for non-existent command '" + arguments[0] + "'"));
2056 ChangeCustomCommandVarInternal(command, arguments[1], arguments[2]);
2059 void ExternalCommandProcessor::ChangeCustomEventcommandVar(double, const std::vector<String>& arguments)
2061 EventCommand::Ptr command = EventCommand::GetByName(arguments[0]);
2064 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change custom var for non-existent command '" + arguments[0] + "'"));
2066 ChangeCustomCommandVarInternal(command, arguments[1], arguments[2]);
2069 void ExternalCommandProcessor::ChangeCustomNotificationcommandVar(double, const std::vector<String>& arguments)
2071 NotificationCommand::Ptr command = NotificationCommand::GetByName(arguments[0]);
2074 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change custom var for non-existent command '" + arguments[0] + "'"));
2076 ChangeCustomCommandVarInternal(command, arguments[1], arguments[2]);
2079 void ExternalCommandProcessor::ChangeCustomCommandVarInternal(const Command::Ptr& command, const String& name, const Value& value)
2081 Log(LogNotice, "ExternalCommandProcessor")
2082 << "Changing custom var '" << name << "' for command '" << command->GetName() << "' to value '" << value << "'";
2084 command->ModifyAttribute("vars." + name, value);
2087 void ExternalCommandProcessor::EnableHostgroupHostNotifications(double, const std::vector<String>& arguments)
2089 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
2092 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable host notifications for non-existent hostgroup '" + arguments[0] + "'"));
2094 for (const Host::Ptr& host : hg->GetMembers()) {
2095 Log(LogNotice, "ExternalCommandProcessor")
2096 << "Enabling notifications for host '" << host->GetName() << "'";
2098 host->ModifyAttribute("enable_notifications", true);
2102 void ExternalCommandProcessor::EnableHostgroupSvcNotifications(double, const std::vector<String>& arguments)
2104 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
2107 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable service notifications for non-existent hostgroup '" + arguments[0] + "'"));
2109 for (const Host::Ptr& host : hg->GetMembers()) {
2110 for (const Service::Ptr& service : host->GetServices()) {
2111 Log(LogNotice, "ExternalCommandProcessor")
2112 << "Enabling notifications for service '" << service->GetName() << "'";
2114 service->ModifyAttribute("enable_notifications", true);
2119 void ExternalCommandProcessor::DisableHostgroupHostNotifications(double, const std::vector<String>& arguments)
2121 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
2124 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable host notifications for non-existent hostgroup '" + arguments[0] + "'"));
2126 for (const Host::Ptr& host : hg->GetMembers()) {
2127 Log(LogNotice, "ExternalCommandProcessor")
2128 << "Disabling notifications for host '" << host->GetName() << "'";
2130 host->ModifyAttribute("enable_notifications", false);
2134 void ExternalCommandProcessor::DisableHostgroupSvcNotifications(double, const std::vector<String>& arguments)
2136 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
2139 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable service notifications for non-existent hostgroup '" + arguments[0] + "'"));
2141 for (const Host::Ptr& host : hg->GetMembers()) {
2142 for (const Service::Ptr& service : host->GetServices()) {
2143 Log(LogNotice, "ExternalCommandProcessor")
2144 << "Disabling notifications for service '" << service->GetName() << "'";
2146 service->ModifyAttribute("enable_notifications", false);
2151 void ExternalCommandProcessor::EnableServicegroupHostNotifications(double, const std::vector<String>& arguments)
2153 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
2156 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable host notifications for non-existent servicegroup '" + arguments[0] + "'"));
2158 for (const Service::Ptr& service : sg->GetMembers()) {
2159 Host::Ptr host = service->GetHost();
2161 Log(LogNotice, "ExternalCommandProcessor")
2162 << "Enabling notifications for host '" << host->GetName() << "'";
2164 host->ModifyAttribute("enable_notifications", true);
2168 void ExternalCommandProcessor::EnableServicegroupSvcNotifications(double, const std::vector<String>& arguments)
2170 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
2173 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable service notifications for non-existent servicegroup '" + arguments[0] + "'"));
2175 for (const Service::Ptr& service : sg->GetMembers()) {
2176 Log(LogNotice, "ExternalCommandProcessor")
2177 << "Enabling notifications for service '" << service->GetName() << "'";
2179 service->ModifyAttribute("enable_notifications", true);
2183 void ExternalCommandProcessor::DisableServicegroupHostNotifications(double, const std::vector<String>& arguments)
2185 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
2188 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable host notifications for non-existent servicegroup '" + arguments[0] + "'"));
2190 for (const Service::Ptr& service : sg->GetMembers()) {
2191 Host::Ptr host = service->GetHost();
2193 Log(LogNotice, "ExternalCommandProcessor")
2194 << "Disabling notifications for host '" << host->GetName() << "'";
2196 host->ModifyAttribute("enable_notifications", false);
2200 void ExternalCommandProcessor::DisableServicegroupSvcNotifications(double, const std::vector<String>& arguments)
2202 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
2205 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable service notifications for non-existent servicegroup '" + arguments[0] + "'"));
2207 for (const Service::Ptr& service : sg->GetMembers()) {
2208 Log(LogNotice, "ExternalCommandProcessor")
2209 << "Disabling notifications for service '" << service->GetName() << "'";
2211 service->ModifyAttribute("enable_notifications", false);
2215 boost::mutex& ExternalCommandProcessor::GetMutex()
2217 static boost::mutex mtx;
2221 std::map<String, ExternalCommandInfo>& ExternalCommandProcessor::GetCommands()
2223 static std::map<String, ExternalCommandInfo> commands;