Implement {EN,DIS}ABLE_HOST_SVC_NOTIFICATIONS commands

fixes #7784
This commit is contained in:
Michael Friedrich 2015-02-11 16:45:52 +01:00
parent 24852e05c7
commit 2ae06b7a52
4 changed files with 52 additions and 4 deletions

View File

@ -1159,7 +1159,6 @@ The following external commands are not supported:
DISABLE_FAILURE_PREDICTION
DISABLE_HOST_AND_CHILD_NOTIFICATIONS
DISABLE_HOST_FRESHNESS_CHECKS
DISABLE_HOST_SVC_NOTIFICATIONS
DISABLE_NOTIFICATIONS_EXPIRE_TIME
DISABLE_SERVICE_FRESHNESS_CHECKS
ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST
@ -1170,7 +1169,6 @@ The following external commands are not supported:
ENABLE_FAILURE_PREDICTION
ENABLE_HOST_AND_CHILD_NOTIFICATIONS
ENABLE_HOST_FRESHNESS_CHECKS
ENABLE_HOST_SVC_NOTIFICATIONS
ENABLE_SERVICE_FRESHNESS_CHECKS
READ_STATE_INFORMATION
SAVE_STATE_INFORMATION

View File

@ -68,6 +68,8 @@ Additional details can be found in the [Icinga 1.x Documentation](http://docs.ic
DISABLE_HOST_NOTIFICATIONS | ;<host_name> (1) | -
ENABLE_SVC_NOTIFICATIONS | ;<host_name>;<service_name> (2) | -
DISABLE_SVC_NOTIFICATIONS | ;<host_name>;<service_name> (2) | -
ENABLE_HOST_SVC_NOTIFICATIONS | ;<host_name> (1) | -
DISABLE_HOST_SVC_NOTIFICATIONS | ;<host_name> (1) | -
DISABLE_HOSTGROUP_HOST_CHECKS | ;<hostgroup_name> (1) | -
DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS | ;<hostgroup_name> (1) | -
DISABLE_SERVICEGROUP_HOST_CHECKS | ;<servicegroup_name> (1) | -

View File

@ -152,7 +152,7 @@ void ExternalCommandProcessor::Execute(double time, const String& command, const
if (argnum > 0) {
std::copy(arguments.begin(), arguments.begin() + argnum - 1, realArguments.begin());
String last_argument;
for (std::vector<String>::size_type i = argnum - 1; i < arguments.size(); i++) {
if (!last_argument.IsEmpty())
@ -233,6 +233,8 @@ void ExternalCommandProcessor::StaticInitialize(void)
RegisterCommand("DISABLE_HOST_NOTIFICATIONS", &ExternalCommandProcessor::DisableHostNotifications, 1);
RegisterCommand("ENABLE_SVC_NOTIFICATIONS", &ExternalCommandProcessor::EnableSvcNotifications, 2);
RegisterCommand("DISABLE_SVC_NOTIFICATIONS", &ExternalCommandProcessor::DisableSvcNotifications, 2);
RegisterCommand("ENABLE_HOST_SVC_NOTIFICATIONS", &ExternalCommandProcessor::EnableHostSvcNotifications, 1);
RegisterCommand("DISABLE_HOST_SVC_NOTIFICATIONS", &ExternalCommandProcessor::DisableHostSvcNotifications, 1);
RegisterCommand("DISABLE_HOSTGROUP_HOST_CHECKS", &ExternalCommandProcessor::DisableHostgroupHostChecks, 1);
RegisterCommand("DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS", &ExternalCommandProcessor::DisableHostgroupPassiveHostChecks, 1);
RegisterCommand("DISABLE_SERVICEGROUP_HOST_CHECKS", &ExternalCommandProcessor::DisableServicegroupHostChecks, 1);
@ -1415,6 +1417,50 @@ void ExternalCommandProcessor::DisableSvcNotifications(double, const std::vector
}
}
void ExternalCommandProcessor::EnableHostSvcNotifications(double, const std::vector<String>& arguments)
{
Host::Ptr host = Host::GetByName(arguments[0]);
if (!host)
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable notifications for all services for non-existent host '" + arguments[0] + "'"));
Log(LogNotice, "ExternalCommandProcessor")
<< "Enabling notifications for all services on host '" << arguments[0] << "'";
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
Log(LogNotice, "ExternalCommandProcessor")
<< "Enabling notifications for service '" << service->GetName() << "'";
{
ObjectLock olock(service);
service->SetEnableNotifications(true);
}
}
}
void ExternalCommandProcessor::DisableHostSvcNotifications(double, const std::vector<String>& arguments)
{
Host::Ptr host = Host::GetByName(arguments[0]);
if (!host)
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable notifications for all services for non-existent host '" + arguments[0] + "'"));
Log(LogNotice, "ExternalCommandProcessor")
<< "Disabling notifications for all services on host '" << arguments[0] << "'";
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
Log(LogNotice, "ExternalCommandProcessor")
<< "Disabling notifications for service '" << service->GetName() << "'";
{
ObjectLock olock(service);
service->SetEnableNotifications(false);
}
}
}
void ExternalCommandProcessor::DisableHostgroupHostChecks(double, const std::vector<String>& arguments)
{
HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);

View File

@ -36,7 +36,7 @@ public:
static void Execute(double time, const String& command, const std::vector<String>& arguments);
static void StaticInitialize(void);
static boost::signals2::signal<void(double, const String&, const std::vector<String>&)> OnNewExternalCommand;
private:
@ -100,6 +100,8 @@ private:
static void DisableHostNotifications(double time, const std::vector<String>& arguments);
static void EnableSvcNotifications(double time, const std::vector<String>& arguments);
static void DisableSvcNotifications(double time, const std::vector<String>& arguments);
static void EnableHostSvcNotifications(double, const std::vector<String>& arguments);
static void DisableHostSvcNotifications(double, const std::vector<String>& arguments);
static void DisableHostgroupHostChecks(double, const std::vector<String>& arguments);
static void DisableHostgroupPassiveHostChecks(double, const std::vector<String>& arguments);
static void DisableServicegroupHostChecks(double, const std::vector<String>& arguments);