1 /******************************************************************************
3 * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
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.h"
21 #include "icinga/host.h"
22 #include "icinga/service.h"
23 #include "icinga/user.h"
24 #include "icinga/hostgroup.h"
25 #include "icinga/servicegroup.h"
26 #include "icinga/pluginchecktask.h"
27 #include "base/convert.h"
28 #include "base/logger_fwd.h"
29 #include "base/objectlock.h"
30 #include "base/application.h"
31 #include "base/utility.h"
33 #include <boost/algorithm/string/classification.hpp>
34 #include <boost/foreach.hpp>
35 #include <boost/exception/diagnostic_information.hpp>
36 #include <boost/algorithm/string/split.hpp>
38 using namespace icinga;
40 boost::once_flag ExternalCommandProcessor::m_InitializeOnce = BOOST_ONCE_INIT;
41 boost::mutex ExternalCommandProcessor::m_Mutex;
42 std::map<String, ExternalCommandProcessor::Callback> ExternalCommandProcessor::m_Commands;
44 void ExternalCommandProcessor::Execute(const String& line)
50 BOOST_THROW_EXCEPTION(std::invalid_argument("Missing timestamp in command: " + line));
52 size_t pos = line.FindFirstOf("]");
54 if (pos == String::NPos)
55 BOOST_THROW_EXCEPTION(std::invalid_argument("Missing timestamp in command: " + line));
57 String timestamp = line.SubStr(1, pos - 1);
58 String args = line.SubStr(pos + 2, String::NPos);
60 double ts = Convert::ToDouble(timestamp);
63 BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid timestamp in command: " + line));
65 std::vector<String> argv;
66 boost::algorithm::split(argv, args, boost::is_any_of(";"));
69 BOOST_THROW_EXCEPTION(std::invalid_argument("Missing arguments in command: " + line));
71 std::vector<String> argvExtra(argv.begin() + 1, argv.end());
72 Execute(ts, argv[0], argvExtra);
75 void ExternalCommandProcessor::Execute(double time, const String& command, const std::vector<String>& arguments)
77 boost::call_once(m_InitializeOnce, &ExternalCommandProcessor::Initialize);
82 boost::mutex::scoped_lock lock(m_Mutex);
84 std::map<String, ExternalCommandProcessor::Callback>::iterator it;
85 it = m_Commands.find(command);
87 if (it == m_Commands.end())
88 BOOST_THROW_EXCEPTION(std::invalid_argument("The external command '" + command + "' does not exist."));
90 callback = it->second;
93 callback(time, arguments);
96 void ExternalCommandProcessor::Initialize(void)
98 RegisterCommand("PROCESS_HOST_CHECK_RESULT", &ExternalCommandProcessor::ProcessHostCheckResult);
99 RegisterCommand("PROCESS_SERVICE_CHECK_RESULT", &ExternalCommandProcessor::ProcessServiceCheckResult);
100 RegisterCommand("SCHEDULE_HOST_CHECK", &ExternalCommandProcessor::ScheduleHostCheck);
101 RegisterCommand("SCHEDULE_FORCED_HOST_CHECK", &ExternalCommandProcessor::ScheduleForcedHostCheck);
102 RegisterCommand("SCHEDULE_SVC_CHECK", &ExternalCommandProcessor::ScheduleSvcCheck);
103 RegisterCommand("SCHEDULE_FORCED_SVC_CHECK", &ExternalCommandProcessor::ScheduleForcedSvcCheck);
104 RegisterCommand("ENABLE_HOST_CHECK", &ExternalCommandProcessor::EnableHostCheck);
105 RegisterCommand("DISABLE_HOST_CHECK", &ExternalCommandProcessor::DisableHostCheck);
106 RegisterCommand("ENABLE_SVC_CHECK", &ExternalCommandProcessor::EnableSvcCheck);
107 RegisterCommand("DISABLE_SVC_CHECK", &ExternalCommandProcessor::DisableSvcCheck);
108 RegisterCommand("SHUTDOWN_PROCESS", &ExternalCommandProcessor::ShutdownProcess);
109 RegisterCommand("RESTART_PROCESS", &ExternalCommandProcessor::RestartProcess);
110 RegisterCommand("SCHEDULE_FORCED_HOST_SVC_CHECKS", &ExternalCommandProcessor::ScheduleForcedHostSvcChecks);
111 RegisterCommand("SCHEDULE_HOST_SVC_CHECKS", &ExternalCommandProcessor::ScheduleHostSvcChecks);
112 RegisterCommand("ENABLE_HOST_SVC_CHECKS", &ExternalCommandProcessor::EnableHostSvcChecks);
113 RegisterCommand("DISABLE_HOST_SVC_CHECKS", &ExternalCommandProcessor::DisableHostSvcChecks);
114 RegisterCommand("ACKNOWLEDGE_SVC_PROBLEM", &ExternalCommandProcessor::AcknowledgeSvcProblem);
115 RegisterCommand("ACKNOWLEDGE_SVC_PROBLEM_EXPIRE", &ExternalCommandProcessor::AcknowledgeSvcProblemExpire);
116 RegisterCommand("REMOVE_SVC_ACKNOWLEDGEMENT", &ExternalCommandProcessor::RemoveSvcAcknowledgement);
117 RegisterCommand("ACKNOWLEDGE_HOST_PROBLEM", &ExternalCommandProcessor::AcknowledgeHostProblem);
118 RegisterCommand("ACKNOWLEDGE_HOST_PROBLEM_EXPIRE", &ExternalCommandProcessor::AcknowledgeHostProblemExpire);
119 RegisterCommand("REMOVE_HOST_ACKNOWLEDGEMENT", &ExternalCommandProcessor::RemoveHostAcknowledgement);
120 RegisterCommand("DISABLE_HOST_FLAP_DETECTION", &ExternalCommandProcessor::DisableHostFlapping);
121 RegisterCommand("ENABLE_HOST_FLAP_DETECTION", &ExternalCommandProcessor::EnableHostFlapping);
122 RegisterCommand("DISABLE_SVC_FLAP_DETECTION", &ExternalCommandProcessor::DisableSvcFlapping);
123 RegisterCommand("ENABLE_SVC_FLAP_DETECTION", &ExternalCommandProcessor::EnableSvcFlapping);
124 RegisterCommand("ENABLE_HOSTGROUP_SVC_CHECKS", &ExternalCommandProcessor::EnableHostgroupSvcChecks);
125 RegisterCommand("DISABLE_HOSTGROUP_SVC_CHECKS", &ExternalCommandProcessor::DisableHostgroupSvcChecks);
126 RegisterCommand("ENABLE_SERVICEGROUP_SVC_CHECKS", &ExternalCommandProcessor::EnableServicegroupSvcChecks);
127 RegisterCommand("DISABLE_SERVICEGROUP_SVC_CHECKS", &ExternalCommandProcessor::DisableServicegroupSvcChecks);
128 RegisterCommand("ENABLE_PASSIVE_HOST_CHECKS", &ExternalCommandProcessor::EnablePassiveHostChecks);
129 RegisterCommand("DISABLE_PASSIVE_HOST_CHECKS", &ExternalCommandProcessor::DisablePassiveHostChecks);
130 RegisterCommand("ENABLE_PASSIVE_SVC_CHECKS", &ExternalCommandProcessor::EnablePassiveSvcChecks);
131 RegisterCommand("DISABLE_PASSIVE_SVC_CHECKS", &ExternalCommandProcessor::DisablePassiveSvcChecks);
132 RegisterCommand("ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS", &ExternalCommandProcessor::EnableServicegroupPassiveSvcChecks);
133 RegisterCommand("DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS", &ExternalCommandProcessor::DisableServicegroupPassiveSvcChecks);
134 RegisterCommand("ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS", &ExternalCommandProcessor::EnableHostgroupPassiveSvcChecks);
135 RegisterCommand("DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS", &ExternalCommandProcessor::DisableHostgroupPassiveSvcChecks);
136 RegisterCommand("PROCESS_FILE", &ExternalCommandProcessor::ProcessFile);
137 RegisterCommand("SCHEDULE_SVC_DOWNTIME", &ExternalCommandProcessor::ScheduleSvcDowntime);
138 RegisterCommand("DEL_SVC_DOWNTIME", &ExternalCommandProcessor::DelSvcDowntime);
139 RegisterCommand("SCHEDULE_HOST_DOWNTIME", &ExternalCommandProcessor::ScheduleHostDowntime);
140 RegisterCommand("DEL_HOST_DOWNTIME", &ExternalCommandProcessor::DelHostDowntime);
141 RegisterCommand("SCHEDULE_HOST_SVC_DOWNTIME", &ExternalCommandProcessor::ScheduleHostSvcDowntime);
142 RegisterCommand("SCHEDULE_HOSTGROUP_HOST_DOWNTIME", &ExternalCommandProcessor::ScheduleHostgroupHostDowntime);
143 RegisterCommand("SCHEDULE_HOSTGROUP_SVC_DOWNTIME", &ExternalCommandProcessor::ScheduleHostgroupSvcDowntime);
144 RegisterCommand("SCHEDULE_SERVICEGROUP_HOST_DOWNTIME", &ExternalCommandProcessor::ScheduleServicegroupHostDowntime);
145 RegisterCommand("SCHEDULE_SERVICEGROUP_SVC_DOWNTIME", &ExternalCommandProcessor::ScheduleServicegroupSvcDowntime);
146 RegisterCommand("ADD_HOST_COMMENT", &ExternalCommandProcessor::AddHostComment);
147 RegisterCommand("DEL_HOST_COMMENT", &ExternalCommandProcessor::DelHostComment);
148 RegisterCommand("ADD_SVC_COMMENT", &ExternalCommandProcessor::AddSvcComment);
149 RegisterCommand("DEL_SVC_COMMENT", &ExternalCommandProcessor::DelSvcComment);
150 RegisterCommand("DEL_ALL_HOST_COMMENTS", &ExternalCommandProcessor::DelAllHostComments);
151 RegisterCommand("DEL_ALL_SVC_COMMENTS", &ExternalCommandProcessor::DelAllSvcComments);
152 RegisterCommand("SEND_CUSTOM_HOST_NOTIFICATION", &ExternalCommandProcessor::SendCustomHostNotification);
153 RegisterCommand("SEND_CUSTOM_SVC_NOTIFICATION", &ExternalCommandProcessor::SendCustomSvcNotification);
154 RegisterCommand("DELAY_HOST_NOTIFICATION", &ExternalCommandProcessor::DelayHostNotification);
155 RegisterCommand("DELAY_SVC_NOTIFICATION", &ExternalCommandProcessor::DelaySvcNotification);
156 RegisterCommand("ENABLE_HOST_NOTIFICATIONS", &ExternalCommandProcessor::EnableHostNotifications);
157 RegisterCommand("DISABLE_HOST_NOTIFICATIONS", &ExternalCommandProcessor::DisableHostNotifications);
158 RegisterCommand("ENABLE_SVC_NOTIFICATIONS", &ExternalCommandProcessor::EnableSvcNotifications);
159 RegisterCommand("DISABLE_SVC_NOTIFICATIONS", &ExternalCommandProcessor::DisableSvcNotifications);
160 RegisterCommand("DISABLE_HOSTGROUP_HOST_CHECKS", &ExternalCommandProcessor::DisableHostgroupHostChecks);
161 RegisterCommand("DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS", &ExternalCommandProcessor::DisableHostgroupPassiveHostChecks);
162 RegisterCommand("DISABLE_SERVICEGROUP_HOST_CHECKS", &ExternalCommandProcessor::DisableServicegroupHostChecks);
163 RegisterCommand("DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS", &ExternalCommandProcessor::DisableServicegroupPassiveHostChecks);
164 RegisterCommand("ENABLE_HOSTGROUP_HOST_CHECKS", &ExternalCommandProcessor::EnableHostgroupHostChecks);
165 RegisterCommand("ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS", &ExternalCommandProcessor::EnableHostgroupPassiveHostChecks);
166 RegisterCommand("ENABLE_SERVICEGROUP_HOST_CHECKS", &ExternalCommandProcessor::EnableServicegroupHostChecks);
167 RegisterCommand("ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS", &ExternalCommandProcessor::EnableServicegroupPassiveHostChecks);
170 void ExternalCommandProcessor::RegisterCommand(const String& command, const ExternalCommandProcessor::Callback& callback)
172 boost::mutex::scoped_lock lock(m_Mutex);
173 m_Commands[command] = callback;
176 void ExternalCommandProcessor::ProcessHostCheckResult(double time, const std::vector<String>& arguments)
178 if (arguments.size() < 3)
179 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 3 arguments."));
181 Host::Ptr host = Host::GetByName(arguments[0]);
183 Service::Ptr hc = host->GetHostCheckService();
185 if (!hc->GetEnablePassiveChecks())
186 BOOST_THROW_EXCEPTION(std::invalid_argument("Got passive check result for host '" + arguments[0] + "' which has passive checks disabled."));
188 int exitStatus = Convert::ToDouble(arguments[1]);
189 Dictionary::Ptr result = PluginCheckTask::ParseCheckOutput(arguments[2]);
190 result->Set("state", PluginCheckTask::ExitStatusToState(exitStatus));
192 result->Set("schedule_start", time);
193 result->Set("schedule_end", time);
194 result->Set("execution_start", time);
195 result->Set("execution_end", time);
196 result->Set("active", 0);
198 Log(LogInformation, "icinga", "Processing passive check result for host '" + arguments[0] + "'");
199 hc->ProcessCheckResult(result);
202 ObjectLock olock(hc);
204 /* Reschedule the next check. The side effect of this is that for as long
205 * as we receive passive results for a service we won't execute any
207 hc->SetNextCheck(Utility::GetTime() + hc->GetCheckInterval());
211 void ExternalCommandProcessor::ProcessServiceCheckResult(double time, const std::vector<String>& arguments)
213 if (arguments.size() < 4)
214 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 4 arguments."));
216 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
218 if (!service->GetEnablePassiveChecks())
219 BOOST_THROW_EXCEPTION(std::invalid_argument("Got passive check result for service '" + arguments[1] + "' which has passive checks disabled."));
221 int exitStatus = Convert::ToDouble(arguments[2]);
222 Dictionary::Ptr result = PluginCheckTask::ParseCheckOutput(arguments[3]);
223 result->Set("state", PluginCheckTask::ExitStatusToState(exitStatus));
225 result->Set("schedule_start", time);
226 result->Set("schedule_end", time);
227 result->Set("execution_start", time);
228 result->Set("execution_end", time);
229 result->Set("active", 0);
231 Log(LogInformation, "icinga", "Processing passive check result for service '" + arguments[1] + "'");
232 service->ProcessCheckResult(result);
235 ObjectLock olock(service);
237 /* Reschedule the next check. The side effect of this is that for as long
238 * as we receive passive results for a service we won't execute any
240 service->SetNextCheck(Utility::GetTime() + service->GetCheckInterval());
244 void ExternalCommandProcessor::ScheduleHostCheck(double, const std::vector<String>& arguments)
246 if (arguments.size() < 2)
247 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments."));
249 Host::Ptr host = Host::GetByName(arguments[0]);
251 Service::Ptr hc = host->GetHostCheckService();
254 Log(LogInformation, "icinga", "Ignoring request request for host '" +
255 arguments[0] + "' (does not have a host check)");
259 double planned_check = Convert::ToDouble(arguments[1]);
261 if (planned_check > hc->GetNextCheck()) {
262 Log(LogInformation, "icinga", "Ignoring reschedule request for host '" +
263 arguments[0] + "' (next check is already sooner than requested check time)");
267 Log(LogInformation, "icinga", "Rescheduling next check for host '" + arguments[0] + "'");
269 if (planned_check < Utility::GetTime())
270 planned_check = Utility::GetTime();
273 ObjectLock olock(hc);
275 hc->SetNextCheck(planned_check);
279 void ExternalCommandProcessor::ScheduleForcedHostCheck(double, const std::vector<String>& arguments)
281 if (arguments.size() < 2)
282 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments."));
284 Host::Ptr host = Host::GetByName(arguments[0]);
286 Service::Ptr hc = host->GetHostCheckService();
289 Log(LogInformation, "icinga", "Ignoring request request for host '" +
290 arguments[0] + "' (does not have a host check)");
294 Log(LogInformation, "icinga", "Rescheduling next check for host '" + arguments[0] + "'");
297 ObjectLock olock(hc);
299 hc->SetForceNextCheck(true);
300 hc->SetNextCheck(Convert::ToDouble(arguments[1]));
304 void ExternalCommandProcessor::ScheduleSvcCheck(double, const std::vector<String>& arguments)
306 if (arguments.size() < 3)
307 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 3 arguments."));
309 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
311 double planned_check = Convert::ToDouble(arguments[2]);
313 if (planned_check > service->GetNextCheck()) {
314 Log(LogInformation, "icinga", "Ignoring reschedule request for service '" +
315 arguments[1] + "' (next check is already sooner than requested check time)");
319 Log(LogInformation, "icinga", "Rescheduling next check for service '" + arguments[1] + "'");
321 if (planned_check < Utility::GetTime())
322 planned_check = Utility::GetTime();
325 ObjectLock olock(service);
327 service->SetNextCheck(planned_check);
331 void ExternalCommandProcessor::ScheduleForcedSvcCheck(double, const std::vector<String>& arguments)
333 if (arguments.size() < 3)
334 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 3 arguments."));
336 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
338 Log(LogInformation, "icinga", "Rescheduling next check for service '" + arguments[1] + "'");
341 ObjectLock olock(service);
343 service->SetForceNextCheck(true);
344 service->SetNextCheck(Convert::ToDouble(arguments[2]));
348 void ExternalCommandProcessor::EnableHostCheck(double, const std::vector<String>& arguments)
350 if (arguments.size() < 1)
351 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
353 Host::Ptr host = Host::GetByName(arguments[0]);
355 Log(LogInformation, "icinga", "Enabling active checks for host '" + arguments[0] + "'");
356 Service::Ptr hc = host->GetHostCheckService();
362 ObjectLock olock(hc);
364 hc->SetEnableActiveChecks(true);
368 void ExternalCommandProcessor::DisableHostCheck(double, const std::vector<String>& arguments)
370 if (arguments.size() < 1)
371 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
373 Host::Ptr host = Host::GetByName(arguments[0]);
375 Log(LogInformation, "icinga", "Disabling active checks for host '" + arguments[0] + "'");
376 Service::Ptr hc = host->GetHostCheckService();
382 ObjectLock olock(hc);
384 hc->SetEnableActiveChecks(false);
388 void ExternalCommandProcessor::EnableSvcCheck(double, const std::vector<String>& arguments)
390 if (arguments.size() < 2)
391 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments."));
393 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
395 Log(LogInformation, "icinga", "Enabling active checks for service '" + arguments[1] + "'");
398 ObjectLock olock(service);
400 service->SetEnableActiveChecks(true);
404 void ExternalCommandProcessor::DisableSvcCheck(double, const std::vector<String>& arguments)
406 if (arguments.size() < 2)
407 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments."));
409 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
411 Log(LogInformation, "icinga", "Disabling active checks for service '" + arguments[1] + "'");
414 ObjectLock olock(service);
416 service->SetEnableActiveChecks(false);
420 void ExternalCommandProcessor::ShutdownProcess(double, const std::vector<String>&)
422 Log(LogInformation, "icinga", "Shutting down Icinga via external command.");
423 Application::RequestShutdown();
426 void ExternalCommandProcessor::RestartProcess(double, const std::vector<String>&)
428 Log(LogInformation, "icinga", "Restarting Icinga via external command.");
429 Application::RequestRestart();
432 void ExternalCommandProcessor::ScheduleForcedHostSvcChecks(double, const std::vector<String>& arguments)
434 if (arguments.size() < 2)
435 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments."));
437 double planned_check = Convert::ToDouble(arguments[1]);
439 Host::Ptr host = Host::GetByName(arguments[0]);
441 BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
442 Log(LogInformation, "icinga", "Rescheduling next check for service '" + service->GetName() + "'");
445 ObjectLock olock(service);
447 service->SetNextCheck(planned_check);
448 service->SetForceNextCheck(true);
453 void ExternalCommandProcessor::ScheduleHostSvcChecks(double, const std::vector<String>& arguments)
455 if (arguments.size() < 2)
456 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments."));
458 double planned_check = Convert::ToDouble(arguments[1]);
460 Host::Ptr host = Host::GetByName(arguments[0]);
462 if (planned_check < Utility::GetTime())
463 planned_check = Utility::GetTime();
465 BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
466 if (planned_check > service->GetNextCheck()) {
467 Log(LogInformation, "icinga", "Ignoring reschedule request for service '" +
468 service->GetName() + "' (next check is already sooner than requested check time)");
472 Log(LogInformation, "icinga", "Rescheduling next check for service '" + service->GetName() + "'");
475 ObjectLock olock(service);
477 service->SetNextCheck(planned_check);
482 void ExternalCommandProcessor::EnableHostSvcChecks(double, const std::vector<String>& arguments)
484 if (arguments.size() < 1)
485 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
487 Host::Ptr host = Host::GetByName(arguments[0]);
489 BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
490 Log(LogInformation, "icinga", "Enabling active checks for service '" + service->GetName() + "'");
491 service->SetEnableActiveChecks(true);
495 void ExternalCommandProcessor::DisableHostSvcChecks(double, const std::vector<String>& arguments)
497 if (arguments.size() < 1)
498 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 arguments."));
500 Host::Ptr host = Host::GetByName(arguments[0]);
502 BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
503 Log(LogInformation, "icinga", "Disabling active checks for service '" + service->GetName() + "'");
506 ObjectLock olock(service);
508 service->SetEnableActiveChecks(false);
513 void ExternalCommandProcessor::AcknowledgeSvcProblem(double, const std::vector<String>& arguments)
515 if (arguments.size() < 7)
516 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 7 arguments."));
518 bool sticky = Convert::ToBool(arguments[2]);
520 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
522 if (service->GetState() == StateOK)
523 BOOST_THROW_EXCEPTION(std::invalid_argument("The service '" + arguments[1] + "' is OK."));
525 Log(LogInformation, "icinga", "Setting acknowledgement for service '" + service->GetName() + "'");
527 service->AddComment(CommentAcknowledgement, arguments[5], arguments[6], 0);
528 service->AcknowledgeProblem(arguments[5], arguments[6], sticky ? AcknowledgementSticky : AcknowledgementNormal);
531 void ExternalCommandProcessor::AcknowledgeSvcProblemExpire(double, const std::vector<String>& arguments)
533 if (arguments.size() < 8)
534 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 8 arguments."));
536 bool sticky = Convert::ToBool(arguments[2]);
537 double timestamp = Convert::ToDouble(arguments[5]);
539 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
541 if (service->GetState() == StateOK)
542 BOOST_THROW_EXCEPTION(std::invalid_argument("The service '" + arguments[1] + "' is OK."));
544 Log(LogInformation, "icinga", "Setting timed acknowledgement for service '" + service->GetName() + "'");
546 service->AddComment(CommentAcknowledgement, arguments[6], arguments[7], 0);
547 service->AcknowledgeProblem(arguments[6], arguments[7], sticky ? AcknowledgementSticky : AcknowledgementNormal, timestamp);
550 void ExternalCommandProcessor::RemoveSvcAcknowledgement(double, const std::vector<String>& arguments)
552 if (arguments.size() < 2)
553 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments."));
555 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
557 Log(LogInformation, "icinga", "Removing acknowledgement for service '" + service->GetName() + "'");
559 service->ClearAcknowledgement();
562 void ExternalCommandProcessor::AcknowledgeHostProblem(double, const std::vector<String>& arguments)
564 if (arguments.size() < 6)
565 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 6 arguments."));
567 bool sticky = Convert::ToBool(arguments[1]);
569 Host::Ptr host = Host::GetByName(arguments[0]);
571 Log(LogInformation, "icinga", "Setting acknowledgement for host '" + host->GetName() + "'");
572 Service::Ptr service = host->GetHostCheckService();
574 if (service->GetState() == StateOK)
575 BOOST_THROW_EXCEPTION(std::invalid_argument("The host '" + arguments[0] + "' is OK."));
577 service->AddComment(CommentAcknowledgement, arguments[4], arguments[5], 0);
578 service->AcknowledgeProblem(arguments[4], arguments[5], sticky ? AcknowledgementSticky : AcknowledgementNormal);
582 void ExternalCommandProcessor::AcknowledgeHostProblemExpire(double, const std::vector<String>& arguments)
584 if (arguments.size() < 7)
585 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 7 arguments."));
587 bool sticky = Convert::ToBool(arguments[1]);
588 double timestamp = Convert::ToDouble(arguments[4]);
590 Host::Ptr host = Host::GetByName(arguments[0]);
592 Log(LogInformation, "icinga", "Setting timed acknowledgement for host '" + host->GetName() + "'");
593 Service::Ptr service = host->GetHostCheckService();
595 if (service->GetState() == StateOK)
596 BOOST_THROW_EXCEPTION(std::invalid_argument("The host '" + arguments[0] + "' is OK."));
598 service->AddComment(CommentAcknowledgement, arguments[5], arguments[6], 0);
599 service->AcknowledgeProblem(arguments[5], arguments[6], sticky ? AcknowledgementSticky : AcknowledgementNormal, timestamp);
603 void ExternalCommandProcessor::RemoveHostAcknowledgement(double, const std::vector<String>& arguments)
605 if (arguments.size() < 1)
606 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
608 Host::Ptr host = Host::GetByName(arguments[0]);
610 Log(LogInformation, "icinga", "Removing acknowledgement for host '" + host->GetName() + "'");
611 Service::Ptr service = host->GetHostCheckService();
613 service->ClearAcknowledgement();
616 void ExternalCommandProcessor::EnableHostgroupSvcChecks(double, const std::vector<String>& arguments)
618 if (arguments.size() < 1)
619 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
621 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
623 BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
624 BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
625 Log(LogInformation, "icinga", "Enabling active checks for service '" + service->GetName() + "'");
628 ObjectLock olock(service);
630 service->SetEnableActiveChecks(true);
636 void ExternalCommandProcessor::DisableHostgroupSvcChecks(double, const std::vector<String>& arguments)
638 if (arguments.size() < 1)
639 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
641 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
643 BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
644 BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
645 Log(LogInformation, "icinga", "Disabling active checks for service '" + service->GetName() + "'");
648 ObjectLock olock(service);
650 service->SetEnableActiveChecks(false);
656 void ExternalCommandProcessor::EnableServicegroupSvcChecks(double, const std::vector<String>& arguments)
658 if (arguments.size() < 1)
659 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
661 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
663 BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
664 Log(LogInformation, "icinga", "Enabling active checks for service '" + service->GetName() + "'");
667 ObjectLock olock(service);
669 service->SetEnableActiveChecks(true);
674 void ExternalCommandProcessor::DisableServicegroupSvcChecks(double, const std::vector<String>& arguments)
676 if (arguments.size() < 1)
677 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
679 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
681 BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
682 Log(LogInformation, "icinga", "Disabling active checks for service '" + service->GetName() + "'");
685 ObjectLock olock(service);
687 service->SetEnableActiveChecks(false);
692 void ExternalCommandProcessor::EnablePassiveHostChecks(double, const std::vector<String>& arguments)
694 if (arguments.size() < 1)
695 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
697 Host::Ptr host = Host::GetByName(arguments[0]);
699 Log(LogInformation, "icinga", "Enabling passive checks for host '" + arguments[0] + "'");
700 Service::Ptr hc = host->GetHostCheckService();
706 ObjectLock olock(hc);
708 hc->SetEnablePassiveChecks(true);
712 void ExternalCommandProcessor::DisablePassiveHostChecks(double, const std::vector<String>& arguments)
714 if (arguments.size() < 1)
715 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 arguments."));
717 Host::Ptr host = Host::GetByName(arguments[0]);
719 Log(LogInformation, "icinga", "Disabling passive checks for host '" + arguments[0] + "'");
720 Service::Ptr hc = host->GetHostCheckService();
726 ObjectLock olock(hc);
728 hc->SetEnablePassiveChecks(false);
732 void ExternalCommandProcessor::EnablePassiveSvcChecks(double, const std::vector<String>& arguments)
734 if (arguments.size() < 2)
735 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments."));
737 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
739 Log(LogInformation, "icinga", "Enabling passive checks for service '" + arguments[1] + "'");
742 ObjectLock olock(service);
744 service->SetEnablePassiveChecks(true);
748 void ExternalCommandProcessor::DisablePassiveSvcChecks(double, const std::vector<String>& arguments)
750 if (arguments.size() < 2)
751 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments."));
753 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
755 Log(LogInformation, "icinga", "Disabling passive checks for service '" + arguments[1] + "'");
758 ObjectLock olock(service);
760 service->SetEnablePassiveChecks(false);
764 void ExternalCommandProcessor::EnableServicegroupPassiveSvcChecks(double, const std::vector<String>& arguments)
766 if (arguments.size() < 1)
767 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
769 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
771 BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
772 Log(LogInformation, "icinga", "Enabling passive checks for service '" + service->GetName() + "'");
775 ObjectLock olock(service);
777 service->SetEnablePassiveChecks(true);
782 void ExternalCommandProcessor::DisableServicegroupPassiveSvcChecks(double, const std::vector<String>& arguments)
784 if (arguments.size() < 1)
785 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
787 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
789 BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
790 Log(LogInformation, "icinga", "Disabling passive checks for service '" + service->GetName() + "'");
793 ObjectLock olock(service);
795 service->SetEnablePassiveChecks(true);
800 void ExternalCommandProcessor::EnableHostgroupPassiveSvcChecks(double, const std::vector<String>& arguments)
802 if (arguments.size() < 1)
803 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
805 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
807 BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
808 BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
809 Log(LogInformation, "icinga", "Enabling passive checks for service '" + service->GetName() + "'");
812 ObjectLock olock(service);
814 service->SetEnablePassiveChecks(true);
820 void ExternalCommandProcessor::DisableHostgroupPassiveSvcChecks(double, const std::vector<String>& arguments)
822 if (arguments.size() < 1)
823 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
825 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
827 BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
828 BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
829 Log(LogInformation, "icinga", "Disabling passive checks for service '" + service->GetName() + "'");
832 ObjectLock olock(service);
834 service->SetEnablePassiveChecks(false);
840 void ExternalCommandProcessor::ProcessFile(double, const std::vector<String>& arguments)
842 if (arguments.size() < 2)
843 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments."));
845 String file = arguments[0];
846 bool del = Convert::ToBool(arguments[1]);
849 ifp.exceptions(std::ifstream::badbit);
851 ifp.open(file.CStr(), std::ifstream::in);
855 std::getline(ifp, line);
858 Log(LogInformation, "compat", "Executing external command: " + line);
861 } catch (const std::exception& ex) {
862 std::ostringstream msgbuf;
863 msgbuf << "External command failed: " << boost::diagnostic_information(ex);
864 Log(LogWarning, "icinga", msgbuf.str());
871 (void) unlink(file.CStr());
874 void ExternalCommandProcessor::ScheduleSvcDowntime(double, const std::vector<String>& arguments)
876 if (arguments.size() < 9)
877 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 9 arguments."));
879 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
882 int triggeredByLegacy = Convert::ToLong(arguments[5]);
883 if (triggeredByLegacy != 0)
884 triggeredBy = Service::GetDowntimeIDFromLegacyID(triggeredByLegacy);
886 Log(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
887 String comment_id = service->AddComment(CommentDowntime, arguments[7], arguments[8], Convert::ToDouble(arguments[3]));
888 (void) service->AddDowntime(comment_id,
889 Convert::ToDouble(arguments[2]), Convert::ToDouble(arguments[3]),
890 Convert::ToBool(arguments[4]), triggeredBy, Convert::ToDouble(arguments[6]));
893 void ExternalCommandProcessor::DelSvcDowntime(double, const std::vector<String>& arguments)
895 if (arguments.size() < 1)
896 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
898 int id = Convert::ToLong(arguments[0]);
899 Log(LogInformation, "icinga", "Removing downtime ID " + arguments[0]);
900 String rid = Service::GetDowntimeIDFromLegacyID(id);
901 Service::RemoveDowntime(rid);
904 void ExternalCommandProcessor::ScheduleHostDowntime(double, const std::vector<String>& arguments)
906 if (arguments.size() < 8)
907 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 8 arguments."));
909 Host::Ptr host = Host::GetByName(arguments[0]);
912 int triggeredByLegacy = Convert::ToLong(arguments[4]);
913 if (triggeredByLegacy != 0)
914 triggeredBy = Service::GetDowntimeIDFromLegacyID(triggeredByLegacy);
916 Log(LogInformation, "icinga", "Creating downtime for host " + host->GetName());
917 Service::Ptr service = host->GetHostCheckService();
919 String comment_id = service->AddComment(CommentDowntime, arguments[6], arguments[7], Convert::ToDouble(arguments[2]));
920 (void) service->AddDowntime(comment_id,
921 Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
922 Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
926 void ExternalCommandProcessor::DelHostDowntime(double, const std::vector<String>& arguments)
928 if (arguments.size() < 1)
929 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
931 int id = Convert::ToLong(arguments[0]);
932 Log(LogInformation, "icinga", "Removing downtime ID " + arguments[0]);
933 String rid = Service::GetDowntimeIDFromLegacyID(id);
934 Service::RemoveDowntime(rid);
937 void ExternalCommandProcessor::ScheduleHostSvcDowntime(double, const std::vector<String>& arguments)
939 if (arguments.size() < 8)
940 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 8 argument."));
942 Host::Ptr host = Host::GetByName(arguments[0]);
945 int triggeredByLegacy = Convert::ToLong(arguments[4]);
946 if (triggeredByLegacy != 0)
947 triggeredBy = Service::GetDowntimeIDFromLegacyID(triggeredByLegacy);
949 BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
950 Log(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
951 String comment_id = service->AddComment(CommentDowntime, arguments[6], arguments[7], Convert::ToDouble(arguments[2]));
952 (void) service->AddDowntime(comment_id,
953 Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
954 Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
958 void ExternalCommandProcessor::ScheduleHostgroupHostDowntime(double, const std::vector<String>& arguments)
960 if (arguments.size() < 8)
961 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 8 arguments."));
963 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
966 int triggeredByLegacy = Convert::ToLong(arguments[4]);
967 if (triggeredByLegacy != 0)
968 triggeredBy = Service::GetDowntimeIDFromLegacyID(triggeredByLegacy);
970 BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
971 Log(LogInformation, "icinga", "Creating downtime for host " + host->GetName());
972 Service::Ptr service = host->GetHostCheckService();
974 String comment_id = service->AddComment(CommentDowntime, arguments[6], arguments[7], Convert::ToDouble(arguments[2]));
975 (void) service->AddDowntime(comment_id,
976 Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
977 Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
982 void ExternalCommandProcessor::ScheduleHostgroupSvcDowntime(double, const std::vector<String>& arguments)
984 if (arguments.size() < 8)
985 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 8 arguments."));
987 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
990 int triggeredByLegacy = Convert::ToLong(arguments[4]);
991 if (triggeredByLegacy != 0)
992 triggeredBy = Service::GetDowntimeIDFromLegacyID(triggeredByLegacy);
994 /* Note: we can't just directly create downtimes for all the services by iterating
995 * over all hosts in the host group - otherwise we might end up creating multiple
996 * downtimes for some services. */
998 std::set<Service::Ptr> services;
1000 BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
1001 BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
1002 services.insert(service);
1006 BOOST_FOREACH(const Service::Ptr& service, services) {
1007 Log(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
1008 String comment_id = service->AddComment(CommentDowntime, arguments[6], arguments[7], Convert::ToDouble(arguments[2]));
1009 (void) service->AddDowntime(comment_id,
1010 Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
1011 Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
1015 void ExternalCommandProcessor::ScheduleServicegroupHostDowntime(double, const std::vector<String>& arguments)
1017 if (arguments.size() < 8)
1018 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 8 arguments."));
1020 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
1023 int triggeredByLegacy = Convert::ToLong(arguments[4]);
1024 if (triggeredByLegacy != 0)
1025 triggeredBy = Service::GetDowntimeIDFromLegacyID(triggeredByLegacy);
1027 /* Note: we can't just directly create downtimes for all the hosts by iterating
1028 * over all services in the service group - otherwise we might end up creating multiple
1029 * downtimes for some hosts. */
1031 std::set<Service::Ptr> services;
1033 BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
1034 Host::Ptr host = service->GetHost();
1035 Service::Ptr hcService = host->GetHostCheckService();
1037 services.insert(hcService);
1040 BOOST_FOREACH(const Service::Ptr& service, services) {
1041 Log(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
1042 String comment_id = service->AddComment(CommentDowntime, arguments[6], arguments[7], Convert::ToDouble(arguments[2]));
1043 (void) service->AddDowntime(comment_id,
1044 Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
1045 Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
1049 void ExternalCommandProcessor::ScheduleServicegroupSvcDowntime(double, const std::vector<String>& arguments)
1051 if (arguments.size() < 8)
1052 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 8 arguments."));
1054 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
1057 int triggeredByLegacy = Convert::ToLong(arguments[4]);
1058 if (triggeredByLegacy != 0)
1059 triggeredBy = Service::GetDowntimeIDFromLegacyID(triggeredByLegacy);
1061 BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
1062 Log(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
1063 String comment_id = service->AddComment(CommentDowntime, arguments[6], arguments[7], Convert::ToDouble(arguments[2]));
1064 (void) service->AddDowntime(comment_id,
1065 Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
1066 Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
1070 void ExternalCommandProcessor::AddHostComment(double, const std::vector<String>& arguments)
1072 if (arguments.size() < 4)
1073 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 4 arguments."));
1075 Host::Ptr host = Host::GetByName(arguments[0]);
1077 Log(LogInformation, "icinga", "Creating comment for host " + host->GetName());
1078 Service::Ptr service = host->GetHostCheckService();
1080 (void) service->AddComment(CommentUser, arguments[2], arguments[3], 0);
1083 void ExternalCommandProcessor::DelHostComment(double, const std::vector<String>& arguments)
1085 if (arguments.size() < 1)
1086 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
1088 int id = Convert::ToLong(arguments[0]);
1089 Log(LogInformation, "icinga", "Removing comment ID " + arguments[0]);
1090 String rid = Service::GetCommentIDFromLegacyID(id);
1091 Service::RemoveComment(rid);
1094 void ExternalCommandProcessor::AddSvcComment(double, const std::vector<String>& arguments)
1096 if (arguments.size() < 5)
1097 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 5 arguments."));
1099 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1101 Log(LogInformation, "icinga", "Creating comment for service " + service->GetName());
1102 (void) service->AddComment(CommentUser, arguments[3], arguments[4], 0);
1105 void ExternalCommandProcessor::DelSvcComment(double, const std::vector<String>& arguments)
1107 if (arguments.size() < 1)
1108 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
1110 int id = Convert::ToLong(arguments[0]);
1111 Log(LogInformation, "icinga", "Removing comment ID " + arguments[0]);
1113 String rid = Service::GetCommentIDFromLegacyID(id);
1114 Service::RemoveComment(rid);
1117 void ExternalCommandProcessor::DelAllHostComments(double, const std::vector<String>& arguments)
1119 if (arguments.size() < 1)
1120 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
1122 Host::Ptr host = Host::GetByName(arguments[0]);
1124 Log(LogInformation, "icinga", "Removing all comments for host " + host->GetName());
1125 Service::Ptr service = host->GetHostCheckService();
1127 service->RemoveAllComments();
1130 void ExternalCommandProcessor::DelAllSvcComments(double, const std::vector<String>& arguments)
1132 if (arguments.size() < 2)
1133 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments."));
1135 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1137 Log(LogInformation, "icinga", "Removing all comments for service " + service->GetName());
1138 service->RemoveAllComments();
1141 void ExternalCommandProcessor::SendCustomHostNotification(double, const std::vector<String>& arguments)
1143 if (arguments.size() < 4)
1144 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 4 arguments."));
1146 Host::Ptr host = Host::GetByName(arguments[0]);
1147 int options = Convert::ToLong(arguments[1]);
1149 Log(LogInformation, "icinga", "Sending custom notification for host " + host->GetName());
1150 Service::Ptr service = host->GetHostCheckService();
1153 ObjectLock olock(service);
1154 service->SetForceNextNotification(true);
1157 Service::OnNotificationsRequested(service, NotificationCustom, service->GetLastCheckResult(), arguments[2], arguments[3]);
1161 void ExternalCommandProcessor::SendCustomSvcNotification(double, const std::vector<String>& arguments)
1163 if (arguments.size() < 5)
1164 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 5 arguments."));
1166 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1167 int options = Convert::ToLong(arguments[2]);
1169 Log(LogInformation, "icinga", "Sending custom notification for service " + service->GetName());
1172 ObjectLock olock(service);
1173 service->SetForceNextNotification(true);
1176 Service::OnNotificationsRequested(service, NotificationCustom, service->GetLastCheckResult(), arguments[3], arguments[4]);
1179 void ExternalCommandProcessor::DelayHostNotification(double, const std::vector<String>& arguments)
1181 if (arguments.size() < 2)
1182 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments."));
1184 Host::Ptr host = Host::GetByName(arguments[0]);
1186 Log(LogInformation, "icinga", "Delaying notifications for host " + host->GetName());
1187 Service::Ptr hc = host->GetHostCheckService();
1191 BOOST_FOREACH(const Notification::Ptr& notification, hc->GetNotifications()) {
1192 ObjectLock olock(notification);
1194 notification->SetNextNotification(Convert::ToDouble(arguments[1]));
1198 void ExternalCommandProcessor::DelaySvcNotification(double, const std::vector<String>& arguments)
1200 if (arguments.size() < 3)
1201 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 3 arguments."));
1203 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1205 Log(LogInformation, "icinga", "Delaying notifications for service " + service->GetName());
1207 BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
1208 ObjectLock olock(notification);
1210 notification->SetNextNotification(Convert::ToDouble(arguments[2]));
1214 void ExternalCommandProcessor::EnableHostNotifications(double, const std::vector<String>& arguments)
1216 if (arguments.size() < 1)
1217 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
1219 Host::Ptr host = Host::GetByName(arguments[0]);
1221 Log(LogInformation, "icinga", "Enabling notifications for host '" + arguments[0] + "'");
1222 Service::Ptr hc = host->GetHostCheckService();
1228 ObjectLock olock(hc);
1230 hc->SetEnableNotifications(true);
1234 void ExternalCommandProcessor::DisableHostNotifications(double, const std::vector<String>& arguments)
1236 if (arguments.size() < 1)
1237 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
1239 Host::Ptr host = Host::GetByName(arguments[0]);
1241 Log(LogInformation, "icinga", "Disabling notifications for host '" + arguments[0] + "'");
1242 Service::Ptr hc = host->GetHostCheckService();
1248 ObjectLock olock(hc);
1250 hc->SetEnableNotifications(false);
1254 void ExternalCommandProcessor::EnableSvcNotifications(double, const std::vector<String>& arguments)
1256 if (arguments.size() < 2)
1257 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments."));
1259 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1261 Log(LogInformation, "icinga", "Enabling notifications for service '" + arguments[1] + "'");
1264 ObjectLock olock(service);
1266 service->SetEnableNotifications(true);
1270 void ExternalCommandProcessor::DisableSvcNotifications(double, const std::vector<String>& arguments)
1272 if (arguments.size() < 2)
1273 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments."));
1275 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1277 Log(LogInformation, "icinga", "Disabling notifications for service '" + arguments[1] + "'");
1280 ObjectLock olock(service);
1282 service->SetEnableNotifications(false);
1286 void ExternalCommandProcessor::DisableHostgroupHostChecks(double, const std::vector<String>& arguments)
1288 if (arguments.size() < 1)
1289 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 arguments."));
1291 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
1293 BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
1294 Service::Ptr hc = host->GetHostCheckService();
1299 Log(LogInformation, "icinga", "Disabling active checks for host '" + host->GetName() + "'");
1302 ObjectLock olock(hc);
1304 hc->SetEnableActiveChecks(false);
1309 void ExternalCommandProcessor::DisableHostgroupPassiveHostChecks(double, const std::vector<String>& arguments)
1311 if (arguments.size() < 1)
1312 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 arguments."));
1314 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
1316 BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
1317 Service::Ptr hc = host->GetHostCheckService();
1322 Log(LogInformation, "icinga", "Disabling active checks for host '" + host->GetName() + "'");
1325 ObjectLock olock(hc);
1327 hc->SetEnablePassiveChecks(false);
1332 void ExternalCommandProcessor::DisableServicegroupHostChecks(double, const std::vector<String>& arguments)
1334 if (arguments.size() < 1)
1335 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 arguments."));
1337 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
1339 BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
1340 Host::Ptr host = service->GetHost();
1345 Service::Ptr hc = host->GetHostCheckService();
1350 Log(LogInformation, "icinga", "Disabling active checks for host '" + host->GetName() + "'");
1353 ObjectLock olock(hc);
1355 hc->SetEnableActiveChecks(false);
1360 void ExternalCommandProcessor::DisableServicegroupPassiveHostChecks(double, const std::vector<String>& arguments)
1362 if (arguments.size() < 1)
1363 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 arguments."));
1365 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
1367 BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
1368 Host::Ptr host = service->GetHost();
1373 Service::Ptr hc = host->GetHostCheckService();
1378 Log(LogInformation, "icinga", "Disabling active checks for host '" + host->GetName() + "'");
1381 ObjectLock olock(hc);
1383 hc->SetEnablePassiveChecks(false);
1388 void ExternalCommandProcessor::EnableHostgroupHostChecks(double, const std::vector<String>& arguments)
1390 if (arguments.size() < 1)
1391 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 arguments."));
1393 HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
1395 BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
1396 Service::Ptr hc = host->GetHostCheckService();
1401 Log(LogInformation, "icinga", "Enabling active checks for host '" + host->GetName() + "'");
1404 ObjectLock olock(hc);
1406 hc->SetEnableActiveChecks(true);
1411 void ExternalCommandProcessor::EnableHostgroupPassiveHostChecks(double, const std::vector<String>& arguments)
1413 if (arguments.size() < 1)
1414 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 arguments."));
1418 void ExternalCommandProcessor::EnableServicegroupHostChecks(double, const std::vector<String>& arguments)
1420 if (arguments.size() < 1)
1421 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 arguments."));
1423 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
1425 BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
1426 Host::Ptr host = service->GetHost();
1431 Service::Ptr hc = host->GetHostCheckService();
1436 Log(LogInformation, "icinga", "Enabling active checks for host '" + host->GetName() + "'");
1439 ObjectLock olock(hc);
1441 hc->SetEnableActiveChecks(true);
1446 void ExternalCommandProcessor::EnableServicegroupPassiveHostChecks(double, const std::vector<String>& arguments)
1448 if (arguments.size() < 1)
1449 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 arguments."));
1451 ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
1453 BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
1454 Host::Ptr host = service->GetHost();
1459 Service::Ptr hc = host->GetHostCheckService();
1464 Log(LogInformation, "icinga", "Enabling active checks for host '" + host->GetName() + "'");
1467 ObjectLock olock(hc);
1469 hc->SetEnablePassiveChecks(false);
1474 void ExternalCommandProcessor::EnableHostFlapping(double, const std::vector<String>& arguments)
1476 if (arguments.size() < 1)
1477 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
1479 Host::Ptr host = Host::GetByName(arguments[0]);
1481 Log(LogInformation, "icinga", "Enabling flapping detection for host '" + arguments[0] + "'");
1482 Service::Ptr hc = host->GetHostCheckService();
1488 ObjectLock olock(hc);
1490 hc->SetEnableFlapping(true);
1494 void ExternalCommandProcessor::DisableHostFlapping(double, const std::vector<String>& arguments)
1496 if (arguments.size() < 1)
1497 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
1499 Host::Ptr host = Host::GetByName(arguments[0]);
1501 Log(LogInformation, "icinga", "Disabling flapping detection for host '" + arguments[0] + "'");
1502 Service::Ptr hc = host->GetHostCheckService();
1508 ObjectLock olock(hc);
1510 hc->SetEnableFlapping(false);
1514 void ExternalCommandProcessor::EnableSvcFlapping(double, const std::vector<String>& arguments)
1516 if (arguments.size() < 2)
1517 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments."));
1519 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1521 Log(LogInformation, "icinga", "Enabling flapping detection for service '" + arguments[1] + "'");
1524 ObjectLock olock(service);
1526 service->SetEnableFlapping(true);
1530 void ExternalCommandProcessor::DisableSvcFlapping(double, const std::vector<String>& arguments)
1532 if (arguments.size() < 2)
1533 BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments."));
1535 Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
1537 Log(LogInformation, "icinga", "Disabling flapping detection for service '" + arguments[1] + "'");
1540 ObjectLock olock(service);
1542 service->SetEnableFlapping(false);