2013-01-22 08:34:29 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
|
|
|
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 2 *
|
|
|
|
* of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software Foundation *
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#include "i2-icinga.h"
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2013-01-29 15:00:39 +01:00
|
|
|
bool I2_EXPORT ExternalCommandProcessor::m_Initialized;
|
|
|
|
map<String, ExternalCommandProcessor::Callback> I2_EXPORT ExternalCommandProcessor::m_Commands;
|
2013-01-22 08:34:29 +01:00
|
|
|
|
2013-01-29 15:00:39 +01:00
|
|
|
void ExternalCommandProcessor::Execute(const String& line)
|
2013-01-24 23:42:02 +01:00
|
|
|
{
|
|
|
|
if (line.IsEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (line[0] != '[')
|
|
|
|
throw_exception(invalid_argument("Missing timestamp in command: " + line));
|
|
|
|
|
|
|
|
size_t pos = line.FindFirstOf("]");
|
|
|
|
|
|
|
|
if (pos == String::NPos)
|
|
|
|
throw_exception(invalid_argument("Missing timestamp in command: " + line));
|
|
|
|
|
|
|
|
String timestamp = line.SubStr(1, pos - 1);
|
|
|
|
String args = line.SubStr(pos + 2, String::NPos);
|
|
|
|
|
2013-01-29 12:05:46 +01:00
|
|
|
double ts = Convert::ToDouble(timestamp);
|
2013-01-24 23:42:02 +01:00
|
|
|
|
|
|
|
if (ts == 0)
|
|
|
|
throw_exception(invalid_argument("Invalid timestamp in command: " + line));
|
|
|
|
|
|
|
|
vector<String> argv = args.Split(is_any_of(";"));
|
|
|
|
|
|
|
|
if (argv.size() == 0)
|
|
|
|
throw_exception(invalid_argument("Missing arguments in command: " + line));
|
|
|
|
|
|
|
|
vector<String> argvExtra(argv.begin() + 1, argv.end());
|
|
|
|
Execute(ts, argv[0], argvExtra);
|
|
|
|
}
|
|
|
|
|
2013-01-29 15:00:39 +01:00
|
|
|
void ExternalCommandProcessor::Execute(double time, const String& command, const vector<String>& arguments)
|
2013-01-22 08:34:29 +01:00
|
|
|
{
|
|
|
|
if (!m_Initialized) {
|
2013-01-29 15:00:39 +01:00
|
|
|
RegisterCommand("PROCESS_SERVICE_CHECK_RESULT", &ExternalCommandProcessor::ProcessServiceCheckResult);
|
|
|
|
RegisterCommand("SCHEDULE_SVC_CHECK", &ExternalCommandProcessor::ScheduleSvcCheck);
|
|
|
|
RegisterCommand("SCHEDULE_FORCED_SVC_CHECK", &ExternalCommandProcessor::ScheduleForcedSvcCheck);
|
|
|
|
RegisterCommand("ENABLE_SVC_CHECK", &ExternalCommandProcessor::EnableSvcCheck);
|
|
|
|
RegisterCommand("DISABLE_SVC_CHECK", &ExternalCommandProcessor::DisableSvcCheck);
|
|
|
|
RegisterCommand("SHUTDOWN_PROCESS", &ExternalCommandProcessor::ShutdownProcess);
|
|
|
|
RegisterCommand("SCHEDULE_FORCED_HOST_SVC_CHECKS", &ExternalCommandProcessor::ScheduleForcedHostSvcChecks);
|
|
|
|
RegisterCommand("SCHEDULE_HOST_SVC_CHECKS", &ExternalCommandProcessor::ScheduleHostSvcChecks);
|
|
|
|
RegisterCommand("ENABLE_HOST_SVC_CHECKS", &ExternalCommandProcessor::EnableHostSvcChecks);
|
|
|
|
RegisterCommand("DISABLE_HOST_SVC_CHECKS", &ExternalCommandProcessor::DisableHostSvcChecks);
|
|
|
|
RegisterCommand("ACKNOWLEDGE_SVC_PROBLEM", &ExternalCommandProcessor::AcknowledgeSvcProblem);
|
|
|
|
RegisterCommand("ACKNOWLEDGE_SVC_PROBLEM_EXPIRE", &ExternalCommandProcessor::AcknowledgeSvcProblemExpire);
|
|
|
|
RegisterCommand("REMOVE_SVC_ACKNOWLEDGEMENT", &ExternalCommandProcessor::RemoveHostAcknowledgement);
|
|
|
|
RegisterCommand("ACKNOWLEDGE_HOST_PROBLEM", &ExternalCommandProcessor::AcknowledgeHostProblem);
|
|
|
|
RegisterCommand("ACKNOWLEDGE_HOST_PROBLEM_EXPIRE", &ExternalCommandProcessor::AcknowledgeHostProblemExpire);
|
|
|
|
RegisterCommand("REMOVE_HOST_ACKNOWLEDGEMENT", &ExternalCommandProcessor::RemoveHostAcknowledgement);
|
|
|
|
RegisterCommand("ENABLE_HOSTGROUP_SVC_CHECKS", &ExternalCommandProcessor::EnableHostgroupSvcChecks);
|
|
|
|
RegisterCommand("DISABLE_HOSTGROUP_SVC_CHECKS", &ExternalCommandProcessor::DisableHostgroupSvcChecks);
|
|
|
|
RegisterCommand("ENABLE_SERVICEGROUP_SVC_CHECKS", &ExternalCommandProcessor::EnableServicegroupSvcChecks);
|
|
|
|
RegisterCommand("DISABLE_SERVICEGROUP_SVC_CHECKS", &ExternalCommandProcessor::DisableServicegroupSvcChecks);
|
|
|
|
RegisterCommand("ENABLE_PASSIVE_SVC_CHECKS", &ExternalCommandProcessor::EnablePassiveSvcChecks);
|
|
|
|
RegisterCommand("DISABLE_PASSIVE_SVC_CHECKS", &ExternalCommandProcessor::DisablePassiveSvcChecks);
|
|
|
|
RegisterCommand("ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS", &ExternalCommandProcessor::EnableServicegroupPassiveSvcChecks);
|
|
|
|
RegisterCommand("DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS", &ExternalCommandProcessor::DisableServicegroupPassiveSvcChecks);
|
|
|
|
RegisterCommand("ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS", &ExternalCommandProcessor::EnableHostgroupPassiveSvcChecks);
|
|
|
|
RegisterCommand("DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS", &ExternalCommandProcessor::DisableHostgroupPassiveSvcChecks);
|
|
|
|
RegisterCommand("PROCESS_FILE", &ExternalCommandProcessor::ProcessFile);
|
|
|
|
RegisterCommand("SCHEDULE_SVC_DOWNTIME", &ExternalCommandProcessor::ScheduleSvcDowntime);
|
|
|
|
RegisterCommand("DEL_SVC_DOWNTIME", &ExternalCommandProcessor::DelSvcDowntime);
|
|
|
|
RegisterCommand("SCHEDULE_HOST_DOWNTIME", &ExternalCommandProcessor::ScheduleHostDowntime);
|
|
|
|
RegisterCommand("DEL_HOST_DOWNTIME", &ExternalCommandProcessor::DelHostDowntime);
|
|
|
|
RegisterCommand("SCHEDULE_HOST_SVC_DOWNTIME", &ExternalCommandProcessor::ScheduleHostSvcDowntime);
|
|
|
|
RegisterCommand("SCHEDULE_HOSTGROUP_HOST_DOWNTIME", &ExternalCommandProcessor::ScheduleHostgroupHostDowntime);
|
|
|
|
RegisterCommand("SCHEDULE_HOSTGROUP_SVC_DOWNTIME", &ExternalCommandProcessor::ScheduleHostgroupSvcDowntime);
|
|
|
|
RegisterCommand("SCHEDULE_SERVICEGROUP_HOST_DOWNTIME", &ExternalCommandProcessor::ScheduleServicegroupHostDowntime);
|
|
|
|
RegisterCommand("SCHEDULE_SERVICEGROUP_SVC_DOWNTIME", &ExternalCommandProcessor::ScheduleServicegroupSvcDowntime);
|
2013-01-29 16:29:09 +01:00
|
|
|
RegisterCommand("ADD_HOST_COMMENT", &ExternalCommandProcessor::AddHostComment);
|
|
|
|
RegisterCommand("DEL_HOST_COMMENT", &ExternalCommandProcessor::DelHostComment);
|
|
|
|
RegisterCommand("ADD_SVC_COMMENT", &ExternalCommandProcessor::AddSvcComment);
|
|
|
|
RegisterCommand("DEL_SVC_COMMENT", &ExternalCommandProcessor::DelSvcComment);
|
|
|
|
RegisterCommand("DEL_ALL_HOST_COMMENTS", &ExternalCommandProcessor::DelAllHostComments);
|
|
|
|
RegisterCommand("DEL_ALL_SVC_COMMENTS", &ExternalCommandProcessor::DelAllSvcComments);
|
2013-01-22 08:34:29 +01:00
|
|
|
|
|
|
|
m_Initialized = true;
|
|
|
|
}
|
|
|
|
|
2013-01-29 15:00:39 +01:00
|
|
|
map<String, ExternalCommandProcessor::Callback>::iterator it;
|
2013-01-22 08:34:29 +01:00
|
|
|
it = m_Commands.find(command);
|
|
|
|
|
|
|
|
if (it == m_Commands.end())
|
2013-01-22 15:13:51 +01:00
|
|
|
throw_exception(invalid_argument("The external command '" + command + "' does not exist."));
|
2013-01-22 08:34:29 +01:00
|
|
|
|
2013-01-22 15:13:51 +01:00
|
|
|
it->second(time, arguments);
|
2013-01-22 08:34:29 +01:00
|
|
|
}
|
|
|
|
|
2013-01-29 15:00:39 +01:00
|
|
|
void ExternalCommandProcessor::RegisterCommand(const String& command, const ExternalCommandProcessor::Callback& callback)
|
2013-01-22 08:34:29 +01:00
|
|
|
{
|
|
|
|
m_Commands[command] = callback;
|
|
|
|
}
|
|
|
|
|
2013-01-29 15:00:39 +01:00
|
|
|
void ExternalCommandProcessor::ProcessServiceCheckResult(double time, const vector<String>& arguments)
|
2013-01-22 12:05:36 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 4)
|
2013-01-22 15:13:51 +01:00
|
|
|
throw_exception(invalid_argument("Expected 4 arguments."));
|
2013-01-22 12:05:36 +01:00
|
|
|
|
|
|
|
if (!Service::Exists(arguments[1]))
|
2013-01-22 15:13:51 +01:00
|
|
|
throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist."));
|
2013-01-22 12:05:36 +01:00
|
|
|
|
|
|
|
Service::Ptr service = Service::GetByName(arguments[1]);
|
|
|
|
|
2013-01-24 23:10:07 +01:00
|
|
|
if (!service->GetEnablePassiveChecks())
|
|
|
|
throw_exception(invalid_argument("Got passive check result for service '" + arguments[1] + "' which has passive checks disabled."));
|
|
|
|
|
2013-01-29 12:05:46 +01:00
|
|
|
int exitStatus = Convert::ToDouble(arguments[2]);
|
2013-01-22 12:05:36 +01:00
|
|
|
Dictionary::Ptr result = PluginCheckTask::ParseCheckOutput(arguments[3]);
|
|
|
|
result->Set("state", PluginCheckTask::ExitStatusToState(exitStatus));
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
result->Set("schedule_start", time);
|
|
|
|
result->Set("schedule_end", time);
|
|
|
|
result->Set("execution_start", time);
|
|
|
|
result->Set("execution_end", time);
|
2013-01-28 09:01:47 +01:00
|
|
|
result->Set("active", 0);
|
2013-01-22 12:05:36 +01:00
|
|
|
|
2013-01-22 15:13:51 +01:00
|
|
|
Logger::Write(LogInformation, "icinga", "Processing passive check result for service '" + arguments[1] + "'");
|
2013-01-22 12:05:36 +01:00
|
|
|
service->ProcessCheckResult(result);
|
2013-01-27 12:13:45 +01:00
|
|
|
|
|
|
|
/* Reschedule the next check. The side effect of this is that for as long
|
|
|
|
* as we receive passive results for a service we won't execute any
|
|
|
|
* active checks. */
|
2013-01-28 08:31:29 +01:00
|
|
|
service->SetNextCheck(Utility::GetTime() + service->GetCheckInterval());
|
2013-01-22 12:05:36 +01:00
|
|
|
}
|
2013-01-22 12:56:29 +01:00
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::ScheduleSvcCheck(double, const vector<String>& arguments)
|
2013-01-22 12:56:29 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 3)
|
2013-01-22 15:13:51 +01:00
|
|
|
throw_exception(invalid_argument("Expected 3 arguments."));
|
2013-01-22 12:56:29 +01:00
|
|
|
|
|
|
|
if (!Service::Exists(arguments[1]))
|
2013-01-22 15:13:51 +01:00
|
|
|
throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist."));
|
2013-01-22 12:56:29 +01:00
|
|
|
|
|
|
|
Service::Ptr service = Service::GetByName(arguments[1]);
|
|
|
|
|
2013-01-29 12:05:46 +01:00
|
|
|
double planned_check = Convert::ToDouble(arguments[2]);
|
2013-01-22 12:56:29 +01:00
|
|
|
|
2013-01-22 15:13:51 +01:00
|
|
|
if (planned_check > service->GetNextCheck()) {
|
|
|
|
Logger::Write(LogInformation, "icinga", "Ignoring reschedule request for service '" +
|
|
|
|
arguments[1] + "' (next check is already sooner than requested check time)");
|
|
|
|
return;
|
|
|
|
}
|
2013-01-22 12:56:29 +01:00
|
|
|
|
2013-01-22 15:13:51 +01:00
|
|
|
Logger::Write(LogInformation, "icinga", "Rescheduling next check for service '" + arguments[1] + "'");
|
2013-01-22 12:56:29 +01:00
|
|
|
service->SetNextCheck(planned_check);
|
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::ScheduleForcedSvcCheck(double, const vector<String>& arguments)
|
2013-01-22 12:56:29 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 3)
|
2013-01-22 15:13:51 +01:00
|
|
|
throw_exception(invalid_argument("Expected 3 arguments."));
|
2013-01-22 12:56:29 +01:00
|
|
|
|
|
|
|
if (!Service::Exists(arguments[1]))
|
2013-01-22 15:13:51 +01:00
|
|
|
throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist."));
|
2013-01-22 12:56:29 +01:00
|
|
|
|
|
|
|
Service::Ptr service = Service::GetByName(arguments[1]);
|
|
|
|
|
2013-01-22 15:13:51 +01:00
|
|
|
Logger::Write(LogInformation, "icinga", "Rescheduling next check for service '" + arguments[1] + "'");
|
2013-01-22 16:01:08 +01:00
|
|
|
service->SetForceNextCheck(true);
|
2013-01-29 12:05:46 +01:00
|
|
|
service->SetNextCheck(Convert::ToDouble(arguments[2]));
|
2013-01-22 12:56:29 +01:00
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::EnableSvcCheck(double, const vector<String>& arguments)
|
2013-01-22 16:01:08 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 2)
|
|
|
|
throw_exception(invalid_argument("Expected 2 arguments."));
|
|
|
|
|
|
|
|
if (!Service::Exists(arguments[1]))
|
|
|
|
throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist."));
|
|
|
|
|
|
|
|
Service::Ptr service = Service::GetByName(arguments[1]);
|
|
|
|
|
2013-01-24 23:10:07 +01:00
|
|
|
Logger::Write(LogInformation, "icinga", "Enabling active checks for service '" + arguments[1] + "'");
|
|
|
|
service->SetEnableActiveChecks(true);
|
2013-01-22 16:01:08 +01:00
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::DisableSvcCheck(double, const vector<String>& arguments)
|
2013-01-22 16:01:08 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 2)
|
|
|
|
throw_exception(invalid_argument("Expected 2 arguments."));
|
|
|
|
|
|
|
|
if (!Service::Exists(arguments[1]))
|
|
|
|
throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist."));
|
|
|
|
|
|
|
|
Service::Ptr service = Service::GetByName(arguments[1]);
|
|
|
|
|
2013-01-24 23:10:07 +01:00
|
|
|
Logger::Write(LogInformation, "icinga", "Disabling active checks for service '" + arguments[1] + "'");
|
|
|
|
service->SetEnableActiveChecks(false);
|
2013-01-22 16:01:08 +01:00
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::ShutdownProcess(double, const vector<String>&)
|
2013-01-22 16:23:25 +01:00
|
|
|
{
|
|
|
|
Logger::Write(LogInformation, "icinga", "Shutting down Icinga via external command.");
|
|
|
|
Application::RequestShutdown();
|
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::ScheduleForcedHostSvcChecks(double, const vector<String>& arguments)
|
2013-01-23 10:42:16 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 2)
|
|
|
|
throw_exception(invalid_argument("Expected 2 arguments."));
|
|
|
|
|
|
|
|
if (!Host::Exists(arguments[0]))
|
|
|
|
throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist."));
|
|
|
|
|
2013-01-29 12:05:46 +01:00
|
|
|
double planned_check = Convert::ToDouble(arguments[1]);
|
2013-01-23 10:42:16 +01:00
|
|
|
|
|
|
|
Host::Ptr host = Host::GetByName(arguments[0]);
|
|
|
|
|
2013-01-29 14:19:54 +01:00
|
|
|
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
|
2013-01-23 10:42:16 +01:00
|
|
|
Logger::Write(LogInformation, "icinga", "Rescheduling next check for service '" + service->GetName() + "'");
|
|
|
|
service->SetNextCheck(planned_check);
|
|
|
|
service->SetForceNextCheck(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::ScheduleHostSvcChecks(double, const vector<String>& arguments)
|
2013-01-23 10:42:16 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 2)
|
|
|
|
throw_exception(invalid_argument("Expected 2 arguments."));
|
|
|
|
|
|
|
|
if (!Host::Exists(arguments[0]))
|
|
|
|
throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist."));
|
|
|
|
|
2013-01-29 12:05:46 +01:00
|
|
|
double planned_check = Convert::ToDouble(arguments[1]);
|
2013-01-23 10:42:16 +01:00
|
|
|
|
|
|
|
Host::Ptr host = Host::GetByName(arguments[0]);
|
|
|
|
|
2013-01-29 14:19:54 +01:00
|
|
|
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
|
2013-01-23 10:42:16 +01:00
|
|
|
if (planned_check > service->GetNextCheck()) {
|
|
|
|
Logger::Write(LogInformation, "icinga", "Ignoring reschedule request for service '" +
|
2013-01-23 16:07:55 +01:00
|
|
|
service->GetName() + "' (next check is already sooner than requested check time)");
|
|
|
|
continue;
|
2013-01-23 10:42:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Logger::Write(LogInformation, "icinga", "Rescheduling next check for service '" + service->GetName() + "'");
|
|
|
|
service->SetNextCheck(planned_check);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::EnableHostSvcChecks(double, const vector<String>& arguments)
|
2013-01-23 10:51:54 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 1)
|
|
|
|
throw_exception(invalid_argument("Expected 1 argument."));
|
|
|
|
|
|
|
|
if (!Host::Exists(arguments[0]))
|
|
|
|
throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist."));
|
|
|
|
|
|
|
|
Host::Ptr host = Host::GetByName(arguments[0]);
|
|
|
|
|
2013-01-29 14:19:54 +01:00
|
|
|
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
|
2013-01-24 23:10:07 +01:00
|
|
|
Logger::Write(LogInformation, "icinga", "Enabling active checks for service '" + service->GetName() + "'");
|
|
|
|
service->SetEnableActiveChecks(true);
|
2013-01-23 10:51:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::DisableHostSvcChecks(double, const vector<String>& arguments)
|
2013-01-23 10:51:54 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 1)
|
|
|
|
throw_exception(invalid_argument("Expected 1 arguments."));
|
|
|
|
|
|
|
|
if (!Host::Exists(arguments[0]))
|
|
|
|
throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist."));
|
|
|
|
|
|
|
|
Host::Ptr host = Host::GetByName(arguments[0]);
|
|
|
|
|
2013-01-29 14:19:54 +01:00
|
|
|
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
|
2013-01-24 23:10:07 +01:00
|
|
|
Logger::Write(LogInformation, "icinga", "Disabling active checks for service '" + service->GetName() + "'");
|
|
|
|
service->SetEnableActiveChecks(false);
|
2013-01-23 10:51:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::AcknowledgeSvcProblem(double, const vector<String>& arguments)
|
2013-01-23 13:21:07 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 7)
|
|
|
|
throw_exception(invalid_argument("Expected 7 arguments."));
|
|
|
|
|
|
|
|
if (!Service::Exists(arguments[1]))
|
|
|
|
throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist."));
|
|
|
|
|
2013-01-29 12:05:46 +01:00
|
|
|
bool sticky = Convert::ToBool(arguments[2]);
|
2013-01-23 13:21:07 +01:00
|
|
|
|
|
|
|
Service::Ptr service = Service::GetByName(arguments[1]);
|
|
|
|
|
2013-01-23 16:18:58 +01:00
|
|
|
if (service->GetState() == StateOK)
|
|
|
|
throw_exception(invalid_argument("The service '" + arguments[1] + "' is OK."));
|
|
|
|
|
2013-01-23 13:46:35 +01:00
|
|
|
Logger::Write(LogInformation, "icinga", "Setting acknowledgement for service '" + service->GetName() + "'");
|
2013-01-23 13:21:07 +01:00
|
|
|
service->SetAcknowledgement(sticky ? AcknowledgementSticky : AcknowledgementNormal);
|
|
|
|
service->SetAcknowledgementExpiry(0);
|
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::AcknowledgeSvcProblemExpire(double, const vector<String>& arguments)
|
2013-01-23 13:21:07 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 8)
|
|
|
|
throw_exception(invalid_argument("Expected 8 arguments."));
|
|
|
|
|
|
|
|
if (!Service::Exists(arguments[1]))
|
|
|
|
throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist."));
|
|
|
|
|
2013-01-29 12:05:46 +01:00
|
|
|
bool sticky = Convert::ToBool(arguments[2]);
|
|
|
|
double timestamp = Convert::ToDouble(arguments[5]);
|
2013-01-23 13:21:07 +01:00
|
|
|
|
|
|
|
Service::Ptr service = Service::GetByName(arguments[1]);
|
|
|
|
|
2013-01-23 16:18:58 +01:00
|
|
|
if (service->GetState() == StateOK)
|
|
|
|
throw_exception(invalid_argument("The service '" + arguments[1] + "' is OK."));
|
|
|
|
|
2013-01-23 13:46:35 +01:00
|
|
|
Logger::Write(LogInformation, "icinga", "Setting timed acknowledgement for service '" + service->GetName() + "'");
|
2013-01-23 13:21:07 +01:00
|
|
|
service->SetAcknowledgement(sticky ? AcknowledgementSticky : AcknowledgementNormal);
|
|
|
|
service->SetAcknowledgementExpiry(timestamp);
|
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::RemoveSvcAcknowledgement(double, const vector<String>& arguments)
|
2013-01-23 13:21:07 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 2)
|
|
|
|
throw_exception(invalid_argument("Expected 2 arguments."));
|
|
|
|
|
|
|
|
if (!Service::Exists(arguments[1]))
|
|
|
|
throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist."));
|
|
|
|
|
|
|
|
Service::Ptr service = Service::GetByName(arguments[1]);
|
|
|
|
|
2013-01-23 13:46:35 +01:00
|
|
|
Logger::Write(LogInformation, "icinga", "Removing acknowledgement for service '" + service->GetName() + "'");
|
2013-01-23 13:21:07 +01:00
|
|
|
service->SetAcknowledgement(AcknowledgementNone);
|
|
|
|
service->SetAcknowledgementExpiry(0);
|
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::AcknowledgeHostProblem(double, const vector<String>& arguments)
|
2013-01-27 11:35:47 +01:00
|
|
|
{
|
2013-01-27 12:02:22 +01:00
|
|
|
if (arguments.size() < 6)
|
|
|
|
throw_exception(invalid_argument("Expected 6 arguments."));
|
2013-01-27 11:35:47 +01:00
|
|
|
|
2013-01-27 12:02:22 +01:00
|
|
|
if (!Host::Exists(arguments[0]))
|
|
|
|
throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist."));
|
2013-01-27 11:35:47 +01:00
|
|
|
|
2013-01-29 12:05:46 +01:00
|
|
|
bool sticky = Convert::ToBool(arguments[0]);
|
2013-01-27 11:35:47 +01:00
|
|
|
|
2013-01-27 12:02:22 +01:00
|
|
|
Host::Ptr host = Host::GetByName(arguments[0]);
|
2013-01-27 11:35:47 +01:00
|
|
|
|
|
|
|
if (host->IsUp())
|
2013-01-27 12:02:22 +01:00
|
|
|
throw_exception(invalid_argument("The host '" + arguments[0] + "' is OK."));
|
2013-01-27 11:35:47 +01:00
|
|
|
|
|
|
|
Logger::Write(LogInformation, "icinga", "Setting acknowledgement for host '" + host->GetName() + "'");
|
|
|
|
host->SetAcknowledgement(sticky ? AcknowledgementSticky : AcknowledgementNormal);
|
|
|
|
host->SetAcknowledgementExpiry(0);
|
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::AcknowledgeHostProblemExpire(double, const vector<String>& arguments)
|
2013-01-27 11:35:47 +01:00
|
|
|
{
|
2013-01-27 12:02:22 +01:00
|
|
|
if (arguments.size() < 7)
|
|
|
|
throw_exception(invalid_argument("Expected 7 arguments."));
|
2013-01-27 11:35:47 +01:00
|
|
|
|
2013-01-27 12:02:22 +01:00
|
|
|
if (!Host::Exists(arguments[0]))
|
|
|
|
throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist."));
|
2013-01-27 11:35:47 +01:00
|
|
|
|
2013-01-29 12:05:46 +01:00
|
|
|
bool sticky = Convert::ToBool(arguments[1]);
|
|
|
|
double timestamp = Convert::ToDouble(arguments[4]);
|
2013-01-27 11:35:47 +01:00
|
|
|
|
2013-01-27 12:02:22 +01:00
|
|
|
Host::Ptr host = Host::GetByName(arguments[0]);
|
2013-01-27 11:35:47 +01:00
|
|
|
|
|
|
|
if (host->IsUp())
|
2013-01-27 12:02:22 +01:00
|
|
|
throw_exception(invalid_argument("The host '" + arguments[0] + "' is OK."));
|
2013-01-27 11:35:47 +01:00
|
|
|
|
|
|
|
Logger::Write(LogInformation, "icinga", "Setting timed acknowledgement for host '" + host->GetName() + "'");
|
|
|
|
host->SetAcknowledgement(sticky ? AcknowledgementSticky : AcknowledgementNormal);
|
|
|
|
host->SetAcknowledgementExpiry(timestamp);
|
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::RemoveHostAcknowledgement(double, const vector<String>& arguments)
|
2013-01-27 11:35:47 +01:00
|
|
|
{
|
2013-01-27 12:02:22 +01:00
|
|
|
if (arguments.size() < 1)
|
|
|
|
throw_exception(invalid_argument("Expected 1 argument."));
|
2013-01-27 11:35:47 +01:00
|
|
|
|
2013-01-27 12:02:22 +01:00
|
|
|
if (!Host::Exists(arguments[0]))
|
|
|
|
throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist."));
|
2013-01-27 11:35:47 +01:00
|
|
|
|
2013-01-27 12:02:22 +01:00
|
|
|
Host::Ptr host = Host::GetByName(arguments[0]);
|
2013-01-27 11:35:47 +01:00
|
|
|
|
|
|
|
Logger::Write(LogInformation, "icinga", "Removing acknowledgement for host '" + host->GetName() + "'");
|
|
|
|
host->SetAcknowledgement(AcknowledgementNone);
|
|
|
|
host->SetAcknowledgementExpiry(0);
|
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::EnableHostgroupSvcChecks(double, const vector<String>& arguments)
|
2013-01-24 13:39:42 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 1)
|
|
|
|
throw_exception(invalid_argument("Expected 1 argument."));
|
|
|
|
|
|
|
|
if (!HostGroup::Exists(arguments[0]))
|
|
|
|
throw_exception(invalid_argument("The host group '" + arguments[0] + "' does not exist."));
|
|
|
|
|
|
|
|
HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
|
|
|
|
|
|
|
|
BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
|
2013-01-24 15:12:32 +01:00
|
|
|
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
|
2013-01-24 23:10:07 +01:00
|
|
|
Logger::Write(LogInformation, "icinga", "Enabling active checks for service '" + service->GetName() + "'");
|
|
|
|
service->SetEnableActiveChecks(true);
|
2013-01-24 15:12:32 +01:00
|
|
|
}
|
2013-01-24 13:39:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::DisableHostgroupSvcChecks(double, const vector<String>& arguments)
|
2013-01-24 13:39:42 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 1)
|
|
|
|
throw_exception(invalid_argument("Expected 1 argument."));
|
|
|
|
|
|
|
|
if (!HostGroup::Exists(arguments[0]))
|
|
|
|
throw_exception(invalid_argument("The host group '" + arguments[0] + "' does not exist."));
|
|
|
|
|
|
|
|
HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
|
|
|
|
|
|
|
|
BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
|
2013-01-24 15:12:32 +01:00
|
|
|
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
|
2013-01-24 23:10:07 +01:00
|
|
|
Logger::Write(LogInformation, "icinga", "Disabling active checks for service '" + service->GetName() + "'");
|
|
|
|
service->SetEnableActiveChecks(false);
|
2013-01-24 15:12:32 +01:00
|
|
|
}
|
2013-01-24 13:39:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::EnableServicegroupSvcChecks(double, const vector<String>& arguments)
|
2013-01-24 13:39:42 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 1)
|
|
|
|
throw_exception(invalid_argument("Expected 1 argument."));
|
|
|
|
|
|
|
|
if (!ServiceGroup::Exists(arguments[0]))
|
|
|
|
throw_exception(invalid_argument("The service group '" + arguments[0] + "' does not exist."));
|
|
|
|
|
|
|
|
ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
|
|
|
|
|
|
|
|
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
|
2013-01-24 23:10:07 +01:00
|
|
|
Logger::Write(LogInformation, "icinga", "Enabling active checks for service '" + service->GetName() + "'");
|
|
|
|
service->SetEnableActiveChecks(true);
|
2013-01-24 13:39:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::DisableServicegroupSvcChecks(double, const vector<String>& arguments)
|
2013-01-24 13:39:42 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 1)
|
|
|
|
throw_exception(invalid_argument("Expected 1 argument."));
|
|
|
|
|
|
|
|
if (!ServiceGroup::Exists(arguments[0]))
|
|
|
|
throw_exception(invalid_argument("The service group '" + arguments[0] + "' does not exist."));
|
|
|
|
|
|
|
|
ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
|
|
|
|
|
|
|
|
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
|
2013-01-24 23:10:07 +01:00
|
|
|
Logger::Write(LogInformation, "icinga", "Disabling active checks for service '" + service->GetName() + "'");
|
|
|
|
service->SetEnableActiveChecks(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::EnablePassiveSvcChecks(double, const vector<String>& arguments)
|
2013-01-24 23:10:07 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 2)
|
|
|
|
throw_exception(invalid_argument("Expected 2 arguments."));
|
|
|
|
|
|
|
|
if (!Service::Exists(arguments[1]))
|
|
|
|
throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist."));
|
|
|
|
|
|
|
|
Service::Ptr service = Service::GetByName(arguments[1]);
|
|
|
|
|
|
|
|
Logger::Write(LogInformation, "icinga", "Enabling passive checks for service '" + arguments[1] + "'");
|
|
|
|
service->SetEnablePassiveChecks(true);
|
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::DisablePassiveSvcChecks(double, const vector<String>& arguments)
|
2013-01-24 23:10:07 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 2)
|
|
|
|
throw_exception(invalid_argument("Expected 2 arguments."));
|
|
|
|
|
|
|
|
if (!Service::Exists(arguments[1]))
|
|
|
|
throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist."));
|
|
|
|
|
|
|
|
Service::Ptr service = Service::GetByName(arguments[1]);
|
|
|
|
|
|
|
|
Logger::Write(LogInformation, "icinga", "Disabling passive checks for service '" + arguments[1] + "'");
|
|
|
|
service->SetEnablePassiveChecks(false);
|
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::EnableServicegroupPassiveSvcChecks(double, const vector<String>& arguments)
|
2013-01-24 23:10:07 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 1)
|
|
|
|
throw_exception(invalid_argument("Expected 1 argument."));
|
|
|
|
|
|
|
|
if (!ServiceGroup::Exists(arguments[0]))
|
|
|
|
throw_exception(invalid_argument("The service group '" + arguments[0] + "' does not exist."));
|
|
|
|
|
|
|
|
ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
|
|
|
|
|
|
|
|
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
|
|
|
|
Logger::Write(LogInformation, "icinga", "Enabling passive checks for service '" + service->GetName() + "'");
|
|
|
|
service->SetEnablePassiveChecks(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::DisableServicegroupPassiveSvcChecks(double, const vector<String>& arguments)
|
2013-01-24 23:10:07 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 1)
|
|
|
|
throw_exception(invalid_argument("Expected 1 argument."));
|
|
|
|
|
|
|
|
if (!ServiceGroup::Exists(arguments[0]))
|
|
|
|
throw_exception(invalid_argument("The service group '" + arguments[0] + "' does not exist."));
|
|
|
|
|
|
|
|
ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
|
|
|
|
|
|
|
|
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
|
|
|
|
Logger::Write(LogInformation, "icinga", "Disabling passive checks for service '" + service->GetName() + "'");
|
|
|
|
service->SetEnablePassiveChecks(true);
|
2013-01-24 13:39:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::EnableHostgroupPassiveSvcChecks(double, const vector<String>& arguments)
|
2013-01-24 23:10:07 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 1)
|
|
|
|
throw_exception(invalid_argument("Expected 1 argument."));
|
|
|
|
|
|
|
|
if (!HostGroup::Exists(arguments[0]))
|
|
|
|
throw_exception(invalid_argument("The host group '" + arguments[0] + "' does not exist."));
|
|
|
|
|
|
|
|
HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
|
|
|
|
|
|
|
|
BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
|
|
|
|
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
|
|
|
|
Logger::Write(LogInformation, "icinga", "Enabling passive checks for service '" + service->GetName() + "'");
|
|
|
|
service->SetEnablePassiveChecks(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::DisableHostgroupPassiveSvcChecks(double, const vector<String>& arguments)
|
2013-01-24 23:10:07 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 1)
|
|
|
|
throw_exception(invalid_argument("Expected 1 argument."));
|
|
|
|
|
|
|
|
if (!HostGroup::Exists(arguments[0]))
|
|
|
|
throw_exception(invalid_argument("The host group '" + arguments[0] + "' does not exist."));
|
|
|
|
|
|
|
|
HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
|
|
|
|
|
|
|
|
BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
|
|
|
|
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
|
|
|
|
Logger::Write(LogInformation, "icinga", "Disabling passive checks for service '" + service->GetName() + "'");
|
|
|
|
service->SetEnablePassiveChecks(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-24 23:42:02 +01:00
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::ProcessFile(double, const vector<String>& arguments)
|
2013-01-24 23:42:02 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 2)
|
|
|
|
throw_exception(invalid_argument("Expected 2 arguments."));
|
|
|
|
|
|
|
|
String file = arguments[0];
|
2013-01-29 12:05:46 +01:00
|
|
|
bool del = Convert::ToBool(arguments[1]);
|
2013-01-24 23:42:02 +01:00
|
|
|
|
|
|
|
ifstream ifp;
|
|
|
|
ifp.exceptions(ifstream::badbit);
|
|
|
|
|
2013-01-24 23:43:34 +01:00
|
|
|
ifp.open(file.CStr(), ifstream::in);
|
2013-01-24 23:42:02 +01:00
|
|
|
|
|
|
|
while(ifp.good()) {
|
|
|
|
std::string line;
|
|
|
|
std::getline(ifp, line);
|
|
|
|
|
|
|
|
try {
|
|
|
|
Logger::Write(LogInformation, "compat", "Executing external command: " + line);
|
|
|
|
|
|
|
|
Execute(line);
|
|
|
|
} catch (const exception& ex) {
|
|
|
|
stringstream msgbuf;
|
|
|
|
msgbuf << "External command failed: " << ex.what();
|
|
|
|
Logger::Write(LogWarning, "icinga", msgbuf.str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ifp.close();
|
|
|
|
|
|
|
|
if (del)
|
|
|
|
(void) unlink(file.CStr());
|
|
|
|
}
|
2013-01-29 14:19:54 +01:00
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::ScheduleSvcDowntime(double, const vector<String>& arguments)
|
2013-01-29 14:19:54 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 9)
|
|
|
|
throw_exception(invalid_argument("Expected 9 arguments."));
|
|
|
|
|
|
|
|
if (!Service::Exists(arguments[1]))
|
|
|
|
throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist."));
|
|
|
|
|
|
|
|
Service::Ptr service = Service::GetByName(arguments[1]);
|
|
|
|
|
2013-01-30 09:59:22 +01:00
|
|
|
String triggeredBy;
|
|
|
|
int triggeredByLegacy = Convert::ToLong(arguments[5]);
|
|
|
|
if (triggeredByLegacy != 0)
|
|
|
|
triggeredBy = DowntimeProcessor::GetIDFromLegacyID(triggeredByLegacy);
|
2013-01-29 14:19:54 +01:00
|
|
|
|
2013-01-30 09:59:22 +01:00
|
|
|
Logger::Write(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
|
2013-01-29 14:19:54 +01:00
|
|
|
(void) DowntimeProcessor::AddDowntime(service, arguments[7], arguments[8],
|
|
|
|
Convert::ToDouble(arguments[2]), Convert::ToDouble(arguments[3]),
|
2013-01-30 09:59:22 +01:00
|
|
|
Convert::ToBool(arguments[4]), triggeredBy, Convert::ToDouble(arguments[6]));
|
2013-01-29 14:19:54 +01:00
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::DelSvcDowntime(double, const vector<String>& arguments)
|
2013-01-29 14:19:54 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 1)
|
|
|
|
throw_exception(invalid_argument("Expected 1 argument."));
|
|
|
|
|
2013-01-30 09:59:22 +01:00
|
|
|
int id = Convert::ToLong(arguments[0]);
|
|
|
|
Logger::Write(LogInformation, "icinga", "Removing downtime ID " + arguments[0]);
|
|
|
|
String rid = DowntimeProcessor::GetIDFromLegacyID(id);
|
|
|
|
DowntimeProcessor::RemoveDowntime(rid);
|
2013-01-29 14:19:54 +01:00
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::ScheduleHostDowntime(double, const vector<String>& arguments)
|
2013-01-29 14:19:54 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 8)
|
|
|
|
throw_exception(invalid_argument("Expected 8 arguments."));
|
|
|
|
|
|
|
|
if (!Host::Exists(arguments[0]))
|
|
|
|
throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist."));
|
|
|
|
|
|
|
|
Host::Ptr host = Host::GetByName(arguments[0]);
|
|
|
|
|
2013-01-30 09:59:22 +01:00
|
|
|
String triggeredBy;
|
|
|
|
int triggeredByLegacy = Convert::ToLong(arguments[4]);
|
|
|
|
if (triggeredByLegacy != 0)
|
|
|
|
triggeredBy = DowntimeProcessor::GetIDFromLegacyID(triggeredByLegacy);
|
2013-01-29 14:19:54 +01:00
|
|
|
|
2013-01-30 09:59:22 +01:00
|
|
|
Logger::Write(LogInformation, "icinga", "Creating downtime for host " + host->GetName());
|
2013-01-29 14:19:54 +01:00
|
|
|
(void) DowntimeProcessor::AddDowntime(host, arguments[6], arguments[7],
|
|
|
|
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
|
2013-01-30 09:59:22 +01:00
|
|
|
Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
|
2013-01-29 14:19:54 +01:00
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::DelHostDowntime(double, const vector<String>& arguments)
|
2013-01-29 14:19:54 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 1)
|
|
|
|
throw_exception(invalid_argument("Expected 1 argument."));
|
|
|
|
|
2013-01-30 09:59:22 +01:00
|
|
|
int id = Convert::ToLong(arguments[0]);
|
|
|
|
Logger::Write(LogInformation, "icinga", "Removing downtime ID " + arguments[0]);
|
|
|
|
String rid = DowntimeProcessor::GetIDFromLegacyID(id);
|
|
|
|
DowntimeProcessor::RemoveDowntime(rid);
|
2013-01-29 14:19:54 +01:00
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::ScheduleHostSvcDowntime(double, const vector<String>& arguments)
|
2013-01-29 14:19:54 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 8)
|
|
|
|
throw_exception(invalid_argument("Expected 8 argument."));
|
|
|
|
|
|
|
|
if (!Host::Exists(arguments[0]))
|
|
|
|
throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist."));
|
|
|
|
|
|
|
|
Host::Ptr host = Host::GetByName(arguments[0]);
|
|
|
|
|
2013-01-30 09:59:22 +01:00
|
|
|
String triggeredBy;
|
|
|
|
int triggeredByLegacy = Convert::ToLong(arguments[4]);
|
|
|
|
if (triggeredByLegacy != 0)
|
|
|
|
triggeredBy = DowntimeProcessor::GetIDFromLegacyID(triggeredByLegacy);
|
|
|
|
|
2013-01-29 14:19:54 +01:00
|
|
|
Logger::Write(LogInformation, "icinga", "Creating downtime for host " + host->GetName());
|
|
|
|
(void) DowntimeProcessor::AddDowntime(host, arguments[6], arguments[7],
|
|
|
|
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
|
2013-01-30 09:59:22 +01:00
|
|
|
Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
|
2013-01-29 14:19:54 +01:00
|
|
|
|
|
|
|
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
|
|
|
|
Logger::Write(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
|
|
|
|
(void) DowntimeProcessor::AddDowntime(service, arguments[6], arguments[7],
|
|
|
|
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
|
2013-01-30 09:59:22 +01:00
|
|
|
Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
|
2013-01-29 14:19:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::ScheduleHostgroupHostDowntime(double, const vector<String>& arguments)
|
2013-01-29 14:19:54 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 8)
|
|
|
|
throw_exception(invalid_argument("Expected 8 arguments."));
|
|
|
|
|
|
|
|
if (!HostGroup::Exists(arguments[0]))
|
|
|
|
throw_exception(invalid_argument("The host group '" + arguments[0] + "' does not exist."));
|
|
|
|
|
|
|
|
HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
|
|
|
|
|
2013-01-30 09:59:22 +01:00
|
|
|
String triggeredBy;
|
|
|
|
int triggeredByLegacy = Convert::ToLong(arguments[4]);
|
|
|
|
if (triggeredByLegacy != 0)
|
|
|
|
triggeredBy = DowntimeProcessor::GetIDFromLegacyID(triggeredByLegacy);
|
|
|
|
|
2013-01-29 14:19:54 +01:00
|
|
|
BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
|
|
|
|
Logger::Write(LogInformation, "icinga", "Creating downtime for host " + host->GetName());
|
|
|
|
(void) DowntimeProcessor::AddDowntime(host, arguments[6], arguments[7],
|
|
|
|
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
|
2013-01-30 09:59:22 +01:00
|
|
|
Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
|
2013-01-29 14:19:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::ScheduleHostgroupSvcDowntime(double, const vector<String>& arguments)
|
2013-01-29 14:19:54 +01:00
|
|
|
{
|
2013-01-30 13:23:00 +01:00
|
|
|
if (arguments.size() < 8)
|
|
|
|
throw_exception(invalid_argument("Expected 8 arguments."));
|
|
|
|
|
|
|
|
if (!HostGroup::Exists(arguments[0]))
|
|
|
|
throw_exception(invalid_argument("The host group '" + arguments[0] + "' does not exist."));
|
|
|
|
|
|
|
|
HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
|
|
|
|
|
|
|
|
String triggeredBy;
|
|
|
|
int triggeredByLegacy = Convert::ToLong(arguments[4]);
|
|
|
|
if (triggeredByLegacy != 0)
|
|
|
|
triggeredBy = DowntimeProcessor::GetIDFromLegacyID(triggeredByLegacy);
|
|
|
|
|
|
|
|
/* Note: we can't just directly create downtimes for all the services by iterating
|
|
|
|
* over all hosts in the host group - otherwise we might end up creating multiple
|
|
|
|
* downtimes for some services. */
|
|
|
|
|
|
|
|
set<Service::Ptr> services;
|
|
|
|
|
|
|
|
BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
|
|
|
|
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
|
|
|
|
services.insert(service);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_FOREACH(const Service::Ptr& service, services) {
|
|
|
|
Logger::Write(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
|
|
|
|
(void) DowntimeProcessor::AddDowntime(service, arguments[6], arguments[7],
|
|
|
|
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
|
|
|
|
Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
|
|
|
|
}
|
2013-01-29 14:19:54 +01:00
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::ScheduleServicegroupHostDowntime(double, const vector<String>& arguments)
|
2013-01-29 14:19:54 +01:00
|
|
|
{
|
2013-01-30 13:23:00 +01:00
|
|
|
if (arguments.size() < 8)
|
|
|
|
throw_exception(invalid_argument("Expected 8 arguments."));
|
|
|
|
|
|
|
|
if (!ServiceGroup::Exists(arguments[0]))
|
|
|
|
throw_exception(invalid_argument("The host group '" + arguments[0] + "' does not exist."));
|
|
|
|
|
|
|
|
ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
|
|
|
|
|
|
|
|
String triggeredBy;
|
|
|
|
int triggeredByLegacy = Convert::ToLong(arguments[4]);
|
|
|
|
if (triggeredByLegacy != 0)
|
|
|
|
triggeredBy = DowntimeProcessor::GetIDFromLegacyID(triggeredByLegacy);
|
|
|
|
|
|
|
|
/* Note: we can't just directly create downtimes for all the hosts by iterating
|
|
|
|
* over all services in the service group - otherwise we might end up creating multiple
|
|
|
|
* downtimes for some hosts. */
|
|
|
|
|
|
|
|
set<Host::Ptr> hosts;
|
|
|
|
|
|
|
|
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
|
|
|
|
hosts.insert(service->GetHost());
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_FOREACH(const Host::Ptr& host, hosts) {
|
|
|
|
Logger::Write(LogInformation, "icinga", "Creating downtime for host " + host->GetName());
|
|
|
|
(void) DowntimeProcessor::AddDowntime(host, arguments[6], arguments[7],
|
|
|
|
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
|
|
|
|
Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
|
|
|
|
}
|
2013-01-29 14:19:54 +01:00
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::ScheduleServicegroupSvcDowntime(double, const vector<String>& arguments)
|
2013-01-29 14:19:54 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 8)
|
|
|
|
throw_exception(invalid_argument("Expected 8 arguments."));
|
|
|
|
|
|
|
|
if (!ServiceGroup::Exists(arguments[0]))
|
|
|
|
throw_exception(invalid_argument("The host group '" + arguments[0] + "' does not exist."));
|
|
|
|
|
|
|
|
ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
|
|
|
|
|
2013-01-30 09:59:22 +01:00
|
|
|
String triggeredBy;
|
|
|
|
int triggeredByLegacy = Convert::ToLong(arguments[4]);
|
|
|
|
if (triggeredByLegacy != 0)
|
|
|
|
triggeredBy = DowntimeProcessor::GetIDFromLegacyID(triggeredByLegacy);
|
|
|
|
|
2013-01-29 14:19:54 +01:00
|
|
|
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
|
|
|
|
Logger::Write(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
|
|
|
|
(void) DowntimeProcessor::AddDowntime(service, arguments[6], arguments[7],
|
|
|
|
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
|
2013-01-30 09:59:22 +01:00
|
|
|
Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
|
2013-01-29 14:19:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::AddHostComment(double, const vector<String>& arguments)
|
2013-01-29 16:29:09 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 4)
|
|
|
|
throw_exception(invalid_argument("Expected 4 arguments."));
|
|
|
|
|
|
|
|
if (!Host::Exists(arguments[0]))
|
|
|
|
throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist."));
|
|
|
|
|
|
|
|
Host::Ptr host = Host::GetByName(arguments[0]);
|
|
|
|
|
|
|
|
Logger::Write(LogInformation, "icinga", "Creating comment for host " + host->GetName());
|
|
|
|
(void) CommentProcessor::AddComment(host, Comment_User, arguments[2], arguments[3], 0);
|
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::DelHostComment(double, const vector<String>& arguments)
|
2013-01-29 16:29:09 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 1)
|
|
|
|
throw_exception(invalid_argument("Expected 1 argument."));
|
|
|
|
|
2013-01-30 09:59:22 +01:00
|
|
|
int id = Convert::ToLong(arguments[0]);
|
|
|
|
Logger::Write(LogInformation, "icinga", "Removing comment ID " + arguments[0]);
|
|
|
|
String rid = CommentProcessor::GetIDFromLegacyID(id);
|
|
|
|
CommentProcessor::RemoveComment(rid);
|
2013-01-29 16:29:09 +01:00
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::AddSvcComment(double, const vector<String>& arguments)
|
2013-01-29 16:29:09 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 5)
|
|
|
|
throw_exception(invalid_argument("Expected 5 arguments."));
|
|
|
|
|
|
|
|
if (!Service::Exists(arguments[1]))
|
|
|
|
throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist."));
|
|
|
|
|
|
|
|
Service::Ptr service = Service::GetByName(arguments[1]);
|
|
|
|
|
|
|
|
Logger::Write(LogInformation, "icinga", "Creating comment for service " + service->GetName());
|
|
|
|
(void) CommentProcessor::AddComment(service, Comment_User, arguments[3], arguments[4], 0);
|
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::DelSvcComment(double, const vector<String>& arguments)
|
2013-01-29 16:29:09 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 1)
|
|
|
|
throw_exception(invalid_argument("Expected 1 argument."));
|
|
|
|
|
2013-01-30 09:59:22 +01:00
|
|
|
int id = Convert::ToLong(arguments[0]);
|
|
|
|
Logger::Write(LogInformation, "icinga", "Removing comment ID " + arguments[0]);
|
|
|
|
|
|
|
|
String rid = CommentProcessor::GetIDFromLegacyID(id);
|
|
|
|
CommentProcessor::RemoveComment(rid);
|
2013-01-29 16:29:09 +01:00
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::DelAllHostComments(double, const vector<String>& arguments)
|
2013-01-29 16:29:09 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 1)
|
|
|
|
throw_exception(invalid_argument("Expected 1 argument."));
|
|
|
|
|
|
|
|
if (!Host::Exists(arguments[0]))
|
|
|
|
throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist."));
|
|
|
|
|
|
|
|
Host::Ptr host = Host::GetByName(arguments[0]);
|
|
|
|
|
|
|
|
Logger::Write(LogInformation, "icinga", "Removing all comments for host " + host->GetName());
|
|
|
|
CommentProcessor::RemoveAllComments(host);
|
|
|
|
}
|
|
|
|
|
2013-02-02 22:13:11 +01:00
|
|
|
void ExternalCommandProcessor::DelAllSvcComments(double, const vector<String>& arguments)
|
2013-01-29 16:29:09 +01:00
|
|
|
{
|
|
|
|
if (arguments.size() < 2)
|
|
|
|
throw_exception(invalid_argument("Expected 2 arguments."));
|
|
|
|
|
|
|
|
if (!Service::Exists(arguments[1]))
|
|
|
|
throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist."));
|
|
|
|
|
|
|
|
Service::Ptr service = Service::GetByName(arguments[1]);
|
|
|
|
|
|
|
|
Logger::Write(LogInformation, "icinga", "Removing all comments for service " + service->GetName());
|
|
|
|
CommentProcessor::RemoveAllComments(service);
|
|
|
|
}
|
|
|
|
|