]> granicus.if.org Git - icinga2/commitdiff
Implement missing host/servicegroup commands
authorJohannes Meyer <johannes.meyer@netways.de>
Mon, 20 Jan 2014 15:58:18 +0000 (16:58 +0100)
committerJohannes Meyer <johannes.meyer@netways.de>
Mon, 20 Jan 2014 15:58:18 +0000 (16:58 +0100)
fixes #5504

lib/icinga/externalcommandprocessor.cpp
lib/icinga/externalcommandprocessor.h

index 0c206a18d815e99e28023722dc20e289a5436f8d..0b206b94fc14173d827d2a026a0d03b68f676054 100644 (file)
@@ -199,6 +199,14 @@ void ExternalCommandProcessor::Initialize(void)
        RegisterCommand("CHANGE_MAX_SVC_CHECK_ATTEMPTS", &ExternalCommandProcessor::ChangeMaxSvcCheckAttempts);
        RegisterCommand("CHANGE_HOST_CHECK_TIMEPERIOD", &ExternalCommandProcessor::ChangeHostCheckTimeperiod);
        RegisterCommand("CHANGE_SVC_CHECK_TIMEPERIOD", &ExternalCommandProcessor::ChangeSvcCheckTimeperiod);
+       RegisterCommand("ENABLE_HOSTGROUP_HOST_NOTIFICATIONS", &ExternalCommandProcessor::EnableHostgroupHostNotifications);
+       RegisterCommand("ENABLE_HOSTGROUP_SVC_NOTIFICATIONS", &ExternalCommandProcessor::EnableHostgroupSvcNotifications);
+       RegisterCommand("DISABLE_HOSTGROUP_HOST_NOTIFICATIONS", &ExternalCommandProcessor::DisableHostgroupHostNotifications);
+       RegisterCommand("DISABLE_HOSTGROUP_SVC_NOTIFICATIONS", &ExternalCommandProcessor::DisableHostgroupSvcNotifications);
+       RegisterCommand("ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS", &ExternalCommandProcessor::EnableServicegroupHostNotifications);
+       RegisterCommand("DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS", &ExternalCommandProcessor::DisableServicegroupHostNotifications);
+       RegisterCommand("ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS", &ExternalCommandProcessor::EnableServicegroupSvcNotifications);
+       RegisterCommand("DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS", &ExternalCommandProcessor::DisableServicegroupSvcNotifications);
 }
 
 void ExternalCommandProcessor::RegisterCommand(const String& command, const ExternalCommandProcessor::Callback& callback)
@@ -2283,3 +2291,203 @@ void ExternalCommandProcessor::ChangeSvcCheckTimeperiod(double time, const std::
                service->SetCheckPeriod(tp);
        }
 }
