Implement missing host/servicegroup commands

fixes #5504
This commit is contained in:
Johannes Meyer 2014-01-20 16:58:18 +01:00
parent f11ed8a684
commit f8e6673123
2 changed files with 216 additions and 0 deletions

View 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);
}
}
}

View 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);
};
}