1 /******************************************************************************
3 * Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/) *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License *
7 * as published by the Free Software Foundation; either version 2 *
8 * of the License, or (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software Foundation *
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ******************************************************************************/
20 #include "icinga/externalcommandprocessor.hpp"
21 #include "icinga/host.hpp"
22 #include "icinga/service.hpp"
23 #include "icinga/user.hpp"
24 #include "icinga/hostgroup.hpp"
25 #include "icinga/servicegroup.hpp"
26 #include "icinga/pluginutility.hpp"
27 #include "icinga/icingaapplication.hpp"
28 #include "icinga/checkcommand.hpp"
29 #include "icinga/eventcommand.hpp"
30 #include "icinga/notificationcommand.hpp"
31 #include "icinga/compatutility.hpp"
32 #include "remote/apifunction.hpp"
33 #include "base/convert.hpp"
34 #include "base/logger.hpp"
35 #include "base/objectlock.hpp"
36 #include "base/application.hpp"
37 #include "base/utility.hpp"
38 #include "base/exception.hpp"
40 #include <boost/thread/once.hpp>
42 using namespace icinga;
44 boost::signals2::signal<void(double, const String&, const std::vector<String>&)> ExternalCommandProcessor::OnNewExternalCommand;
46 void ExternalCommandProcessor::Execute(const String& line)
52 BOOST_THROW_EXCEPTION(std::invalid_argument("Missing timestamp in command: " + line));
54 size_t pos = line.FindFirstOf("]");
56 if (pos == String::NPos)
57 BOOST_THROW_EXCEPTION(std::invalid_argument("Missing timestamp in command: " + line));
59 String timestamp = line.SubStr(1, pos - 1);
60 String args = line.SubStr(pos + 2, String::NPos);
62 double ts = Convert::ToDouble(timestamp);
65 BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid timestamp in command: " + line));
67 std::vector<String> argv = args.Split(";");
70 BOOST_THROW_EXCEPTION(std::invalid_argument("Missing arguments in command: " + line));
72 std::vector<String> argvExtra(argv.begin() + 1, argv.end());
73 Execute(ts, argv[0], argvExtra);
76 void ExternalCommandProcessor::Execute(double time, const String& command, const std::vector<String>& arguments)
78 ExternalCommandInfo eci;
80 static boost::once_flag once = BOOST_ONCE_INIT;
82 boost::call_once(once, []() {
87 boost::mutex::scoped_lock lock(GetMutex());
89 auto it = GetCommands().find(command);
91 if (it == GetCommands().end())
92 BOOST_THROW_EXCEPTION(std::invalid_argument("The external command '" + command + "' does not exist."));
97 if (arguments.size() < eci.MinArgs)
98 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected " + Convert::ToString(eci.MinArgs) + " arguments"));
100 size_t argnum = std::min(arguments.size(), eci.MaxArgs);
102 std::vector<String> realArguments;
103 realArguments.resize(argnum);
106 std::copy(arguments.begin(), arguments.begin() + argnum - 1, realArguments.begin());
108 String last_argument;
109 for (std::vector<String>::size_type i = argnum - 1; i < arguments.size(); i++) {
110 if (!last_argument.IsEmpty())
111 last_argument += ";";
113 last_argument += arguments[i];
116 realArguments[argnum - 1] = last_argument;
119 OnNewExternalCommand(time, command, realArguments);
121 eci.Callback(time, realArguments);
124 void ExternalCommandProcessor::RegisterCommand(const String& command, const ExternalCommandCallback& callback, size_t minArgs, size_t maxArgs)
126 boost::mutex::scoped_lock lock(GetMutex());
127 ExternalCommandInfo eci;
128 eci.Callback = callback;
129 eci.MinArgs = minArgs;
130 eci.MaxArgs = (maxArgs == UINT_MAX) ? minArgs : maxArgs;
131 GetCommands()[command] = eci;
134 void ExternalCommandProcessor::RegisterCommands()
136 RegisterCommand("PROCESS_HOST_CHECK_RESULT", &ExternalCommandProcessor::ProcessHostCheckResult, 3);
137 RegisterCommand("PROCESS_SERVICE_CHECK_RESULT", &ExternalCommandProcessor::ProcessServiceCheckResult, 4);
138 RegisterCommand("SCHEDULE_HOST_CHECK", &ExternalCommandProcessor::ScheduleHostCheck, 2);
139 RegisterCommand("SCHEDULE_FORCED_HOST_CHECK", &ExternalCommandProcessor::ScheduleForcedHostCheck, 2);
140 RegisterCommand("SCHEDULE_SVC_CHECK", &ExternalCommandProcessor::ScheduleSvcCheck, 3);
141 RegisterCommand("SCHEDULE_FORCED_SVC_CHECK", &ExternalCommandProcessor::ScheduleForcedSvcCheck, 3);
142 RegisterCommand("ENABLE_HOST_CHECK", &ExternalCommandProcessor::EnableHostCheck, 1);
143 RegisterCommand("DISABLE_HOST_CHECK", &ExternalCommandProcessor::DisableHostCheck, 1);
144 RegisterCommand("ENABLE_SVC_CHECK", &ExternalCommandProcessor::EnableSvcCheck, 2);
145 RegisterCommand("DISABLE_SVC_CHECK", &ExternalCommandProcessor::DisableSvcCheck, 2);
146 RegisterCommand("SHUTDOWN_PROCESS", &ExternalCommandProcessor::ShutdownProcess);
147 RegisterCommand("RESTART_PROCESS", &ExternalCommandProcessor::RestartProcess);
148 RegisterCommand("SCHEDULE_FORCED_HOST_SVC_CHECKS", &ExternalCommandProcessor::ScheduleForcedHostSvcChecks, 2);
149 RegisterCommand("SCHEDULE_HOST_SVC_CHECKS", &ExternalCommandProcessor::ScheduleHostSvcChecks, 2);
150 RegisterCommand("ENABLE_HOST_SVC_CHECKS", &ExternalCommandProcessor::EnableHostSvcChecks, 1);
151 RegisterCommand("DISABLE_HOST_SVC_CHECKS", &ExternalCommandProcessor::DisableHostSvcChecks, 1);
152 RegisterCommand("ACKNOWLEDGE_SVC_PROBLEM", &ExternalCommandProcessor::AcknowledgeSvcProblem, 7);
153 RegisterCommand("ACKNOWLEDGE_SVC_PROBLEM_EXPIRE", &ExternalCommandProcessor::AcknowledgeSvcProblemExpire, 8);
154 RegisterCommand("REMOVE_SVC_ACKNOWLEDGEMENT", &ExternalCommandProcessor::RemoveSvcAcknowledgement, 2);
155 RegisterCommand("ACKNOWLEDGE_HOST_PROBLEM", &ExternalCommandProcessor::AcknowledgeHostProblem, 6);
156 RegisterCommand("ACKNOWLEDGE_HOST_PROBLEM_EXPIRE", &ExternalCommandProcessor::AcknowledgeHostProblemExpire, 7);
157 RegisterCommand("REMOVE_HOST_ACKNOWLEDGEMENT", &ExternalCommandProcessor::RemoveHostAcknowledgement, 1);
158 RegisterCommand("DISABLE_HOST_FLAP_DETECTION", &ExternalCommandProcessor::DisableHostFlapping, 1);
159 RegisterCommand("ENABLE_HOST_FLAP_DETECTION", &ExternalCommandProcessor::EnableHostFlapping, 1);
160 RegisterCommand("DISABLE_SVC_FLAP_DETECTION", &ExternalCommandProcessor::DisableSvcFlapping, 2);
161 RegisterCommand("ENABLE_SVC_FLAP_DETECTION", &ExternalCommandProcessor::EnableSvcFlapping, 2);
162 RegisterCommand("ENABLE_HOSTGROUP_SVC_CHECKS", &ExternalCommandProcessor::EnableHostgroupSvcChecks, 1);
163 RegisterCommand("DISABLE_HOSTGROUP_SVC_CHECKS", &ExternalCommandProcessor::DisableHostgroupSvcChecks, 1);
164 RegisterCommand("ENABLE_SERVICEGROUP_SVC_CHECKS", &ExternalCommandProcessor::EnableServicegroupSvcChecks, 1);
165 RegisterCommand("DISABLE_SERVICEGROUP_SVC_CHECKS", &ExternalCommandProcessor::DisableServicegroupSvcChecks, 1);
166 RegisterCommand("ENABLE_PASSIVE_HOST_CHECKS", &ExternalCommandProcessor::EnablePassiveHostChecks, 1);
167 RegisterCommand("DISABLE_PASSIVE_HOST_CHECKS", &ExternalCommandProcessor::DisablePassiveHostChecks, 1);
168 RegisterCommand("ENABLE_PASSIVE_SVC_CHECKS", &ExternalCommandProcessor::EnablePassiveSvcChecks, 2);
169 RegisterCommand("DISABLE_PASSIVE_SVC_CHECKS", &ExternalCommandProcessor::DisablePassiveSvcChecks, 2);
170 RegisterCommand("ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS", &ExternalCommandProcessor::EnableServicegroupPassiveSvcChecks, 1);
171 RegisterCommand("DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS", &ExternalCommandProcessor::DisableServicegroupPassiveSvcChecks, 1);
172 RegisterCommand("ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS", &ExternalCommandProcessor::EnableHostgroupPassiveSvcChecks, 1);
173 RegisterCommand("DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS", &ExternalCommandProcessor::DisableHostgroupPassiveSvcChecks, 1);
174 RegisterCommand("PROCESS_FILE", &ExternalCommandProcessor::ProcessFile, 2);
175 RegisterCommand("SCHEDULE_SVC_DOWNTIME", &ExternalCommandProcessor::ScheduleSvcDowntime, 9);
176 RegisterCommand("DEL_SVC_DOWNTIME", &ExternalCommandProcessor::DelSvcDowntime, 1);
177 RegisterCommand("SCHEDULE_HOST_DOWNTIME", &ExternalCommandProcessor::ScheduleHostDowntime, 8);
178 RegisterCommand("SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME", &ExternalCommandProcessor::ScheduleAndPropagateHostDowntime, 8);
179 RegisterCommand("SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME", &ExternalCommandProcessor::ScheduleAndPropagateTriggeredHostDowntime, 8);
180 RegisterCommand("DEL_HOST_DOWNTIME", &ExternalCommandProcessor::DelHostDowntime, 1);
181 RegisterCommand("DEL_DOWNTIME_BY_HOST_NAME", &ExternalCommandProcessor::DelDowntimeByHostName, 1, 4);
182 RegisterCommand("SCHEDULE_HOST_SVC_DOWNTIME", &ExternalCommandProcessor::ScheduleHostSvcDowntime, 8);
183 RegisterCommand("SCHEDULE_HOSTGROUP_HOST_DOWNTIME", &ExternalCommandProcessor::ScheduleHostgroupHostDowntime, 8);
184 RegisterCommand("SCHEDULE_HOSTGROUP_SVC_DOWNTIME", &ExternalCommandProcessor::ScheduleHostgroupSvcDowntime, 8);
185 RegisterCommand("SCHEDULE_SERVICEGROUP_HOST_DOWNTIME", &ExternalCommandProcessor::ScheduleServicegroupHostDowntime, 8);
186 RegisterCommand("SCHEDULE_SERVICEGROUP_SVC_DOWNTIME", &ExternalCommandProcessor::ScheduleServicegroupSvcDowntime, 8);
187 RegisterCommand("ADD_HOST_COMMENT", &ExternalCommandProcessor::AddHostComment, 4);
188 RegisterCommand("DEL_HOST_COMMENT", &ExternalCommandProcessor::DelHostComment, 1);
189 RegisterCommand("ADD_SVC_COMMENT", &ExternalCommandProcessor::AddSvcComment, 5);
190 RegisterCommand("DEL_SVC_COMMENT", &ExternalCommandProcessor::DelSvcComment, 1);
191 RegisterCommand("DEL_ALL_HOST_COMMENTS", &ExternalCommandProcessor::DelAllHostComments, 1);
192 RegisterCommand("DEL_ALL_SVC_COMMENTS", &ExternalCommandProcessor::DelAllSvcComments, 2);
193 RegisterCommand("SEND_CUSTOM_HOST_NOTIFICATION", &ExternalCommandProcessor::SendCustomHostNotification, 4);
194 RegisterCommand("SEND_CUSTOM_SVC_NOTIFICATION", &ExternalCommandProcessor::SendCustomSvcNotification, 5);
195 RegisterCommand("DELAY_HOST_NOTIFICATION", &ExternalCommandProcessor::DelayHostNotification, 2);
196 RegisterCommand("DELAY_SVC_NOTIFICATION", &ExternalCommandProcessor::DelaySvcNotification, 3);
197 RegisterCommand("ENABLE_HOST_NOTIFICATIONS", &ExternalCommandProcessor::EnableHostNotifications, 1);
198 RegisterCommand("DISABLE_HOST_NOTIFICATIONS", &ExternalCommandProcessor::DisableHostNotifications, 1);
199 RegisterCommand("ENABLE_SVC_NOTIFICATIONS", &ExternalCommandProcessor::EnableSvcNotifications, 2);
200 RegisterCommand("DISABLE_SVC_NOTIFICATIONS", &ExternalCommandProcessor::DisableSvcNotifications, 2);
201 RegisterCommand("ENABLE_HOST_SVC_NOTIFICATIONS", &ExternalCommandProcessor::EnableHostSvcNotifications, 1);
202 RegisterCommand("DISABLE_HOST_SVC_NOTIFICATIONS", &ExternalCommandProcessor::DisableHostSvcNotifications, 1);
203 RegisterCommand("DISABLE_HOSTGROUP_HOST_CHECKS", &ExternalCommandProcessor::DisableHostgroupHostChecks, 1);
204 RegisterCommand("DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS", &ExternalCommandProcessor::DisableHostgroupPassiveHostChecks, 1);
205 RegisterCommand("DISABLE_SERVICEGROUP_HOST_CHECKS", &ExternalCommandProcessor::DisableServicegroupHostChecks, 1);
206 RegisterCommand("DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS", &ExternalCommandProcessor::DisableServicegroupPassiveHostChecks, 1);
207 RegisterCommand("ENABLE_HOSTGROUP_HOST_CHECKS", &ExternalCommandProcessor::EnableHostgroupHostChecks, 1);
208 RegisterCommand("ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS", &ExternalCommandProcessor::EnableHostgroupPassiveHostChecks, 1);
209 RegisterCommand("ENABLE_SERVICEGROUP_HOST_CHECKS", &ExternalCommandProcessor::EnableServicegroupHostChecks, 1);
210 RegisterCommand("ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS", &ExternalCommandProcessor::EnableServicegroupPassiveHostChecks, 1);
211 RegisterCommand("ENABLE_NOTIFICATIONS", &ExternalCommandProcessor::EnableNotifications);
212 RegisterCommand("DISABLE_NOTIFICATIONS", &ExternalCommandProcessor::DisableNotifications);
213 RegisterCommand("ENABLE_FLAP_DETECTION", &ExternalCommandProcessor::EnableFlapDetection);
214 RegisterCommand("DISABLE_FLAP_DETECTION", &ExternalCommandProcessor::DisableFlapDetection);
215 RegisterCommand("ENABLE_EVENT_HANDLERS", &ExternalCommandProcessor::EnableEventHandlers);
216 RegisterCommand("DISABLE_EVENT_HANDLERS", &ExternalCommandProcessor::DisableEventHandlers);
217 RegisterCommand("ENABLE_PERFORMANCE_DATA", &ExternalCommandProcessor::EnablePerformanceData);
218 RegisterCommand("DISABLE_PERFORMANCE_DATA", &ExternalCommandProcessor::DisablePerformanceData);
219 RegisterCommand("START_EXECUTING_SVC_CHECKS", &ExternalCommandProcessor::StartExecutingSvcChecks);
220 RegisterCommand("STOP_EXECUTING_SVC_CHECKS", &ExternalCommandProcessor::StopExecutingSvcChecks);
221 RegisterCommand("START_EXECUTING_HOST_CHECKS", &ExternalCommandProcessor::StartExecutingHostChecks);
222 RegisterCommand("STOP_EXECUTING_HOST_CHECKS", &ExternalCommandProcessor::StopExecutingHostChecks);
223 RegisterCommand("CHANGE_NORMAL_SVC_CHECK_INTERVAL", &ExternalCommandProcessor::ChangeNormalSvcCheckInterval, 3);
224 RegisterCommand("CHANGE_NORMAL_HOST_CHECK_INTERVAL", &ExternalCommandProcessor::ChangeNormalHostCheckInterval, 2);
225 RegisterCommand("CHANGE_RETRY_SVC_CHECK_INTERVAL", &ExternalCommandProcessor::ChangeRetrySvcCheckInterval, 3);
226 RegisterCommand("CHANGE_RETRY_HOST_CHECK_INTERVAL", &ExternalCommandProcessor::ChangeRetryHostCheckInterval, 2);
227 RegisterCommand("ENABLE_HOST_EVENT_HANDLER", &ExternalCommandProcessor::EnableHostEventHandler, 1);
228 RegisterCommand("DISABLE_HOST_EVENT_HANDLER", &ExternalCommandProcessor::DisableHostEventHandler, 1);
229 RegisterCommand("ENABLE_SVC_EVENT_HANDLER", &ExternalCommandProcessor::EnableSvcEventHandler, 2);
230 RegisterCommand("DISABLE_SVC_EVENT_HANDLER", &ExternalCommandProcessor::DisableSvcEventHandler, 2);
231 RegisterCommand("CHANGE_HOST_EVENT_HANDLER", &ExternalCommandProcessor::ChangeHostEventHandler, 2);
232 RegisterCommand("CHANGE_SVC_EVENT_HANDLER", &ExternalCommandProcessor::ChangeSvcEventHandler, 3);
233 RegisterCommand("CHANGE_HOST_CHECK_COMMAND", &ExternalCommandProcessor::ChangeHostCheckCommand, 2);
234 RegisterCommand("CHANGE_SVC_CHECK_COMMAND", &ExternalCommandProcessor::ChangeSvcCheckCommand, 3);
235 RegisterCommand("CHANGE_MAX_HOST_CHECK_ATTEMPTS", &ExternalCommandProcessor::ChangeMaxHostCheckAttempts, 2);
236 RegisterCommand("CHANGE_MAX_SVC_CHECK_ATTEMPTS", &ExternalCommandProcessor::ChangeMaxSvcCheckAttempts, 3);
237 RegisterCommand("CHANGE_HOST_CHECK_TIMEPERIOD", &ExternalCommandProcessor::ChangeHostCheckTimeperiod, 2);
238 RegisterCommand("CHANGE_SVC_CHECK_TIMEPERIOD", &ExternalCommandProcessor::ChangeSvcCheckTimeperiod, 3);
239 RegisterCommand("CHANGE_CUSTOM_HOST_VAR", &ExternalCommandProcessor::ChangeCustomHostVar, 3);
240 RegisterCommand("CHANGE_CUSTOM_SVC_VAR", &ExternalCommandProcessor::ChangeCustomSvcVar, 4);
241 RegisterCommand("CHANGE_CUSTOM_USER_VAR", &ExternalCommandProcessor::ChangeCustomUserVar, 3);
242 RegisterCommand("CHANGE_CUSTOM_CHECKCOMMAND_VAR", &ExternalCommandProcessor::ChangeCustomCheckcommandVar, 3);
243 RegisterCommand("CHANGE_CUSTOM_EVENTCOMMAND_VAR", &ExternalCommandProcessor::ChangeCustomEventcommandVar, 3);
244 RegisterCommand("CHANGE_CUSTOM_NOTIFICATIONCOMMAND_VAR", &ExternalCommandProcessor::ChangeCustomNotificationcommandVar, 3);
246 RegisterCommand("ENABLE_HOSTGROUP_HOST_NOTIFICATIONS", &ExternalCommandProcessor::EnableHostgroupHostNotifications, 1);
247 RegisterCommand("ENABLE_HOSTGROUP_SVC_NOTIFICATIONS", &ExternalCommandProcessor::EnableHostgroupSvcNotifications, 1);
248 RegisterCommand("DISABLE_HOSTGROUP_HOST_NOTIFICATIONS", &ExternalCommandProcessor::DisableHostgroupHostNotifications, 1);
249 RegisterCommand("DISABLE_HOSTGROUP_SVC_NOTIFICATIONS", &ExternalCommandProcessor::DisableHostgroupSvcNotifications, 1);
250 RegisterCommand("ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS", &ExternalCommandProcessor::EnableServicegroupHostNotifications, 1);
251 RegisterCommand("DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS", &ExternalCommandProcessor::DisableServicegroupHostNotifications, 1);
252 RegisterCommand("ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS", &ExternalCommandProcessor::EnableServicegroupSvcNotifications, 1);
253 RegisterCommand("DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS", &ExternalCommandProcessor::DisableServicegroupSvcNotifications, 1);
256 void ExternalCommandProcessor::ExecuteFromFile(const String& line, std::deque< std::vector<String> >& file_queue)
262 BOOST_THROW_EXCEPTION(std::invalid_argument("Missing timestamp in command: " + line));
264 size_t pos = line.FindFirstOf("]");
266 if (pos == String::NPos)
267 BOOST_THROW_EXCEPTION(std::invalid_argument("Missing timestamp in command: " + line));
269 String timestamp = line.SubStr(1, pos - 1);
270 String args = line.SubStr(pos + 2, String::NPos);
272 double ts = Convert::ToDouble(timestamp);
275 BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid timestamp in command: " + line));
277 std::vector<String> argv = args.Split(";");
280 BOOST_THROW_EXCEPTION(std::invalid_argument("Missing arguments in command: " + line));
282 std::vector<String> argvExtra(argv.begin() + 1, argv.end());
284 if (argv[0] == "PROCESS_FILE") {
285 Log(LogDebug, "ExternalCommandProcessor")
286 << "Enqueing external command file " << argvExtra[0];
287 file_queue.push_back(argvExtra);
289 Execute(ts, argv[0], argvExtra);
293 void ExternalCommandProcessor::ProcessHostCheckResult(double time, const std::vector<String>& arguments)
295 Host::Ptr host = Host::GetByName(arguments[0]);
298 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot process passive host check result for non-existent host '" + arguments[0] + "'"));
300 if (!host->GetEnablePassiveChecks())
301 BOOST_THROW_EXCEPTION(std::invalid_argument("Got passive check result for host '" + arguments[0] + "' which has passive checks disabled."));
303 int exitStatus = Convert::ToDouble(arguments[1]);
304 CheckResult::Ptr result = new CheckResult();
305 std::pair<String, String> co = PluginUtility::ParseCheckOutput(arguments[2]);
306 result->SetOutput(co.first);
307 result->SetPerformanceData(PluginUtility::SplitPerfdata(co.second));
313 else if (exitStatus == 1)
314 state = ServiceCritical;
316 BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid status code: " + arguments[1]));
318 result->SetState(state);
320 result->SetScheduleStart(time);
321 result->SetScheduleEnd(time);
322 result->SetExecutionStart(time);
323 result->SetExecutionEnd(time);
325 /* Mark this check result as passive. */
326 result->SetActive(false);
328 Log(LogNotice, "ExternalCommandProcessor")
329 << "Processing passive check result for host '" << arguments[0] << "'";
331 host->ProcessCheckResult(result);
334 void ExternalCommandProcessor::ProcessServiceCheckResult(double time, const std::vector<String>& arguments)
336 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
339 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot process passive service check result for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
341 if (!service->GetEnablePassiveChecks())
342 BOOST_THROW_EXCEPTION(std::invalid_argument("Got passive check result for service '" + arguments[1] + "' which has passive checks disabled."));
344 int exitStatus = Convert::ToDouble(arguments[2]);
345 CheckResult::Ptr result = new CheckResult();
346 String output = CompatUtility::UnEscapeString(arguments[3]);
347 std::pair<String, String> co = PluginUtility::ParseCheckOutput(output);
348 result->SetOutput(co.first);
349 result->SetPerformanceData(PluginUtility::SplitPerfdata(co.second));
350 result->SetState(PluginUtility::ExitStatusToState(exitStatus));
352 result->SetScheduleStart(time);
353 result->SetScheduleEnd(time);
354 result->SetExecutionStart(time);
355 result->SetExecutionEnd(time);
357 /* Mark this check result as passive. */
358 result->SetActive(false);
360 Log(LogNotice, "ExternalCommandProcessor")
361 << "Processing passive check result for service '" << arguments[1] << "'";
363 service->ProcessCheckResult(result);
366 void ExternalCommandProcessor::ScheduleHostCheck(double, const std::vector<String>& arguments)
368 Host::Ptr host = Host::GetByName(arguments[0]);
371 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot reschedule host check for non-existent host '" + arguments[0] + "'"));
373 double planned_check = Convert::ToDouble(arguments[1]);
375 if (planned_check > host->GetNextCheck()) {
376 Log(LogNotice, "ExternalCommandProcessor")
377 << "Ignoring reschedule request for host '"
378 << arguments[0] << "' (next check is already sooner than requested check time)";
382 Log(LogNotice, "ExternalCommandProcessor")
383 << "Rescheduling next check for host '" << arguments[0] << "'";
385 if (planned_check < Utility::GetTime())
386 planned_check = Utility::GetTime();
388 host->SetNextCheck(planned_check);
390 /* trigger update event for DB IDO */
391 Checkable::OnNextCheckUpdated(host);
394 void ExternalCommandProcessor::ScheduleForcedHostCheck(double, const std::vector<String>& arguments)
396 Host::Ptr host = Host::GetByName(arguments[0]);
399 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot reschedule forced host check for non-existent host '" + arguments[0] + "'"));
401 Log(LogNotice, "ExternalCommandProcessor")
402 << "Rescheduling next check for host '" << arguments[0] << "'";
404 host->SetForceNextCheck(true);
405 host->SetNextCheck(Convert::ToDouble(arguments[1]));
407 /* trigger update event for DB IDO */
408 Checkable::OnNextCheckUpdated(host);
411 void ExternalCommandProcessor::ScheduleSvcCheck(double, const std::vector<String>& arguments)
413 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
416 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot reschedule service check for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
418 double planned_check = Convert::ToDouble(arguments[2]);
420 if (planned_check > service->GetNextCheck()) {
421 Log(LogNotice, "ExternalCommandProcessor")
422 << "Ignoring reschedule request for service '"
423 << arguments[1] << "' (next check is already sooner than requested check time)";
427 Log(LogNotice, "ExternalCommandProcessor")
428 << "Rescheduling next check for service '" << arguments[1] << "'";
430 if (planned_check < Utility::GetTime())
431 planned_check = Utility::GetTime();
433 service->SetNextCheck(planned_check);
435 /* trigger update event for DB IDO */
436 Checkable::OnNextCheckUpdated(service);
439 void ExternalCommandProcessor::ScheduleForcedSvcCheck(double, const std::vector<String>& arguments)
441 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
444 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot reschedule forced service check for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
446 Log(LogNotice, "ExternalCommandProcessor")
447 << "Rescheduling next check for service '" << arguments[1] << "'";
449 service->SetForceNextCheck(true);
450 service->SetNextCheck(Convert::ToDouble(arguments[2]));
452 /* trigger update event for DB IDO */
453 Checkable::OnNextCheckUpdated(service);
456 void ExternalCommandProcessor::EnableHostCheck(double, const std::vector<String>& arguments)
458 Host::Ptr host = Host::GetByName(arguments[0]);
461 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable host checks for non-existent host '" + arguments[0] + "'"));
463 Log(LogNotice, "ExternalCommandProcessor")
464 << "Enabling active checks for host '" << arguments[0] << "'";
466 host->ModifyAttribute("enable_active_checks", true);
469 void ExternalCommandProcessor::DisableHostCheck(double, const std::vector<String>& arguments)
471 Host::Ptr host = Host::GetByName(arguments[0]);
474 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable host check non-existent host '" + arguments[0] + "'"));
476 Log(LogNotice, "ExternalCommandProcessor")
477 << "Disabling active checks for host '" << arguments[0] << "'";
479 host->ModifyAttribute("enable_active_checks", false);
482 void ExternalCommandProcessor::EnableSvcCheck(double, const std::vector<String>& arguments)
484 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
487 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable service check for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
489 Log(LogNotice, "ExternalCommandProcessor")
490 << "Enabling active checks for service '" << arguments[1] << "'";
492 service->ModifyAttribute("enable_active_checks", true);
495 void ExternalCommandProcessor::DisableSvcCheck(double, const std::vector<String>& arguments)
497 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
500 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable service check for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
502 Log(LogNotice, "ExternalCommandProcessor")
503 << "Disabling active checks for service '" << arguments[1] << "'";
505 service->ModifyAttribute("enable_active_checks", false);
508 void ExternalCommandProcessor::ShutdownProcess(double, const std::vector<String>&)
510 Log(LogNotice, "ExternalCommandProcessor", "Shutting down Icinga via external command.");
511 Application::RequestShutdown();
514 void ExternalCommandProcessor::RestartProcess(double, const std::vector<String>&)
516 Log(LogNotice, "ExternalCommandProcessor", "Restarting Icinga via external command.");
517 Application::RequestRestart();
520 void ExternalCommandProcessor::ScheduleForcedHostSvcChecks(double, const std::vector<String>& arguments)
522 double planned_check = Convert::ToDouble(arguments[1]);
524 Host::Ptr host = Host::GetByName(arguments[0]);
527 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot reschedule forced host service checks for non-existent host '" + arguments[0] + "'"));
529 for (const Service::Ptr& service : host->GetServices()) {
530 Log(LogNotice, "ExternalCommandProcessor")
531 << "Rescheduling next check for service '" << service->GetName() << "'";
533 service->SetNextCheck(planned_check);
534 service->SetForceNextCheck(true);
536 /* trigger update event for DB IDO */
537 Checkable::OnNextCheckUpdated(service);
541 void ExternalCommandProcessor::ScheduleHostSvcChecks(double, const std::vector<String>& arguments)
543 double planned_check = Convert::ToDouble(arguments[1]);
545 Host::Ptr host = Host::GetByName(arguments[0]);
548 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot reschedule host service checks for non-existent host '" + arguments[0] + "'"));
550 if (planned_check < Utility::GetTime())
551 planned_check = Utility::GetTime();
553 for (const Service::Ptr& service : host->GetServices()) {
554 if (planned_check > service->GetNextCheck()) {
555 Log(LogNotice, "ExternalCommandProcessor")
556 << "Ignoring reschedule request for service '"
557 << service->GetName() << "' (next check is already sooner than requested check time)";
561 Log(LogNotice, "ExternalCommandProcessor")
562 << "Rescheduling next check for service '" << service->GetName() << "'";
564 service->SetNextCheck(planned_check);
566 /* trigger update event for DB IDO */
567 Checkable::OnNextCheckUpdated(service);
571 void ExternalCommandProcessor::EnableHostSvcChecks(double, const std::vector<String>& arguments)
573 Host::Ptr host = Host::GetByName(arguments[0]);
576 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable host service checks for non-existent host '" + arguments[0] + "'"));
578 for (const Service::Ptr& service : host->GetServices()) {
579 Log(LogNotice, "ExternalCommandProcessor")
580 << "Enabling active checks for service '" << service->GetName() << "'";
582 service->ModifyAttribute("enable_active_checks", true);
586 void ExternalCommandProcessor::DisableHostSvcChecks(double, const std::vector<String>& arguments)
588 Host::Ptr host = Host::GetByName(arguments[0]);
591 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable host service checks for non-existent host '" + arguments[0] + "'"));
593 for (const Service::Ptr& service : host->GetServices()) {
594 Log(LogNotice, "ExternalCommandProcessor")
595 << "Disabling active checks for service '" << service->GetName() << "'";
597 service->ModifyAttribute("enable_active_checks", false);
601 void ExternalCommandProcessor::AcknowledgeSvcProblem(double, const std::vector<String>& arguments)
603 bool sticky = (Convert::ToLong(arguments[2]) == 2 ? true : false);
604 bool notify = (Convert::ToLong(arguments[3]) > 0 ? true : false);
605 bool persistent = (Convert::ToLong(arguments[4]) > 0 ? true : false);
607 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
610 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot acknowledge service problem for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
612 if (service->GetState() == ServiceOK)
613 BOOST_THROW_EXCEPTION(std::invalid_argument("The service '" + arguments[1] + "' is OK."));
615 Log(LogNotice, "ExternalCommandProcessor")
616 << "Setting acknowledgement for service '" << service->GetName() << "'" << (notify ? "" : ". Disabled notification");
618 Comment::AddComment(service, CommentAcknowledgement, arguments[5], arguments[6], persistent, 0);
619 service->AcknowledgeProblem(arguments[5], arguments[6], sticky ? AcknowledgementSticky : AcknowledgementNormal, notify, persistent);
622 void ExternalCommandProcessor::AcknowledgeSvcProblemExpire(double, const std::vector<String>& arguments)
624 bool sticky = (Convert::ToLong(arguments[2]) == 2 ? true : false);
625 bool notify = (Convert::ToLong(arguments[3]) > 0 ? true : false);
626 bool persistent = (Convert::ToLong(arguments[4]) > 0 ? true : false);
627 double timestamp = Convert::ToDouble(arguments[5]);
629 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
632 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot acknowledge service problem with expire time for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
634 if (service->GetState() == ServiceOK)
635 BOOST_THROW_EXCEPTION(std::invalid_argument("The service '" + arguments[1] + "' is OK."));
637 if (timestamp != 0 && timestamp <= Utility::GetTime())
638 BOOST_THROW_EXCEPTION(std::invalid_argument("Acknowledgement expire time must be in the future for service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
640 Log(LogNotice, "ExternalCommandProcessor")
641 << "Setting timed acknowledgement for service '" << service->GetName() << "'" << (notify ? "" : ". Disabled notification");
643 Comment::AddComment(service, CommentAcknowledgement, arguments[6], arguments[7], persistent, timestamp);
644 service->AcknowledgeProblem(arguments[6], arguments[7], sticky ? AcknowledgementSticky : AcknowledgementNormal, notify, persistent, timestamp);
647 void ExternalCommandProcessor::RemoveSvcAcknowledgement(double, const std::vector<String>& arguments)
649 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
652 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot remove service acknowledgement for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
654 Log(LogNotice, "ExternalCommandProcessor")
655 << "Removing acknowledgement for service '" << service->GetName() << "'";
658 ObjectLock olock(service);
659 service->ClearAcknowledgement();
662 service->RemoveCommentsByType(CommentAcknowledgement);
665 void ExternalCommandProcessor::AcknowledgeHostProblem(double, const std::vector<String>& arguments)
667 bool sticky = (Convert::ToLong(arguments[1]) == 2 ? true : false);
668 bool notify = (Convert::ToLong(arguments[2]) > 0 ? true : false);
669 bool persistent = (Convert::ToLong(arguments[3]) > 0 ? true : false);
671 Host::Ptr host = Host::GetByName(arguments[0]);
674 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot acknowledge host problem for non-existent host '" + arguments[0] + "'"));
676 Log(LogNotice, "ExternalCommandProcessor")
677 << "Setting acknowledgement for host '" << host->GetName() << "'" << (notify ? "" : ". Disabled notification");
679 if (host->GetState() == HostUp)
680 BOOST_THROW_EXCEPTION(std::invalid_argument("The host '" + arguments[0] + "' is OK."));
682 Comment::AddComment(host, CommentAcknowledgement, arguments[4], arguments[5], persistent, 0);
683 host->AcknowledgeProblem(arguments[4], arguments[5], sticky ? AcknowledgementSticky : AcknowledgementNormal, notify, persistent);
686 void ExternalCommandProcessor::AcknowledgeHostProblemExpire(double, const std::vector<String>& arguments)
688 bool sticky = (Convert::ToLong(arguments[1]) == 2 ? true : false);
689 bool notify = (Convert::ToLong(arguments[2]) > 0 ? true : false);
690 bool persistent = (Convert::ToLong(arguments[3]) > 0 ? true : false);
691 double timestamp = Convert::ToDouble(arguments[4]);
693 Host::Ptr host = Host::GetByName(arguments[0]);
696 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot acknowledge host problem with expire time for non-existent host '" + arguments[0] + "'"));
698 Log(LogNotice, "ExternalCommandProcessor")
699 << "Setting timed acknowledgement for host '" << host->GetName() << "'" << (notify ? "" : ". Disabled notification");
701 if (host->GetState() == HostUp)
702 BOOST_THROW_EXCEPTION(std::invalid_argument("The host '" + arguments[0] + "' is OK."));
704 if (timestamp != 0 && timestamp <= Utility::GetTime())
705 BOOST_THROW_EXCEPTION(std::invalid_argument("Acknowledgement expire time must be in the future for host '" + arguments[0] + "'"));
707 Comment::AddComment(host, CommentAcknowledgement, arguments[5], arguments[6], persistent, timestamp);
708 host->AcknowledgeProblem(arguments[5], arguments[6], sticky ? AcknowledgementSticky : AcknowledgementNormal, notify, persistent, timestamp);
711 void ExternalCommandProcessor::RemoveHostAcknowledgement(double, const std::vector<String>& arguments)
713 Host::Ptr host = Host::GetByName(arguments[0]);
716 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot remove acknowledgement for non-existent host '" + arguments[0] + "'"));
718 Log(LogNotice, "ExternalCommandProcessor")
719 << "Removing acknowledgement for host '" << host->GetName() << "'";
722 ObjectLock olock(host);
723 host->ClearAcknowledgement();
725 host->RemoveCommentsByType(CommentAcknowledgement);
728 void ExternalCommandProcessor::EnableHostgroupSvcChecks(double, const std::vector<String>& arguments)
730 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
733 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable 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 << "Enabling active checks for service '" << service->GetName() << "'";
740 service->ModifyAttribute("enable_active_checks", true);
745 void ExternalCommandProcessor::DisableHostgroupSvcChecks(double, const std::vector<String>& arguments)
747 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
750 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable hostgroup service checks for non-existent hostgroup '" + arguments[0] + "'"));
752 for (const Host::Ptr& host : hg->GetMembers()) {
753 for (const Service::Ptr& service : host->GetServices()) {
754 Log(LogNotice, "ExternalCommandProcessor")
755 << "Disabling active checks for service '" << service->GetName() << "'";
757 service->ModifyAttribute("enable_active_checks", false);
762 void ExternalCommandProcessor::EnableServicegroupSvcChecks(double, const std::vector<String>& arguments)
764 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
767 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable servicegroup service checks for non-existent servicegroup '" + arguments[0] + "'"));
769 for (const Service::Ptr& service : sg->GetMembers()) {
770 Log(LogNotice, "ExternalCommandProcessor")
771 << "Enabling active checks for service '" << service->GetName() << "'";
773 service->ModifyAttribute("enable_active_checks", true);
777 void ExternalCommandProcessor::DisableServicegroupSvcChecks(double, const std::vector<String>& arguments)
779 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
782 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable servicegroup service checks for non-existent servicegroup '" + arguments[0] + "'"));
784 for (const Service::Ptr& service : sg->GetMembers()) {
785 Log(LogNotice, "ExternalCommandProcessor")
786 << "Disabling active checks for service '" << service->GetName() << "'";
788 service->ModifyAttribute("enable_active_checks", false);
792 void ExternalCommandProcessor::EnablePassiveHostChecks(double, const std::vector<String>& arguments)
794 Host::Ptr host = Host::GetByName(arguments[0]);
797 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable passive host checks for non-existent host '" + arguments[0] + "'"));
799 Log(LogNotice, "ExternalCommandProcessor")
800 << "Enabling passive checks for host '" << arguments[0] << "'";
802 host->ModifyAttribute("enable_passive_checks", true);
805 void ExternalCommandProcessor::DisablePassiveHostChecks(double, const std::vector<String>& arguments)
807 Host::Ptr host = Host::GetByName(arguments[0]);
810 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable passive host checks for non-existent host '" + arguments[0] + "'"));
812 Log(LogNotice, "ExternalCommandProcessor")
813 << "Disabling passive checks for host '" << arguments[0] << "'";
815 host->ModifyAttribute("enable_passive_checks", false);
818 void ExternalCommandProcessor::EnablePassiveSvcChecks(double, const std::vector<String>& arguments)
820 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
823 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable service checks for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
825 Log(LogNotice, "ExternalCommandProcessor")
826 << "Enabling passive checks for service '" << arguments[1] << "'";
828 service->ModifyAttribute("enable_passive_checks", true);
831 void ExternalCommandProcessor::DisablePassiveSvcChecks(double, const std::vector<String>& arguments)
833 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
836 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable service checks for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
838 Log(LogNotice, "ExternalCommandProcessor")
839 << "Disabling passive checks for service '" << arguments[1] << "'";
841 service->ModifyAttribute("enable_passive_checks", false);
844 void ExternalCommandProcessor::EnableServicegroupPassiveSvcChecks(double, const std::vector<String>& arguments)
846 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
849 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable servicegroup passive service checks for non-existent servicegroup '" + arguments[0] + "'"));
851 for (const Service::Ptr& service : sg->GetMembers()) {
852 Log(LogNotice, "ExternalCommandProcessor")
853 << "Enabling passive checks for service '" << service->GetName() << "'";
855 service->ModifyAttribute("enable_passive_checks", true);
859 void ExternalCommandProcessor::DisableServicegroupPassiveSvcChecks(double, const std::vector<String>& arguments)
861 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
864 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable servicegroup passive service checks for non-existent servicegroup '" + arguments[0] + "'"));
866 for (const Service::Ptr& service : sg->GetMembers()) {
867 Log(LogNotice, "ExternalCommandProcessor")
868 << "Disabling passive checks for service '" << service->GetName() << "'";
870 service->ModifyAttribute("enable_passive_checks", false);
874 void ExternalCommandProcessor::EnableHostgroupPassiveSvcChecks(double, const std::vector<String>& arguments)
876 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
879 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable 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 << "Enabling passive checks for service '" << service->GetName() << "'";
886 service->ModifyAttribute("enable_passive_checks", true);
891 void ExternalCommandProcessor::DisableHostgroupPassiveSvcChecks(double, const std::vector<String>& arguments)
893 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
896 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable hostgroup passive service checks for non-existent hostgroup '" + arguments[0] + "'"));
898 for (const Host::Ptr& host : hg->GetMembers()) {
899 for (const Service::Ptr& service : host->GetServices()) {
900 Log(LogNotice, "ExternalCommandProcessor")
901 << "Disabling passive checks for service '" << service->GetName() << "'";
903 service->ModifyAttribute("enable_passive_checks", false);
908 void ExternalCommandProcessor::ProcessFile(double, const std::vector<String>& arguments)
910 std::deque< std::vector<String> > file_queue;
911 file_queue.push_back(arguments);
913 while (!file_queue.empty()) {
914 std::vector<String> argument = file_queue.front();
915 file_queue.pop_front();
917 String file = argument[0];
918 int to_delete = Convert::ToLong(argument[1]);
921 ifp.exceptions(std::ifstream::badbit);
923 ifp.open(file.CStr(), std::ifstream::in);
927 std::getline(ifp, line);
930 Log(LogNotice, "compat")
931 << "Executing external command: " << line;
933 ExecuteFromFile(line, file_queue);
934 } catch (const std::exception& ex) {
935 Log(LogWarning, "ExternalCommandProcessor")
936 << "External command failed: " << DiagnosticInformation(ex);
943 (void) unlink(file.CStr());
947 void ExternalCommandProcessor::ScheduleSvcDowntime(double, const std::vector<String>& arguments)
949 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
952 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot schedule service downtime for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
955 int triggeredByLegacy = Convert::ToLong(arguments[5]);
956 int is_fixed = Convert::ToLong(arguments[4]);
957 if (triggeredByLegacy != 0)
958 triggeredBy = Downtime::GetDowntimeIDFromLegacyID(triggeredByLegacy);
960 Log(LogNotice, "ExternalCommandProcessor")
961 << "Creating downtime for service " << service->GetName();
962 (void) Downtime::AddDowntime(service, arguments[7], arguments[8],
963 Convert::ToDouble(arguments[2]), Convert::ToDouble(arguments[3]),
964 Convert::ToBool(is_fixed), triggeredBy, Convert::ToDouble(arguments[6]));
967 void ExternalCommandProcessor::DelSvcDowntime(double, const std::vector<String>& arguments)
969 int id = Convert::ToLong(arguments[0]);
970 Log(LogNotice, "ExternalCommandProcessor")
971 << "Removing downtime ID " << arguments[0];
972 String rid = Downtime::GetDowntimeIDFromLegacyID(id);
973 Downtime::RemoveDowntime(rid, true);
976 void ExternalCommandProcessor::ScheduleHostDowntime(double, const std::vector<String>& arguments)
978 Host::Ptr host = Host::GetByName(arguments[0]);
981 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot schedule host downtime for non-existent host '" + arguments[0] + "'"));
984 int triggeredByLegacy = Convert::ToLong(arguments[4]);
985 int is_fixed = Convert::ToLong(arguments[3]);
986 if (triggeredByLegacy != 0)
987 triggeredBy = Downtime::GetDowntimeIDFromLegacyID(triggeredByLegacy);
989 Log(LogNotice, "ExternalCommandProcessor")
990 << "Creating downtime for host " << host->GetName();
992 (void) Downtime::AddDowntime(host, arguments[6], arguments[7],
993 Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
994 Convert::ToBool(is_fixed), triggeredBy, Convert::ToDouble(arguments[5]));
997 void ExternalCommandProcessor::ScheduleAndPropagateHostDowntime(double, const std::vector<String>& arguments)
999 Host::Ptr host = Host::GetByName(arguments[0]);
1002 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot schedule and propagate host downtime for non-existent host '" + arguments[0] + "'"));
1005 int triggeredByLegacy = Convert::ToLong(arguments[4]);
1006 int is_fixed = Convert::ToLong(arguments[3]);
1007 if (triggeredByLegacy != 0)
1008 triggeredBy = Downtime::GetDowntimeIDFromLegacyID(triggeredByLegacy);
1010 Log(LogNotice, "ExternalCommandProcessor")
1011 << "Creating downtime for host " << host->GetName();
1013 (void) Downtime::AddDowntime(host, arguments[6], arguments[7],
1014 Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
1015 Convert::ToBool(is_fixed), triggeredBy, Convert::ToDouble(arguments[5]));
1017 /* Schedule downtime for all child hosts */
1018 for (const Checkable::Ptr& child : host->GetAllChildren()) {
1020 Service::Ptr service;
1021 tie(host, service) = GetHostService(child);
1023 /* ignore all service children */
1027 (void) Downtime::AddDowntime(child, arguments[6], arguments[7],
1028 Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
1029 Convert::ToBool(is_fixed), triggeredBy, Convert::ToDouble(arguments[5]));
1033 void ExternalCommandProcessor::ScheduleAndPropagateTriggeredHostDowntime(double, const std::vector<String>& arguments)
1035 Host::Ptr host = Host::GetByName(arguments[0]);
1038 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot schedule and propagate triggered host downtime for non-existent host '" + arguments[0] + "'"));
1041 int triggeredByLegacy = Convert::ToLong(arguments[4]);
1042 int is_fixed = Convert::ToLong(arguments[3]);
1043 if (triggeredByLegacy != 0)
1044 triggeredBy = Downtime::GetDowntimeIDFromLegacyID(triggeredByLegacy);
1046 Log(LogNotice, "ExternalCommandProcessor")
1047 << "Creating downtime for host " << host->GetName();
1049 String parentDowntime = Downtime::AddDowntime(host, arguments[6], arguments[7],
1050 Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
1051 Convert::ToBool(is_fixed), triggeredBy, Convert::ToDouble(arguments[5]));
1053 /* Schedule downtime for all child hosts and explicitely trigger them through the parent host's downtime */
1054 for (const Checkable::Ptr& child : host->GetAllChildren()) {
1056 Service::Ptr service;
1057 tie(host, service) = GetHostService(child);
1059 /* ignore all service children */
1063 (void) Downtime::AddDowntime(child, arguments[6], arguments[7],
1064 Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
1065 Convert::ToBool(is_fixed), parentDowntime, Convert::ToDouble(arguments[5]));
1069 void ExternalCommandProcessor::DelHostDowntime(double, const std::vector<String>& arguments)
1071 int id = Convert::ToLong(arguments[0]);
1072 Log(LogNotice, "ExternalCommandProcessor")
1073 << "Removing downtime ID " << arguments[0];
1074 String rid = Downtime::GetDowntimeIDFromLegacyID(id);
1075 Downtime::RemoveDowntime(rid, true);
1078 void ExternalCommandProcessor::DelDowntimeByHostName(double, const std::vector<String>& arguments)
1080 Host::Ptr host = Host::GetByName(arguments[0]);
1083 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot schedule host services downtime for non-existent host '" + arguments[0] + "'"));
1086 if (arguments.size() >= 2)
1087 serviceName = arguments[1];
1090 if (arguments.size() >= 3)
1091 startTime = arguments[2];
1093 String commentString;
1094 if (arguments.size() >= 4)
1095 commentString = arguments[3];
1097 if (arguments.size() > 5)
1098 Log(LogWarning, "ExternalCommandProcessor")
1099 << ("Ignoring additional parameters for host '" + arguments[0] + "' downtime deletion.");
1101 for (const Downtime::Ptr& downtime : host->GetDowntimes()) {
1102 Log(LogNotice, "ExternalCommandProcessor")
1103 << "Removing downtime '" << downtime->GetName() << "'.";
1105 Downtime::RemoveDowntime(downtime->GetName(), true);
1108 for (const Service::Ptr& service : host->GetServices()) {
1109 if (!serviceName.IsEmpty() && serviceName != service->GetName())
1112 for (const Downtime::Ptr& downtime : service->GetDowntimes()) {
1113 if (!startTime.IsEmpty() && downtime->GetStartTime() != Convert::ToDouble(startTime))
1116 if (!commentString.IsEmpty() && downtime->GetComment() != commentString)
1119 Log(LogNotice, "ExternalCommandProcessor")
1120 << "Removing downtime '" << downtime->GetName() << "'.";
1122 Downtime::RemoveDowntime(downtime->GetName(), true);
1127 void ExternalCommandProcessor::ScheduleHostSvcDowntime(double, const std::vector<String>& arguments)
1129 Host::Ptr host = Host::GetByName(arguments[0]);
1132 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot schedule host services downtime for non-existent host '" + arguments[0] + "'"));
1135 int triggeredByLegacy = Convert::ToLong(arguments[4]);
1136 int is_fixed = Convert::ToLong(arguments[3]);
1137 if (triggeredByLegacy != 0)
1138 triggeredBy = Downtime::GetDowntimeIDFromLegacyID(triggeredByLegacy);
1140 Log(LogNotice, "ExternalCommandProcessor")
1141 << "Creating downtime for host " << host->GetName();
1143 (void) Downtime::AddDowntime(host, arguments[6], arguments[7],
1144 Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
1145 Convert::ToBool(is_fixed), triggeredBy, Convert::ToDouble(arguments[5]));
1147 for (const Service::Ptr& service : host->GetServices()) {
1148 Log(LogNotice, "ExternalCommandProcessor")
1149 << "Creating downtime for service " << service->GetName();
1150 (void) Downtime::AddDowntime(service, arguments[6], arguments[7],
1151 Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
1152 Convert::ToBool(is_fixed), triggeredBy, Convert::ToDouble(arguments[5]));
1156 void ExternalCommandProcessor::ScheduleHostgroupHostDowntime(double, const std::vector<String>& arguments)
1158 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
1161 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot schedule hostgroup host downtime for non-existent hostgroup '" + arguments[0] + "'"));
1164 int triggeredByLegacy = Convert::ToLong(arguments[4]);
1165 int is_fixed = Convert::ToLong(arguments[3]);
1166 if (triggeredByLegacy != 0)
1167 triggeredBy = Downtime::GetDowntimeIDFromLegacyID(triggeredByLegacy);
1169 for (const Host::Ptr& host : hg->GetMembers()) {
1170 Log(LogNotice, "ExternalCommandProcessor")
1171 << "Creating downtime for host " << host->GetName();
1173 (void) Downtime::AddDowntime(host, arguments[6], arguments[7],
1174 Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
1175 Convert::ToBool(is_fixed), triggeredBy, Convert::ToDouble(arguments[5]));
1179 void ExternalCommandProcessor::ScheduleHostgroupSvcDowntime(double, const std::vector<String>& arguments)
1181 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
1184 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot schedule hostgroup service downtime for non-existent hostgroup '" + arguments[0] + "'"));
1187 int triggeredByLegacy = Convert::ToLong(arguments[4]);
1188 int is_fixed = Convert::ToLong(arguments[3]);
1189 if (triggeredByLegacy != 0)
1190 triggeredBy = Downtime::GetDowntimeIDFromLegacyID(triggeredByLegacy);
1192 /* Note: we can't just directly create downtimes for all the services by iterating
1193 * over all hosts in the host group - otherwise we might end up creating multiple
1194 * downtimes for some services. */
1196 std::set<Service::Ptr> services;
1198 for (const Host::Ptr& host : hg->GetMembers()) {
1199 for (const Service::Ptr& service : host->GetServices()) {
1200 services.insert(service);
1204 for (const Service::Ptr& service : services) {
1205 Log(LogNotice, "ExternalCommandProcessor")
1206 << "Creating downtime for service " << service->GetName();
1207 (void) Downtime::AddDowntime(service, arguments[6], arguments[7],
1208 Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
1209 Convert::ToBool(is_fixed), triggeredBy, Convert::ToDouble(arguments[5]));
1213 void ExternalCommandProcessor::ScheduleServicegroupHostDowntime(double, const std::vector<String>& arguments)
1215 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
1218 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot schedule servicegroup host downtime for non-existent servicegroup '" + arguments[0] + "'"));
1221 int triggeredByLegacy = Convert::ToLong(arguments[4]);
1222 int is_fixed = Convert::ToLong(arguments[3]);
1223 if (triggeredByLegacy != 0)
1224 triggeredBy = Downtime::GetDowntimeIDFromLegacyID(triggeredByLegacy);
1226 /* Note: we can't just directly create downtimes for all the hosts by iterating
1227 * over all services in the service group - otherwise we might end up creating multiple
1228 * downtimes for some hosts. */
1230 std::set<Host::Ptr> hosts;
1232 for (const Service::Ptr& service : sg->GetMembers()) {
1233 Host::Ptr host = service->GetHost();
1237 for (const Host::Ptr& host : hosts) {
1238 Log(LogNotice, "ExternalCommandProcessor")
1239 << "Creating downtime for host " << host->GetName();
1240 (void) Downtime::AddDowntime(host, arguments[6], arguments[7],
1241 Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
1242 Convert::ToBool(is_fixed), triggeredBy, Convert::ToDouble(arguments[5]));
1246 void ExternalCommandProcessor::ScheduleServicegroupSvcDowntime(double, const std::vector<String>& arguments)
1248 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
1251 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot schedule servicegroup service downtime for non-existent servicegroup '" + arguments[0] + "'"));
1254 int triggeredByLegacy = Convert::ToLong(arguments[4]);
1255 int is_fixed = Convert::ToLong(arguments[3]);
1256 if (triggeredByLegacy != 0)
1257 triggeredBy = Downtime::GetDowntimeIDFromLegacyID(triggeredByLegacy);
1259 for (const Service::Ptr& service : sg->GetMembers()) {
1260 Log(LogNotice, "ExternalCommandProcessor")
1261 << "Creating downtime for service " << service->GetName();
1262 (void) Downtime::AddDowntime(service, arguments[6], arguments[7],
1263 Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
1264 Convert::ToBool(is_fixed), triggeredBy, Convert::ToDouble(arguments[5]));
1268 void ExternalCommandProcessor::AddHostComment(double, const std::vector<String>& arguments)
1270 Host::Ptr host = Host::GetByName(arguments[0]);
1273 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot add host comment for non-existent host '" + arguments[0] + "'"));
1275 if (arguments[2].IsEmpty() || arguments[3].IsEmpty())
1276 BOOST_THROW_EXCEPTION(std::invalid_argument("Author and comment must not be empty"));
1278 Log(LogNotice, "ExternalCommandProcessor")
1279 << "Creating comment for host " << host->GetName();
1280 (void) Comment::AddComment(host, CommentUser, arguments[2], arguments[3], false, 0);
1283 void ExternalCommandProcessor::DelHostComment(double, const std::vector<String>& arguments)
1285 int id = Convert::ToLong(arguments[0]);
1286 Log(LogNotice, "ExternalCommandProcessor")
1287 << "Removing comment ID " << arguments[0];
1288 String rid = Comment::GetCommentIDFromLegacyID(id);
1289 Comment::RemoveComment(rid);
1292 void ExternalCommandProcessor::AddSvcComment(double, const std::vector<String>& arguments)
1294 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1297 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot add service comment for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
1299 if (arguments[3].IsEmpty() || arguments[4].IsEmpty())
1300 BOOST_THROW_EXCEPTION(std::invalid_argument("Author and comment must not be empty"));
1302 Log(LogNotice, "ExternalCommandProcessor")
1303 << "Creating comment for service " << service->GetName();
1304 (void) Comment::AddComment(service, CommentUser, arguments[3], arguments[4], false, 0);
1307 void ExternalCommandProcessor::DelSvcComment(double, const std::vector<String>& arguments)
1309 int id = Convert::ToLong(arguments[0]);
1310 Log(LogNotice, "ExternalCommandProcessor")
1311 << "Removing comment ID " << arguments[0];
1313 String rid = Comment::GetCommentIDFromLegacyID(id);
1314 Comment::RemoveComment(rid);
1317 void ExternalCommandProcessor::DelAllHostComments(double, const std::vector<String>& arguments)
1319 Host::Ptr host = Host::GetByName(arguments[0]);
1322 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot delete all host comments for non-existent host '" + arguments[0] + "'"));
1324 Log(LogNotice, "ExternalCommandProcessor")
1325 << "Removing all comments for host " << host->GetName();
1326 host->RemoveAllComments();
1329 void ExternalCommandProcessor::DelAllSvcComments(double, const std::vector<String>& arguments)
1331 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1334 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot delete all service comments for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
1336 Log(LogNotice, "ExternalCommandProcessor")
1337 << "Removing all comments for service " << service->GetName();
1338 service->RemoveAllComments();
1341 void ExternalCommandProcessor::SendCustomHostNotification(double, const std::vector<String>& arguments)
1343 Host::Ptr host = Host::GetByName(arguments[0]);
1346 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot send custom host notification for non-existent host '" + arguments[0] + "'"));
1348 int options = Convert::ToLong(arguments[1]);
1350 Log(LogNotice, "ExternalCommandProcessor")
1351 << "Sending custom notification for host " << host->GetName();
1353 host->SetForceNextNotification(true);
1356 Checkable::OnNotificationsRequested(host, NotificationCustom,
1357 host->GetLastCheckResult(), arguments[2], arguments[3], nullptr);
1360 void ExternalCommandProcessor::SendCustomSvcNotification(double, const std::vector<String>& arguments)
1362 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1365 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot send custom service notification for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
1367 int options = Convert::ToLong(arguments[2]);
1369 Log(LogNotice, "ExternalCommandProcessor")
1370 << "Sending custom notification for service " << service->GetName();
1373 service->SetForceNextNotification(true);
1376 Service::OnNotificationsRequested(service, NotificationCustom,
1377 service->GetLastCheckResult(), arguments[3], arguments[4], nullptr);
1380 void ExternalCommandProcessor::DelayHostNotification(double, const std::vector<String>& arguments)
1382 Host::Ptr host = Host::GetByName(arguments[0]);
1385 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot delay host notification for non-existent host '" + arguments[0] + "'"));
1387 Log(LogNotice, "ExternalCommandProcessor")
1388 << "Delaying notifications for host '" << host->GetName() << "'";
1390 for (const Notification::Ptr& notification : host->GetNotifications()) {
1391 notification->SetNextNotification(Convert::ToDouble(arguments[1]));
1395 void ExternalCommandProcessor::DelaySvcNotification(double, const std::vector<String>& arguments)
1397 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1400 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot delay service notification for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
1402 Log(LogNotice, "ExternalCommandProcessor")
1403 << "Delaying notifications for service " << service->GetName();
1405 for (const Notification::Ptr& notification : service->GetNotifications()) {
1406 notification->SetNextNotification(Convert::ToDouble(arguments[2]));
1410 void ExternalCommandProcessor::EnableHostNotifications(double, const std::vector<String>& arguments)
1412 Host::Ptr host = Host::GetByName(arguments[0]);
1415 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable host notifications for non-existent host '" + arguments[0] + "'"));
1417 Log(LogNotice, "ExternalCommandProcessor")
1418 << "Enabling notifications for host '" << arguments[0] << "'";
1420 host->ModifyAttribute("enable_notifications", true);
1423 void ExternalCommandProcessor::DisableHostNotifications(double, const std::vector<String>& arguments)
1425 Host::Ptr host = Host::GetByName(arguments[0]);
1428 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable host notifications for non-existent host '" + arguments[0] + "'"));
1430 Log(LogNotice, "ExternalCommandProcessor")
1431 << "Disabling notifications for host '" << arguments[0] << "'";
1433 host->ModifyAttribute("enable_notifications", false);
1436 void ExternalCommandProcessor::EnableSvcNotifications(double, const std::vector<String>& arguments)
1438 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1441 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable service notifications for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
1443 Log(LogNotice, "ExternalCommandProcessor")
1444 << "Enabling notifications for service '" << arguments[1] << "'";
1446 service->ModifyAttribute("enable_notifications", true);
1449 void ExternalCommandProcessor::DisableSvcNotifications(double, const std::vector<String>& arguments)
1451 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1454 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable service notifications for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
1456 Log(LogNotice, "ExternalCommandProcessor")
1457 << "Disabling notifications for service '" << arguments[1] << "'";
1459 service->ModifyAttribute("enable_notifications", false);
1462 void ExternalCommandProcessor::EnableHostSvcNotifications(double, const std::vector<String>& arguments)
1464 Host::Ptr host = Host::GetByName(arguments[0]);
1467 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable notifications for all services for non-existent host '" + arguments[0] + "'"));
1469 Log(LogNotice, "ExternalCommandProcessor")
1470 << "Enabling notifications for all services on host '" << arguments[0] << "'";
1472 for (const Service::Ptr& service : host->GetServices()) {
1473 Log(LogNotice, "ExternalCommandProcessor")
1474 << "Enabling notifications for service '" << service->GetName() << "'";
1476 service->ModifyAttribute("enable_notifications", true);
1480 void ExternalCommandProcessor::DisableHostSvcNotifications(double, const std::vector<String>& arguments)
1482 Host::Ptr host = Host::GetByName(arguments[0]);
1485 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable notifications for all services for non-existent host '" + arguments[0] + "'"));
1487 Log(LogNotice, "ExternalCommandProcessor")
1488 << "Disabling notifications for all services on host '" << arguments[0] << "'";
1490 for (const Service::Ptr& service : host->GetServices()) {
1491 Log(LogNotice, "ExternalCommandProcessor")
1492 << "Disabling notifications for service '" << service->GetName() << "'";
1494 service->ModifyAttribute("enable_notifications", false);
1498 void ExternalCommandProcessor::DisableHostgroupHostChecks(double, const std::vector<String>& arguments)
1500 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
1503 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable hostgroup host checks for non-existent hostgroup '" + arguments[0] + "'"));
1505 for (const Host::Ptr& host : hg->GetMembers()) {
1506 Log(LogNotice, "ExternalCommandProcessor")
1507 << "Disabling active checks for host '" << host->GetName() << "'";
1509 host->ModifyAttribute("enable_active_checks", false);
1513 void ExternalCommandProcessor::DisableHostgroupPassiveHostChecks(double, const std::vector<String>& arguments)
1515 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
1518 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable hostgroup passive host checks for non-existent hostgroup '" + arguments[0] + "'"));
1520 for (const Host::Ptr& host : hg->GetMembers()) {
1521 Log(LogNotice, "ExternalCommandProcessor")
1522 << "Disabling passive checks for host '" << host->GetName() << "'";
1524 host->ModifyAttribute("enable_passive_checks", false);
1528 void ExternalCommandProcessor::DisableServicegroupHostChecks(double, const std::vector<String>& arguments)
1530 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
1533 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable servicegroup 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 active checks for host '" << host->GetName() << "'";
1541 host->ModifyAttribute("enable_active_checks", false);
1545 void ExternalCommandProcessor::DisableServicegroupPassiveHostChecks(double, const std::vector<String>& arguments)
1547 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
1550 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable servicegroup passive host checks for non-existent servicegroup '" + arguments[0] + "'"));
1552 for (const Service::Ptr& service : sg->GetMembers()) {
1553 Host::Ptr host = service->GetHost();
1555 Log(LogNotice, "ExternalCommandProcessor")
1556 << "Disabling passive checks for host '" << host->GetName() << "'";
1558 host->ModifyAttribute("enable_passive_checks", false);
1562 void ExternalCommandProcessor::EnableHostgroupHostChecks(double, const std::vector<String>& arguments)
1564 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
1567 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable hostgroup host checks for non-existent hostgroup '" + arguments[0] + "'"));
1569 for (const Host::Ptr& host : hg->GetMembers()) {
1570 Log(LogNotice, "ExternalCommandProcessor")
1571 << "Enabling active checks for host '" << host->GetName() << "'";
1573 host->ModifyAttribute("enable_active_checks", true);
1577 void ExternalCommandProcessor::EnableHostgroupPassiveHostChecks(double, const std::vector<String>& arguments)
1579 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
1582 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable hostgroup passive host checks for non-existent hostgroup '" + arguments[0] + "'"));
1584 for (const Host::Ptr& host : hg->GetMembers()) {
1585 Log(LogNotice, "ExternalCommandProcessor")
1586 << "Enabling passive checks for host '" << host->GetName() << "'";
1588 host->ModifyAttribute("enable_passive_checks", true);
1592 void ExternalCommandProcessor::EnableServicegroupHostChecks(double, const std::vector<String>& arguments)
1594 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
1597 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable servicegroup 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 active checks for host '" << host->GetName() << "'";
1605 host->ModifyAttribute("enable_active_checks", true);
1609 void ExternalCommandProcessor::EnableServicegroupPassiveHostChecks(double, const std::vector<String>& arguments)
1611 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
1614 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable servicegroup passive host checks for non-existent servicegroup '" + arguments[0] + "'"));
1616 for (const Service::Ptr& service : sg->GetMembers()) {
1617 Host::Ptr host = service->GetHost();
1619 Log(LogNotice, "ExternalCommandProcessor")
1620 << "Enabling passive checks for host '" << host->GetName() << "'";
1622 host->ModifyAttribute("enable_passive_checks", true);
1626 void ExternalCommandProcessor::EnableHostFlapping(double, const std::vector<String>& arguments)
1628 Host::Ptr host = Host::GetByName(arguments[0]);
1631 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable host flapping for non-existent host '" + arguments[0] + "'"));
1633 Log(LogNotice, "ExternalCommandProcessor")
1634 << "Enabling flapping detection for host '" << arguments[0] << "'";
1636 host->ModifyAttribute("enable_flapping", true);
1639 void ExternalCommandProcessor::DisableHostFlapping(double, const std::vector<String>& arguments)
1641 Host::Ptr host = Host::GetByName(arguments[0]);
1644 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable host flapping for non-existent host '" + arguments[0] + "'"));
1646 Log(LogNotice, "ExternalCommandProcessor")
1647 << "Disabling flapping detection for host '" << arguments[0] << "'";
1649 host->ModifyAttribute("enable_flapping", false);
1652 void ExternalCommandProcessor::EnableSvcFlapping(double, const std::vector<String>& arguments)
1654 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1657 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable service flapping for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
1659 Log(LogNotice, "ExternalCommandProcessor")
1660 << "Enabling flapping detection for service '" << arguments[1] << "'";
1662 service->ModifyAttribute("enable_flapping", true);
1665 void ExternalCommandProcessor::DisableSvcFlapping(double, const std::vector<String>& arguments)
1667 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1670 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable service flapping for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
1672 Log(LogNotice, "ExternalCommandProcessor")
1673 << "Disabling flapping detection for service '" << arguments[1] << "'";
1675 service->ModifyAttribute("enable_flapping", false);
1678 void ExternalCommandProcessor::EnableNotifications(double, const std::vector<String>&)
1680 Log(LogNotice, "ExternalCommandProcessor", "Globally enabling notifications.");
1682 IcingaApplication::GetInstance()->ModifyAttribute("enable_notifications", true);
1685 void ExternalCommandProcessor::DisableNotifications(double, const std::vector<String>&)
1687 Log(LogNotice, "ExternalCommandProcessor", "Globally disabling notifications.");
1689 IcingaApplication::GetInstance()->ModifyAttribute("enable_notifications", false);
1692 void ExternalCommandProcessor::EnableFlapDetection(double, const std::vector<String>&)
1694 Log(LogNotice, "ExternalCommandProcessor", "Globally enabling flap detection.");
1696 IcingaApplication::GetInstance()->ModifyAttribute("enable_flapping", true);
1699 void ExternalCommandProcessor::DisableFlapDetection(double, const std::vector<String>&)
1701 Log(LogNotice, "ExternalCommandProcessor", "Globally disabling flap detection.");
1703 IcingaApplication::GetInstance()->ModifyAttribute("enable_flapping", false);
1706 void ExternalCommandProcessor::EnableEventHandlers(double, const std::vector<String>&)
1708 Log(LogNotice, "ExternalCommandProcessor", "Globally enabling event handlers.");
1710 IcingaApplication::GetInstance()->ModifyAttribute("enable_event_handlers", true);
1713 void ExternalCommandProcessor::DisableEventHandlers(double, const std::vector<String>&)
1715 Log(LogNotice, "ExternalCommandProcessor", "Globally disabling event handlers.");
1717 IcingaApplication::GetInstance()->ModifyAttribute("enable_event_handlers", false);
1720 void ExternalCommandProcessor::EnablePerformanceData(double, const std::vector<String>&)
1722 Log(LogNotice, "ExternalCommandProcessor", "Globally enabling performance data processing.");
1724 IcingaApplication::GetInstance()->ModifyAttribute("enable_perfdata", true);
1727 void ExternalCommandProcessor::DisablePerformanceData(double, const std::vector<String>&)
1729 Log(LogNotice, "ExternalCommandProcessor", "Globally disabling performance data processing.");
1731 IcingaApplication::GetInstance()->ModifyAttribute("enable_perfdata", false);
1734 void ExternalCommandProcessor::StartExecutingSvcChecks(double, const std::vector<String>&)
1736 Log(LogNotice, "ExternalCommandProcessor", "Globally enabling service checks.");
1738 IcingaApplication::GetInstance()->ModifyAttribute("enable_service_checks", true);
1741 void ExternalCommandProcessor::StopExecutingSvcChecks(double, const std::vector<String>&)
1743 Log(LogNotice, "ExternalCommandProcessor", "Globally disabling service checks.");
1745 IcingaApplication::GetInstance()->ModifyAttribute("enable_service_checks", false);
1748 void ExternalCommandProcessor::StartExecutingHostChecks(double, const std::vector<String>&)
1750 Log(LogNotice, "ExternalCommandProcessor", "Globally enabling host checks.");
1752 IcingaApplication::GetInstance()->ModifyAttribute("enable_host_checks", true);
1755 void ExternalCommandProcessor::StopExecutingHostChecks(double, const std::vector<String>&)
1757 Log(LogNotice, "ExternalCommandProcessor", "Globally disabling host checks.");
1759 IcingaApplication::GetInstance()->ModifyAttribute("enable_host_checks", false);
1762 void ExternalCommandProcessor::ChangeNormalSvcCheckInterval(double, const std::vector<String>& arguments)
1764 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1767 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot update check interval for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
1769 double interval = Convert::ToDouble(arguments[2]);
1771 Log(LogNotice, "ExternalCommandProcessor")
1772 << "Updating check interval for service '" << arguments[1] << "'";
1774 service->ModifyAttribute("check_interval", interval * 60);
1777 void ExternalCommandProcessor::ChangeNormalHostCheckInterval(double, const std::vector<String>& arguments)
1779 Host::Ptr host = Host::GetByName(arguments[0]);
1782 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot update check interval for non-existent host '" + arguments[0] + "'"));
1784 Log(LogNotice, "ExternalCommandProcessor")
1785 << "Updating check interval for host '" << arguments[0] << "'";
1787 double interval = Convert::ToDouble(arguments[1]);
1789 host->ModifyAttribute("check_interval", interval * 60);
1792 void ExternalCommandProcessor::ChangeRetrySvcCheckInterval(double, const std::vector<String>& arguments)
1794 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1797 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot update retry interval for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
1799 double interval = Convert::ToDouble(arguments[2]);
1801 Log(LogNotice, "ExternalCommandProcessor")
1802 << "Updating retry interval for service '" << arguments[1] << "'";
1804 service->ModifyAttribute("retry_interval", interval * 60);
1807 void ExternalCommandProcessor::ChangeRetryHostCheckInterval(double, const std::vector<String>& arguments)
1809 Host::Ptr host = Host::GetByName(arguments[0]);
1812 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot update retry interval for non-existent host '" + arguments[0] + "'"));
1814 Log(LogNotice, "ExternalCommandProcessor")
1815 << "Updating retry interval for host '" << arguments[0] << "'";
1817 double interval = Convert::ToDouble(arguments[1]);
1819 host->ModifyAttribute("retry_interval", interval * 60);
1822 void ExternalCommandProcessor::EnableHostEventHandler(double, const std::vector<String>& arguments)
1824 Host::Ptr host = Host::GetByName(arguments[0]);
1827 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable event handler for non-existent host '" + arguments[0] + "'"));
1829 Log(LogNotice, "ExternalCommandProcessor")
1830 << "Enabling event handler for host '" << arguments[0] << "'";
1832 host->ModifyAttribute("enable_event_handler", true);
1835 void ExternalCommandProcessor::DisableHostEventHandler(double, const std::vector<String>& arguments)
1837 Host::Ptr host = Host::GetByName(arguments[0]);
1840 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable event handler for non-existent host '" + arguments[0] + "'"));
1842 Log(LogNotice, "ExternalCommandProcessor")
1843 << "Disabling event handler for host '" << arguments[0] << "'";
1845 host->ModifyAttribute("enable_event_handler", false);
1848 void ExternalCommandProcessor::EnableSvcEventHandler(double, const std::vector<String>& arguments)
1850 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1853 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable event handler for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
1855 Log(LogNotice, "ExternalCommandProcessor")
1856 << "Enabling event handler for service '" << arguments[1] << "'";
1858 service->ModifyAttribute("enable_event_handler", true);
1861 void ExternalCommandProcessor::DisableSvcEventHandler(double, const std::vector<String>& arguments)
1863 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1866 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable event handler for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
1868 Log(LogNotice, "ExternalCommandProcessor")
1869 << "Disabling event handler for service '" << arguments[1] + "'";
1871 service->ModifyAttribute("enable_event_handler", false);
1874 void ExternalCommandProcessor::ChangeHostEventHandler(double, const std::vector<String>& arguments)
1876 Host::Ptr host = Host::GetByName(arguments[0]);
1879 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change event handler for non-existent host '" + arguments[0] + "'"));
1881 if (arguments[1].IsEmpty()) {
1882 Log(LogNotice, "ExternalCommandProcessor")
1883 << "Unsetting event handler for host '" << arguments[0] << "'";
1885 host->ModifyAttribute("event_command", "");
1887 EventCommand::Ptr command = EventCommand::GetByName(arguments[1]);
1890 BOOST_THROW_EXCEPTION(std::invalid_argument("Event command '" + arguments[1] + "' does not exist."));
1892 Log(LogNotice, "ExternalCommandProcessor")
1893 << "Changing event handler for host '" << arguments[0] << "' to '" << arguments[1] << "'";
1895 host->ModifyAttribute("event_command", command->GetName());
1899 void ExternalCommandProcessor::ChangeSvcEventHandler(double, const std::vector<String>& arguments)
1901 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1904 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change event handler for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
1906 if (arguments[2].IsEmpty()) {
1907 Log(LogNotice, "ExternalCommandProcessor")
1908 << "Unsetting event handler for service '" << arguments[1] << "'";
1910 service->ModifyAttribute("event_command", "");
1912 EventCommand::Ptr command = EventCommand::GetByName(arguments[2]);
1915 BOOST_THROW_EXCEPTION(std::invalid_argument("Event command '" + arguments[2] + "' does not exist."));
1917 Log(LogNotice, "ExternalCommandProcessor")
1918 << "Changing event handler for service '" << arguments[1] << "' to '" << arguments[2] << "'";
1920 service->ModifyAttribute("event_command", command->GetName());
1924 void ExternalCommandProcessor::ChangeHostCheckCommand(double, const std::vector<String>& arguments)
1926 Host::Ptr host = Host::GetByName(arguments[0]);
1929 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change check command for non-existent host '" + arguments[0] + "'"));
1931 CheckCommand::Ptr command = CheckCommand::GetByName(arguments[1]);
1934 BOOST_THROW_EXCEPTION(std::invalid_argument("Check command '" + arguments[1] + "' does not exist."));
1936 Log(LogNotice, "ExternalCommandProcessor")
1937 << "Changing check command for host '" << arguments[0] << "' to '" << arguments[1] << "'";
1939 host->ModifyAttribute("check_command", command->GetName());
1942 void ExternalCommandProcessor::ChangeSvcCheckCommand(double, const std::vector<String>& arguments)
1944 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1947 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change check command for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
1949 CheckCommand::Ptr command = CheckCommand::GetByName(arguments[2]);
1952 BOOST_THROW_EXCEPTION(std::invalid_argument("Check command '" + arguments[2] + "' does not exist."));
1954 Log(LogNotice, "ExternalCommandProcessor")
1955 << "Changing check command for service '" << arguments[1] << "' to '" << arguments[2] << "'";
1957 service->ModifyAttribute("check_command", command->GetName());
1960 void ExternalCommandProcessor::ChangeMaxHostCheckAttempts(double, const std::vector<String>& arguments)
1962 Host::Ptr host = Host::GetByName(arguments[0]);
1965 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change max check attempts for non-existent host '" + arguments[0] + "'"));
1967 int attempts = Convert::ToLong(arguments[1]);
1969 Log(LogNotice, "ExternalCommandProcessor")
1970 << "Changing max check attempts for host '" << arguments[0] << "' to '" << arguments[1] << "'";
1972 host->ModifyAttribute("max_check_attempts", attempts);
1975 void ExternalCommandProcessor::ChangeMaxSvcCheckAttempts(double, const std::vector<String>& arguments)
1977 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1980 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change max check attempts for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
1982 int attempts = Convert::ToLong(arguments[2]);
1984 Log(LogNotice, "ExternalCommandProcessor")
1985 << "Changing max check attempts for service '" << arguments[1] << "' to '" << arguments[2] << "'";
1987 service->ModifyAttribute("max_check_attempts", attempts);
1990 void ExternalCommandProcessor::ChangeHostCheckTimeperiod(double, const std::vector<String>& arguments)
1992 Host::Ptr host = Host::GetByName(arguments[0]);
1995 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change check period for non-existent host '" + arguments[0] + "'"));
1997 TimePeriod::Ptr tp = TimePeriod::GetByName(arguments[1]);
2000 BOOST_THROW_EXCEPTION(std::invalid_argument("Time period '" + arguments[1] + "' does not exist."));
2002 Log(LogNotice, "ExternalCommandProcessor")
2003 << "Changing check period for host '" << arguments[0] << "' to '" << arguments[1] << "'";
2005 host->ModifyAttribute("check_period", tp->GetName());
2008 void ExternalCommandProcessor::ChangeSvcCheckTimeperiod(double, const std::vector<String>& arguments)
2010 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
2013 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change check period for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
2015 TimePeriod::Ptr tp = TimePeriod::GetByName(arguments[2]);
2018 BOOST_THROW_EXCEPTION(std::invalid_argument("Time period '" + arguments[2] + "' does not exist."));
2020 Log(LogNotice, "ExternalCommandProcessor")
2021 << "Changing check period for service '" << arguments[1] << "' to '" << arguments[2] << "'";
2023 service->ModifyAttribute("check_period", tp->GetName());
2026 void ExternalCommandProcessor::ChangeCustomHostVar(double, const std::vector<String>& arguments)
2028 Host::Ptr host = Host::GetByName(arguments[0]);
2031 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change custom var for non-existent host '" + arguments[0] + "'"));
2033 Log(LogNotice, "ExternalCommandProcessor")
2034 << "Changing custom var '" << arguments[1] << "' for host '" << arguments[0] << "' to value '" << arguments[2] << "'";
2036 host->ModifyAttribute("vars." + arguments[1], arguments[2]);
2039 void ExternalCommandProcessor::ChangeCustomSvcVar(double, const std::vector<String>& arguments)
2041 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
2044 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change custom var for non-existent service '" + arguments[1] + "' on host '" + arguments[0] + "'"));
2046 Log(LogNotice, "ExternalCommandProcessor")
2047 << "Changing custom var '" << arguments[2] << "' for service '" << arguments[1] << "' on host '"
2048 << arguments[0] << "' to value '" << arguments[3] << "'";
2050 service->ModifyAttribute("vars." + arguments[2], arguments[3]);
2053 void ExternalCommandProcessor::ChangeCustomUserVar(double, const std::vector<String>& arguments)
2055 User::Ptr user = User::GetByName(arguments[0]);
2058 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change custom var for non-existent user '" + arguments[0] + "'"));
2060 Log(LogNotice, "ExternalCommandProcessor")
2061 << "Changing custom var '" << arguments[1] << "' for user '" << arguments[0] << "' to value '" << arguments[2] << "'";
2063 user->ModifyAttribute("vars." + arguments[1], arguments[2]);
2066 void ExternalCommandProcessor::ChangeCustomCheckcommandVar(double, const std::vector<String>& arguments)
2068 CheckCommand::Ptr command = CheckCommand::GetByName(arguments[0]);
2071 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change custom var for non-existent command '" + arguments[0] + "'"));
2073 ChangeCustomCommandVarInternal(command, arguments[1], arguments[2]);
2076 void ExternalCommandProcessor::ChangeCustomEventcommandVar(double, const std::vector<String>& arguments)
2078 EventCommand::Ptr command = EventCommand::GetByName(arguments[0]);
2081 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change custom var for non-existent command '" + arguments[0] + "'"));
2083 ChangeCustomCommandVarInternal(command, arguments[1], arguments[2]);
2086 void ExternalCommandProcessor::ChangeCustomNotificationcommandVar(double, const std::vector<String>& arguments)
2088 NotificationCommand::Ptr command = NotificationCommand::GetByName(arguments[0]);
2091 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change custom var for non-existent command '" + arguments[0] + "'"));
2093 ChangeCustomCommandVarInternal(command, arguments[1], arguments[2]);
2096 void ExternalCommandProcessor::ChangeCustomCommandVarInternal(const Command::Ptr& command, const String& name, const Value& value)
2098 Log(LogNotice, "ExternalCommandProcessor")
2099 << "Changing custom var '" << name << "' for command '" << command->GetName() << "' to value '" << value << "'";
2101 command->ModifyAttribute("vars." + name, value);
2104 void ExternalCommandProcessor::EnableHostgroupHostNotifications(double, const std::vector<String>& arguments)
2106 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
2109 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable host notifications for non-existent hostgroup '" + arguments[0] + "'"));
2111 for (const Host::Ptr& host : hg->GetMembers()) {
2112 Log(LogNotice, "ExternalCommandProcessor")
2113 << "Enabling notifications for host '" << host->GetName() << "'";
2115 host->ModifyAttribute("enable_notifications", true);
2119 void ExternalCommandProcessor::EnableHostgroupSvcNotifications(double, const std::vector<String>& arguments)
2121 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
2124 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable service notifications for non-existent hostgroup '" + arguments[0] + "'"));
2126 for (const Host::Ptr& host : hg->GetMembers()) {
2127 for (const Service::Ptr& service : host->GetServices()) {
2128 Log(LogNotice, "ExternalCommandProcessor")
2129 << "Enabling notifications for service '" << service->GetName() << "'";
2131 service->ModifyAttribute("enable_notifications", true);
2136 void ExternalCommandProcessor::DisableHostgroupHostNotifications(double, const std::vector<String>& arguments)
2138 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
2141 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable host notifications for non-existent hostgroup '" + arguments[0] + "'"));
2143 for (const Host::Ptr& host : hg->GetMembers()) {
2144 Log(LogNotice, "ExternalCommandProcessor")
2145 << "Disabling notifications for host '" << host->GetName() << "'";
2147 host->ModifyAttribute("enable_notifications", false);
2151 void ExternalCommandProcessor::DisableHostgroupSvcNotifications(double, const std::vector<String>& arguments)
2153 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
2156 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable service notifications for non-existent hostgroup '" + arguments[0] + "'"));
2158 for (const Host::Ptr& host : hg->GetMembers()) {
2159 for (const Service::Ptr& service : host->GetServices()) {
2160 Log(LogNotice, "ExternalCommandProcessor")
2161 << "Disabling notifications for service '" << service->GetName() << "'";
2163 service->ModifyAttribute("enable_notifications", false);
2168 void ExternalCommandProcessor::EnableServicegroupHostNotifications(double, const std::vector<String>& arguments)
2170 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
2173 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable host notifications for non-existent servicegroup '" + arguments[0] + "'"));
2175 for (const Service::Ptr& service : sg->GetMembers()) {
2176 Host::Ptr host = service->GetHost();
2178 Log(LogNotice, "ExternalCommandProcessor")
2179 << "Enabling notifications for host '" << host->GetName() << "'";
2181 host->ModifyAttribute("enable_notifications", true);
2185 void ExternalCommandProcessor::EnableServicegroupSvcNotifications(double, const std::vector<String>& arguments)
2187 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
2190 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable service notifications for non-existent servicegroup '" + arguments[0] + "'"));
2192 for (const Service::Ptr& service : sg->GetMembers()) {
2193 Log(LogNotice, "ExternalCommandProcessor")
2194 << "Enabling notifications for service '" << service->GetName() << "'";
2196 service->ModifyAttribute("enable_notifications", true);
2200 void ExternalCommandProcessor::DisableServicegroupHostNotifications(double, const std::vector<String>& arguments)
2202 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
2205 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable host notifications for non-existent servicegroup '" + arguments[0] + "'"));
2207 for (const Service::Ptr& service : sg->GetMembers()) {
2208 Host::Ptr host = service->GetHost();
2210 Log(LogNotice, "ExternalCommandProcessor")
2211 << "Disabling notifications for host '" << host->GetName() << "'";
2213 host->ModifyAttribute("enable_notifications", false);
2217 void ExternalCommandProcessor::DisableServicegroupSvcNotifications(double, const std::vector<String>& arguments)
2219 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
2222 BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable service notifications for non-existent servicegroup '" + arguments[0] + "'"));
2224 for (const Service::Ptr& service : sg->GetMembers()) {
2225 Log(LogNotice, "ExternalCommandProcessor")
2226 << "Disabling notifications for service '" << service->GetName() << "'";
2228 service->ModifyAttribute("enable_notifications", false);
2232 boost::mutex& ExternalCommandProcessor::GetMutex()
2234 static boost::mutex mtx;
2238 std::map<String, ExternalCommandInfo>& ExternalCommandProcessor::GetCommands()
2240 static std::map<String, ExternalCommandInfo> commands;