+
+void ExternalCommandProcessor::EnableHostgroupHostNotifications(double time, const std::vector<String>& arguments)
+{
+       if (arguments.size() < 1)
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 arguments."));
+
+       HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
+
+       if (!hg)
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable host notifications for non-existent hostgroup '" + arguments[0] + "'"));
+
+       BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
+               Service::Ptr hc = host->GetCheckService();
+
+               if (!hc) {
+                       Log(LogInformation, "icinga", "Cannot enable notifications for host '" + host->GetName() + "' which has no check service.");
+               } else {
+                       Log(LogInformation, "icinga", "Enabling notifications for host '" + host->GetName() + "'");
+
+                       {
+                               ObjectLock olock(hc);
+
+                               hc->SetEnableNotifications(true);
+                       }
+               }
+       }
+}
+
+void ExternalCommandProcessor::EnableHostgroupSvcNotifications(double time, const std::vector<String>& arguments)
+{
+       if (arguments.size() < 1)
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
+
+       HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
+
+       if (!hg)
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable service notifications for non-existent hostgroup '" + arguments[0] + "'"));
+
+       BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
+               BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
+                       Log(LogInformation, "icinga", "Enabling notifications for service '" + service->GetName() + "'");
+
+                       {
+                               ObjectLock olock(service);
+
+                               service->SetEnableNotifications(true);
+                       }
+               }
+       }
+}
+
+void ExternalCommandProcessor::DisableHostgroupHostNotifications(double time, const std::vector<String>& arguments)
+{
+       if (arguments.size() < 1)
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 arguments."));
+
+       HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
+
+       if (!hg)
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable host notifications for non-existent hostgroup '" + arguments[0] + "'"));
+
+       BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
+               Service::Ptr hc = host->GetCheckService();
+
+               if (!hc) {
+                       Log(LogInformation, "icinga", "Cannot disable notifications for host '" + host->GetName() + "' which has no check service.");
+               } else {
+                       Log(LogInformation, "icinga", "Disabling notifications for host '" + host->GetName() + "'");
+
+                       {
+                               ObjectLock olock(hc);
+
+                               hc->SetEnableNotifications(false);
+                       }
+               }
+       }
+}
+
+void ExternalCommandProcessor::DisableHostgroupSvcNotifications(double time, const std::vector<String>& arguments)
+{
+       if (arguments.size() < 1)
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
+
+       HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
+
+       if (!hg)
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable service notifications for non-existent hostgroup '" + arguments[0] + "'"));
+
+       BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
+               BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
+                       Log(LogInformation, "icinga", "Disabling notifications for service '" + service->GetName() + "'");
+
+                       {
+                               ObjectLock olock(service);
+
+                               service->SetEnableNotifications(false);
+                       }
+               }
+       }
+}
+
+void ExternalCommandProcessor::EnableServicegroupHostNotifications(double time, const std::vector<String>& arguments)
+{
+       if (arguments.size() < 1)
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 arguments."));
+
+       ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
+
+       if (!sg)
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable host notifications for non-existent servicegroup '" + arguments[0] + "'"));
+
+       BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
+               Host::Ptr host = service->GetHost();
+
+               Service::Ptr hc = host->GetCheckService();
+
+               if (!hc) {
+                       Log(LogInformation, "icinga", "Cannot enable notifications for host '" + host->GetName() + "' which has no check service.");
+               } else {
+                       Log(LogInformation, "icinga", "Enabling notifications for host '" + host->GetName() + "'");
+
+                       {
+                               ObjectLock olock(hc);
+
+                               hc->SetEnableNotifications(true);
+                       }
+               }
+       }
+}
+
+void ExternalCommandProcessor::EnableServicegroupSvcNotifications(double time, const std::vector<String>& arguments)
+{
+       if (arguments.size() < 1)
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
+
+       ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
+
+       if (!sg)
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable service notifications for non-existent servicegroup '" + arguments[0] + "'"));
+
+       BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
+               Log(LogInformation, "icinga", "Enabling notifications for service '" + service->GetName() + "'");
+
+               {
+                       ObjectLock olock(service);
+
+                       service->SetEnableNotifications(true);
+               }
+       }
+}
+
+void ExternalCommandProcessor::DisableServicegroupHostNotifications(double time, const std::vector<String>& arguments)
+{
+       if (arguments.size() < 1)
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 arguments."));
+
+       ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
+
+       if (!sg)
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable host notifications for non-existent servicegroup '" + arguments[0] + "'"));
+
+       BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
+               Host::Ptr host = service->GetHost();
+
+               Service::Ptr hc = host->GetCheckService();
+
+               if (!hc) {
+                       Log(LogInformation, "icinga", "Cannot disable notifications for host '" + host->GetName() + "' which has no check service.");
+               } else {
+                       Log(LogInformation, "icinga", "Disabling notifications for host '" + host->GetName() + "'");
+
+                       {
+                               ObjectLock olock(hc);
+
+                               hc->SetEnableNotifications(false);
+                       }
+               }
+       }
+}
+
+void ExternalCommandProcessor::DisableServicegroupSvcNotifications(double time, const std::vector<String>& arguments)
+{
+       if (arguments.size() < 1)
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
+
+       ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
+
+       if (!sg)
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable service notifications for non-existent servicegroup '" + arguments[0] + "'"));
+
+       BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
+               Log(LogInformation, "icinga", "Disabling notifications for service '" + service->GetName() + "'");
+
+               {
+                       ObjectLock olock(service);
+
+                       service->SetEnableNotifications(false);
+               }
+       }
+}
index 202c3cf95309e9db8da1385945b20a9d168b68b8..35317453da37cffbcc2ba8e9156add23d8b5d21c 100644 (file)
@@ -149,6 +149,14 @@ private:
        static void ChangeMaxSvcCheckAttempts(double time, const std::vector<String>& arguments);
        static void ChangeHostCheckTimeperiod(double time, const std::vector<String>& arguments);
        static void ChangeSvcCheckTimeperiod(double time, const std::vector<String>& arguments);
+       static void EnableHostgroupHostNotifications(double time, const std::vector<String>& arguments);
+       static void EnableHostgroupSvcNotifications(double time, const std::vector<String>& arguments);
+       static void DisableHostgroupHostNotifications(double time, const std::vector<String>& arguments);
+       static void DisableHostgroupSvcNotifications(double time, const std::vector<String>& arguments);
+       static void EnableServicegroupHostNotifications(double time, const std::vector<String>& arguments);
+       static void EnableServicegroupSvcNotifications(double time, const std::vector<String>& arguments);
+       static void DisableServicegroupHostNotifications(double time, const std::vector<String>& arguments);
+       static void DisableServicegroupSvcNotifications(double time, const std::vector<String>& arguments);
 };
 
 }