From 487ef513cf533991694525e8878d0d4fc1c0747a Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Mon, 28 Sep 2015 19:03:13 +0200 Subject: [PATCH] Remove dead code from old mod attrs in the cluster refs #9851 --- lib/icinga/apievents.cpp | 905 +-------------------------------------- lib/icinga/apievents.hpp | 39 -- 2 files changed, 1 insertion(+), 943 deletions(-) diff --git a/lib/icinga/apievents.cpp b/lib/icinga/apievents.cpp index 8a5e4932e..2dfeda7e5 100644 --- a/lib/icinga/apievents.cpp +++ b/lib/icinga/apievents.cpp @@ -43,19 +43,6 @@ REGISTER_APIFUNCTION(SetNextCheck, event, &ApiEvents::NextCheckChangedAPIHandler REGISTER_APIFUNCTION(SetNextNotification, event, &ApiEvents::NextNotificationChangedAPIHandler); REGISTER_APIFUNCTION(SetForceNextCheck, event, &ApiEvents::ForceNextCheckChangedAPIHandler); REGISTER_APIFUNCTION(SetForceNextNotification, event, &ApiEvents::ForceNextNotificationChangedAPIHandler); -REGISTER_APIFUNCTION(SetEnableActiveChecks, event, &ApiEvents::EnableActiveChecksChangedAPIHandler); -REGISTER_APIFUNCTION(SetEnablePassiveChecks, event, &ApiEvents::EnablePassiveChecksChangedAPIHandler); -REGISTER_APIFUNCTION(SetEnableNotifications, event, &ApiEvents::EnableNotificationsChangedAPIHandler); -REGISTER_APIFUNCTION(SetEnableFlapping, event, &ApiEvents::EnableFlappingChangedAPIHandler); -REGISTER_APIFUNCTION(SetEnableEventHandler, event, &ApiEvents::EnableEventHandlerChangedAPIHandler); -REGISTER_APIFUNCTION(SetEnablePerfdata, event, &ApiEvents::EnablePerfdataChangedAPIHandler); -REGISTER_APIFUNCTION(SetCheckInterval, event, &ApiEvents::CheckIntervalChangedAPIHandler); -REGISTER_APIFUNCTION(SetRetryInterval, event, &ApiEvents::RetryIntervalChangedAPIHandler); -REGISTER_APIFUNCTION(SetMaxCheckAttempts, event, &ApiEvents::MaxCheckAttemptsChangedAPIHandler); -REGISTER_APIFUNCTION(SetEventCommand, event, &ApiEvents::EventCommandChangedAPIHandler); -REGISTER_APIFUNCTION(SetCheckCommand, event, &ApiEvents::CheckCommandChangedAPIHandler); -REGISTER_APIFUNCTION(SetCheckPeriod, event, &ApiEvents::CheckPeriodChangedAPIHandler); -REGISTER_APIFUNCTION(SetVars, event, &ApiEvents::VarsChangedAPIHandler); REGISTER_APIFUNCTION(AddComment, event, &ApiEvents::CommentAddedAPIHandler); REGISTER_APIFUNCTION(RemoveComment, event, &ApiEvents::CommentRemovedAPIHandler); REGISTER_APIFUNCTION(AddDowntime, event, &ApiEvents::DowntimeAddedAPIHandler); @@ -74,19 +61,7 @@ void ApiEvents::StaticInitialize(void) Notification::OnNextNotificationChanged.connect(&ApiEvents::NextNotificationChangedHandler); Checkable::OnForceNextCheckChanged.connect(&ApiEvents::ForceNextCheckChangedHandler); Checkable::OnForceNextNotificationChanged.connect(&ApiEvents::ForceNextNotificationChangedHandler); - Checkable::OnEnableActiveChecksChanged.connect(&ApiEvents::EnableActiveChecksChangedHandler); - Checkable::OnEnablePassiveChecksChanged.connect(&ApiEvents::EnablePassiveChecksChangedHandler); - Checkable::OnEnableNotificationsChanged.connect(&ApiEvents::EnableNotificationsChangedHandler); - Checkable::OnEnableFlappingChanged.connect(&ApiEvents::EnableFlappingChangedHandler); - Checkable::OnEnableEventHandlerChanged.connect(&ApiEvents::EnableEventHandlerChangedHandler); - Checkable::OnEnablePerfdataChanged.connect(&ApiEvents::EnablePerfdataChangedHandler); - Checkable::OnCheckIntervalChanged.connect(&ApiEvents::CheckIntervalChangedHandler); - Checkable::OnRetryIntervalChanged.connect(&ApiEvents::RetryIntervalChangedHandler); - Checkable::OnMaxCheckAttemptsChanged.connect(&ApiEvents::MaxCheckAttemptsChangedHandler); - Checkable::OnEventCommandRawChanged.connect(&ApiEvents::EventCommandChangedHandler); - Checkable::OnCheckCommandRawChanged.connect(&ApiEvents::CheckCommandChangedHandler); - Checkable::OnCheckPeriodRawChanged.connect(&ApiEvents::CheckPeriodChangedHandler); - Checkable::OnVarsChanged.connect(&ApiEvents::VarsChangedHandler); + Checkable::OnCommentAdded.connect(&ApiEvents::CommentAddedHandler); Checkable::OnCommentRemoved.connect(&ApiEvents::CommentRemovedHandler); Checkable::OnDowntimeAdded.connect(&ApiEvents::DowntimeAddedHandler); @@ -447,884 +422,6 @@ Value ApiEvents::ForceNextNotificationChangedAPIHandler(const MessageOrigin::Ptr return Empty; } - -void ApiEvents::EnableActiveChecksChangedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin) -{ - ApiListener::Ptr listener = ApiListener::GetInstance(); - - if (!listener) - return; - - Host::Ptr host; - Service::Ptr service; - tie(host, service) = GetHostService(checkable); - - Dictionary::Ptr params = new Dictionary(); - params->Set("host", host->GetName()); - if (service) - params->Set("service", service->GetShortName()); - params->Set("enabled", checkable->GetEnableActiveChecks()); - - Dictionary::Ptr message = new Dictionary(); - message->Set("jsonrpc", "2.0"); - message->Set("method", "event::SetEnableActiveChecks"); - message->Set("params", params); - - listener->RelayMessage(origin, checkable, message, true); -} - -Value ApiEvents::EnableActiveChecksChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params) -{ - Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint(); - - if (!endpoint) { - Log(LogNotice, "ApiEvents") - << "Discarding 'enable active checks changed' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed)."; - return Empty; - } - - if (!params) - return Empty; - - Host::Ptr host = Host::GetByName(params->Get("host")); - - if (!host) - return Empty; - - Checkable::Ptr checkable; - - if (params->Contains("service")) - checkable = host->GetServiceByShortName(params->Get("service")); - else - checkable = host; - - if (!checkable) - return Empty; - - if (origin->FromZone && !origin->FromZone->CanAccessObject(checkable)) { - Log(LogNotice, "ApiEvents") - << "Discarding 'enable active checks' changed message from '" << origin->FromClient->GetIdentity() << "': Unauthorized access."; - return Empty; - } - - checkable->SetEnableActiveChecks(params->Get("enabled"), false, origin); - - return Empty; -} - -void ApiEvents::EnablePassiveChecksChangedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin) -{ - ApiListener::Ptr listener = ApiListener::GetInstance(); - - if (!listener) - return; - - Host::Ptr host; - Service::Ptr service; - tie(host, service) = GetHostService(checkable); - - Dictionary::Ptr params = new Dictionary(); - params->Set("host", host->GetName()); - if (service) - params->Set("service", service->GetShortName()); - params->Set("enabled", checkable->GetEnablePassiveChecks()); - - Dictionary::Ptr message = new Dictionary(); - message->Set("jsonrpc", "2.0"); - message->Set("method", "event::SetEnablePassiveChecks"); - message->Set("params", params); - - listener->RelayMessage(origin, checkable, message, true); -} - -Value ApiEvents::EnablePassiveChecksChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params) -{ - Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint(); - - if (!endpoint) { - Log(LogNotice, "ApiEvents") - << "Discarding 'enable passive checks changed' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed)."; - return Empty; - } - - if (!params) - return Empty; - - Host::Ptr host = Host::GetByName(params->Get("host")); - - if (!host) - return Empty; - - Checkable::Ptr checkable; - - if (params->Contains("service")) - checkable = host->GetServiceByShortName(params->Get("service")); - else - checkable = host; - - if (!checkable) - return Empty; - - if (origin->FromZone && !origin->FromZone->CanAccessObject(checkable)) { - Log(LogNotice, "ApiEvents") - << "Discarding 'enable passive checks changed' message from '" << origin->FromClient->GetIdentity() << "': Unauthorized access."; - return Empty; - } - - checkable->SetEnablePassiveChecks(params->Get("enabled"), false, origin); - - return Empty; -} - -void ApiEvents::EnableNotificationsChangedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin) -{ - ApiListener::Ptr listener = ApiListener::GetInstance(); - - if (!listener) - return; - - Host::Ptr host; - Service::Ptr service; - tie(host, service) = GetHostService(checkable); - - Dictionary::Ptr params = new Dictionary(); - params->Set("host", host->GetName()); - if (service) - params->Set("service", service->GetShortName()); - params->Set("enabled", checkable->GetEnableNotifications()); - - Dictionary::Ptr message = new Dictionary(); - message->Set("jsonrpc", "2.0"); - message->Set("method", "event::SetEnableNotifications"); - message->Set("params", params); - - listener->RelayMessage(origin, checkable, message, true); -} - -Value ApiEvents::EnableNotificationsChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params) -{ - Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint(); - - if (!endpoint) { - Log(LogNotice, "ApiEvents") - << "Discarding 'enable notifications changed' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed)."; - return Empty; - } - - if (!params) - return Empty; - - Host::Ptr host = Host::GetByName(params->Get("host")); - - if (!host) - return Empty; - - Checkable::Ptr checkable; - - if (params->Contains("service")) - checkable = host->GetServiceByShortName(params->Get("service")); - else - checkable = host; - - if (!checkable) - return Empty; - - if (origin->FromZone && !origin->FromZone->CanAccessObject(checkable)) { - Log(LogNotice, "ApiEvents") - << "Discarding 'enable notifications changed' message from '" << origin->FromClient->GetIdentity() << "': Unauthorized access."; - return Empty; - } - - checkable->SetEnableNotifications(params->Get("enabled"), false, origin); - - return Empty; -} - -void ApiEvents::EnableFlappingChangedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin) -{ - ApiListener::Ptr listener = ApiListener::GetInstance(); - - if (!listener) - return; - - Host::Ptr host; - Service::Ptr service; - tie(host, service) = GetHostService(checkable); - - Dictionary::Ptr params = new Dictionary(); - params->Set("host", host->GetName()); - if (service) - params->Set("service", service->GetShortName()); - params->Set("enabled", checkable->GetEnableFlapping()); - - Dictionary::Ptr message = new Dictionary(); - message->Set("jsonrpc", "2.0"); - message->Set("method", "event::SetEnableFlapping"); - message->Set("params", params); - - listener->RelayMessage(origin, checkable, message, true); -} - -Value ApiEvents::EnableFlappingChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params) -{ - Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint(); - - if (!endpoint) { - Log(LogNotice, "ApiEvents") - << "Discarding 'enable flapping changed' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed)."; - return Empty; - } - - if (!params) - return Empty; - - Host::Ptr host = Host::GetByName(params->Get("host")); - - if (!host) - return Empty; - - Checkable::Ptr checkable; - - if (params->Contains("service")) - checkable = host->GetServiceByShortName(params->Get("service")); - else - checkable = host; - - if (!checkable) - return Empty; - - if (origin->FromZone && !origin->FromZone->CanAccessObject(checkable)) { - Log(LogNotice, "ApiEvents") - << "Discarding 'enable flapping changed' message from '" << origin->FromClient->GetIdentity() << "': Unauthorized access."; - return Empty; - } - - checkable->SetEnableFlapping(params->Get("enabled"), false, origin); - - return Empty; -} - -void ApiEvents::EnableEventHandlerChangedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin) -{ - ApiListener::Ptr listener = ApiListener::GetInstance(); - - if (!listener) - return; - - Host::Ptr host; - Service::Ptr service; - tie(host, service) = GetHostService(checkable); - - Dictionary::Ptr params = new Dictionary(); - params->Set("host", host->GetName()); - if (service) - params->Set("service", service->GetShortName()); - params->Set("enabled", checkable->GetEnableEventHandler()); - - Dictionary::Ptr message = new Dictionary(); - message->Set("jsonrpc", "2.0"); - message->Set("method", "event::SetEnableEventHandler"); - message->Set("params", params); - - listener->RelayMessage(origin, checkable, message, true); -} - -Value ApiEvents::EnableEventHandlerChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params) -{ - Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint(); - - if (!endpoint) { - Log(LogNotice, "ApiEvents") - << "Discarding 'enable event handler changed' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed)."; - return Empty; - } - - if (!params) - return Empty; - - Host::Ptr host = Host::GetByName(params->Get("host")); - - if (!host) - return Empty; - - Checkable::Ptr checkable; - - if (params->Contains("service")) - checkable = host->GetServiceByShortName(params->Get("service")); - else - checkable = host; - - if (!checkable) - return Empty; - - if (origin->FromZone && !origin->FromZone->CanAccessObject(checkable)) { - Log(LogNotice, "ApiEvents") - << "Discarding 'enable event handler' message from '" << origin->FromClient->GetIdentity() << "': Unauthorized access."; - return Empty; - } - - checkable->SetEnableEventHandler(params->Get("enabled"), false, origin); - - return Empty; -} - -void ApiEvents::EnablePerfdataChangedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin) -{ - ApiListener::Ptr listener = ApiListener::GetInstance(); - - if (!listener) - return; - - Host::Ptr host; - Service::Ptr service; - tie(host, service) = GetHostService(checkable); - - Dictionary::Ptr params = new Dictionary(); - params->Set("host", host->GetName()); - if (service) - params->Set("service", service->GetShortName()); - params->Set("enabled", checkable->GetEnablePerfdata()); - - Dictionary::Ptr message = new Dictionary(); - message->Set("jsonrpc", "2.0"); - message->Set("method", "event::SetEnablePerfdata"); - message->Set("params", params); - - listener->RelayMessage(origin, checkable, message, true); -} - -Value ApiEvents::EnablePerfdataChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params) -{ - Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint(); - - if (!endpoint) { - Log(LogNotice, "ApiEvents") - << "Discarding 'enable perfdata changed' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed)."; - return Empty; - } - - if (!params) - return Empty; - - Host::Ptr host = Host::GetByName(params->Get("host")); - - if (!host) - return Empty; - - Checkable::Ptr checkable; - - if (params->Contains("service")) - checkable = host->GetServiceByShortName(params->Get("service")); - else - checkable = host; - - if (!checkable) - return Empty; - - if (origin->FromZone && !origin->FromZone->CanAccessObject(checkable)) { - Log(LogNotice, "ApiEvents") - << "Discarding 'enable perfdata changed' message from '" << origin->FromClient->GetIdentity() << "': Unauthorized access."; - return Empty; - } - - checkable->SetEnablePerfdata(params->Get("enabled"), false, origin); - - return Empty; -} - -void ApiEvents::CheckIntervalChangedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin) -{ - ApiListener::Ptr listener = ApiListener::GetInstance(); - - if (!listener) - return; - - Host::Ptr host; - Service::Ptr service; - tie(host, service) = GetHostService(checkable); - - Dictionary::Ptr params = new Dictionary(); - params->Set("host", host->GetName()); - if (service) - params->Set("service", service->GetShortName()); - params->Set("interval", checkable->GetCheckInterval()); - - Dictionary::Ptr message = new Dictionary(); - message->Set("jsonrpc", "2.0"); - message->Set("method", "event::SetCheckInterval"); - message->Set("params", params); - - listener->RelayMessage(origin, checkable, message, true); -} - -Value ApiEvents::CheckIntervalChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params) -{ - Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint(); - - if (!endpoint) { - Log(LogNotice, "ApiEvents") - << "Discarding 'check interval changed' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed)."; - return Empty; - } - - if (!params) - return Empty; - - Host::Ptr host = Host::GetByName(params->Get("host")); - - if (!host) - return Empty; - - Checkable::Ptr checkable; - - if (params->Contains("service")) - checkable = host->GetServiceByShortName(params->Get("service")); - else - checkable = host; - - if (!checkable) - return Empty; - - if (origin->FromZone && !origin->FromZone->CanAccessObject(checkable)) { - Log(LogNotice, "ApiEvents") - << "Discarding 'check interval' changed message from '" << origin->FromClient->GetIdentity() << "': Unauthorized access."; - return Empty; - } - - checkable->SetCheckInterval(params->Get("interval"), false, origin); - - return Empty; -} - -void ApiEvents::RetryIntervalChangedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin) -{ - ApiListener::Ptr listener = ApiListener::GetInstance(); - - if (!listener) - return; - - Host::Ptr host; - Service::Ptr service; - tie(host, service) = GetHostService(checkable); - - Dictionary::Ptr params = new Dictionary(); - params->Set("host", host->GetName()); - if (service) - params->Set("service", service->GetShortName()); - params->Set("interval", checkable->GetRetryInterval()); - - Dictionary::Ptr message = new Dictionary(); - message->Set("jsonrpc", "2.0"); - message->Set("method", "event::SetRetryInterval"); - message->Set("params", params); - - listener->RelayMessage(origin, checkable, message, true); -} - -Value ApiEvents::RetryIntervalChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params) -{ - Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint(); - - if (!endpoint) { - Log(LogNotice, "ApiEvents") - << "Discarding 'retry interval changed' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed)."; - return Empty; - } - - if (!params) - return Empty; - - Host::Ptr host = Host::GetByName(params->Get("host")); - - if (!host) - return Empty; - - Checkable::Ptr checkable; - - if (params->Contains("service")) - checkable = host->GetServiceByShortName(params->Get("service")); - else - checkable = host; - - if (!checkable) - return Empty; - - if (origin->FromZone && !origin->FromZone->CanAccessObject(checkable)) { - Log(LogNotice, "ApiEvents") - << "Discarding 'retry interval' changed message from '" << origin->FromClient->GetIdentity() << "': Unauthorized access."; - return Empty; - } - - checkable->SetRetryInterval(params->Get("interval"), false, origin); - - return Empty; -} - -void ApiEvents::MaxCheckAttemptsChangedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin) -{ - ApiListener::Ptr listener = ApiListener::GetInstance(); - - if (!listener) - return; - - Host::Ptr host; - Service::Ptr service; - tie(host, service) = GetHostService(checkable); - - Dictionary::Ptr params = new Dictionary(); - params->Set("host", host->GetName()); - if (service) - params->Set("service", service->GetShortName()); - params->Set("attempts", checkable->GetMaxCheckAttempts()); - - Dictionary::Ptr message = new Dictionary(); - message->Set("jsonrpc", "2.0"); - message->Set("method", "event::SetMaxCheckAttempts"); - message->Set("params", params); - - listener->RelayMessage(origin, checkable, message, true); -} - -Value ApiEvents::MaxCheckAttemptsChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params) -{ - Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint(); - - if (!endpoint) { - Log(LogNotice, "ApiEvents") - << "Discarding 'max checkt attempts changed' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed)."; - return Empty; - } - - if (!params) - return Empty; - - Host::Ptr host = Host::GetByName(params->Get("host")); - - if (!host) - return Empty; - - Checkable::Ptr checkable; - - if (params->Contains("service")) - checkable = host->GetServiceByShortName(params->Get("service")); - else - checkable = host; - - if (!checkable) - return Empty; - - if (origin->FromZone && !origin->FromZone->CanAccessObject(checkable)) { - Log(LogNotice, "ApiEvents") - << "Discarding 'max check attempts changed' message from '" << origin->FromClient->GetIdentity() << "': Unauthorized access."; - return Empty; - } - - checkable->SetMaxCheckAttempts(params->Get("attempts"), false, origin); - - return Empty; -} - -void ApiEvents::EventCommandChangedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin) -{ - ApiListener::Ptr listener = ApiListener::GetInstance(); - - if (!listener) - return; - - Host::Ptr host; - Service::Ptr service; - tie(host, service) = GetHostService(checkable); - - Dictionary::Ptr params = new Dictionary(); - params->Set("host", host->GetName()); - if (service) - params->Set("service", service->GetShortName()); - params->Set("command", checkable->GetEventCommand()); - - Dictionary::Ptr message = new Dictionary(); - message->Set("jsonrpc", "2.0"); - message->Set("method", "event::SetEventCommand"); - message->Set("params", params); - - listener->RelayMessage(origin, checkable, message, true); -} - -Value ApiEvents::EventCommandChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params) -{ - Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint(); - - if (!endpoint) { - Log(LogNotice, "ApiEvents") - << "Discarding 'event command changed' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed)."; - return Empty; - } - - if (!params) - return Empty; - - Host::Ptr host = Host::GetByName(params->Get("host")); - - if (!host) - return Empty; - - Checkable::Ptr checkable; - - if (params->Contains("service")) - checkable = host->GetServiceByShortName(params->Get("service")); - else - checkable = host; - - if (!checkable) - return Empty; - - EventCommand::Ptr command = EventCommand::GetByName(params->Get("command")); - - if (!command) - return Empty; - - if (origin->FromZone && !origin->FromZone->CanAccessObject(checkable)) { - Log(LogNotice, "ApiEvents") - << "Discarding 'event command changed' message from '" << origin->FromClient->GetIdentity() << "': Unauthorized access."; - return Empty; - } - - checkable->SetEventCommandRaw(command->GetName(), false, origin); - - return Empty; -} - -void ApiEvents::CheckCommandChangedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin) -{ - ApiListener::Ptr listener = ApiListener::GetInstance(); - - if (!listener) - return; - - Host::Ptr host; - Service::Ptr service; - tie(host, service) = GetHostService(checkable); - - Dictionary::Ptr params = new Dictionary(); - params->Set("host", host->GetName()); - if (service) - params->Set("service", service->GetShortName()); - params->Set("command", checkable->GetCheckCommand()); - - Dictionary::Ptr message = new Dictionary(); - message->Set("jsonrpc", "2.0"); - message->Set("method", "event::SetCheckCommand"); - message->Set("params", params); - - listener->RelayMessage(origin, checkable, message, true); -} - -Value ApiEvents::CheckCommandChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params) -{ - Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint(); - - if (!endpoint) { - Log(LogNotice, "ApiEvents") - << "Discarding 'check command changed' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed)."; - return Empty; - } - - if (!params) - return Empty; - - Host::Ptr host = Host::GetByName(params->Get("host")); - - if (!host) - return Empty; - - Checkable::Ptr checkable; - - if (params->Contains("service")) - checkable = host->GetServiceByShortName(params->Get("service")); - else - checkable = host; - - if (!checkable) - return Empty; - - if (origin->FromZone && !origin->FromZone->CanAccessObject(checkable)) { - Log(LogNotice, "ApiEvents") - << "Discarding 'check command changed' message from '" << origin->FromClient->GetIdentity() << "': Unauthorized access."; - return Empty; - } - - CheckCommand::Ptr command = CheckCommand::GetByName(params->Get("command")); - - if (!command) - return Empty; - - checkable->SetCheckCommandRaw(command->GetName(), false, origin); - - return Empty; -} - -void ApiEvents::CheckPeriodChangedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin) -{ - ApiListener::Ptr listener = ApiListener::GetInstance(); - - if (!listener) - return; - - Host::Ptr host; - Service::Ptr service; - tie(host, service) = GetHostService(checkable); - - Dictionary::Ptr params = new Dictionary(); - params->Set("host", host->GetName()); - if (service) - params->Set("service", service->GetShortName()); - params->Set("timeperiod", checkable->GetCheckPeriod()); - - Dictionary::Ptr message = new Dictionary(); - message->Set("jsonrpc", "2.0"); - message->Set("method", "event::SetCheckPeriod"); - message->Set("params", params); - - listener->RelayMessage(origin, checkable, message, true); -} - -Value ApiEvents::CheckPeriodChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params) -{ - Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint(); - - if (!endpoint) { - Log(LogNotice, "ApiEvents") - << "Discarding 'check period changed' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed)."; - return Empty; - } - - if (!params) - return Empty; - - Host::Ptr host = Host::GetByName(params->Get("host")); - - if (!host) - return Empty; - - Checkable::Ptr checkable; - - if (params->Contains("service")) - checkable = host->GetServiceByShortName(params->Get("service")); - else - checkable = host; - - if (!checkable) - return Empty; - - if (origin->FromZone && !origin->FromZone->CanAccessObject(checkable)) { - Log(LogNotice, "ApiEvents") - << "Discarding 'check period changed' message from '" << origin->FromClient->GetIdentity() << "': Unauthorized access."; - return Empty; - } - - TimePeriod::Ptr timeperiod = TimePeriod::GetByName(params->Get("timeperiod")); - - if (!timeperiod) - return Empty; - - checkable->SetCheckPeriodRaw(timeperiod->GetName(), false, origin); - - return Empty; -} - -void ApiEvents::VarsChangedHandler(const CustomVarObject::Ptr& object, const MessageOrigin::Ptr& origin) -{ - ApiListener::Ptr listener = ApiListener::GetInstance(); - - if (!listener) - return; - - Dictionary::Ptr params = new Dictionary(); - params->Set("object", object->GetName()); - - ConfigType::Ptr dtype = object->GetType(); - ASSERT(dtype); - - params->Set("object_type", dtype->GetName()); - Log(LogDebug, "ApiEvents") - << "Changed vars handler for object name: '" << object->GetName() << "' type: '" << dtype->GetName() << "'."; - - params->Set("vars", Serialize(object->GetVars())); - - Dictionary::Ptr message = new Dictionary(); - message->Set("jsonrpc", "2.0"); - message->Set("method", "event::SetVars"); - message->Set("params", params); - - listener->RelayMessage(origin, object, message, true); -} - -Value ApiEvents::VarsChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params) -{ - Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint(); - - if (!endpoint) { - Log(LogNotice, "ApiEvents") - << "Discarding 'vars changed' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed)."; - return Empty; - } - - if (!params) - return Empty; - - String objectName = params->Get("object"); - String objectType = params->Get("object_type"); - - if (objectName.IsEmpty()) - return Empty; - - CustomVarObject::Ptr object; - - if (objectType.IsEmpty()) { - /* keep the old broken way for compatibility reasons for <= v2.3.5 */ - object = Host::GetByName(objectName); - if (!object) - object = Service::GetByName(objectName); - if (!object) - object = User::GetByName(objectName); - if (!object) - object = Service::GetByName(objectName); - if (!object) - object = EventCommand::GetByName(objectName); - if (!object) - object = CheckCommand::GetByName(objectName); - if (!object) - object = NotificationCommand::GetByName(objectName); - } else { - ConfigType::Ptr dtype = ConfigType::GetByName(objectType); - - if (!dtype) - return Empty; - - object = dynamic_pointer_cast(dtype->GetObject(objectName)); - } - - if (!object) - return Empty; - - Log(LogDebug, "ApiEvents") - << "Processing 'vars changed' for object: '" << object->GetName() << "' type: '" << object->GetType()->GetName() << "'."; - - if (origin->FromZone && !origin->FromZone->CanAccessObject(object)) { - Log(LogNotice, "ApiEvents") - << "Discarding 'vars changed' message from '" << origin->FromClient->GetIdentity() << "': Unauthorized access."; - return Empty; - } - - Dictionary::Ptr vars = params->Get("vars"); - - if (!vars) - return Empty; - - object->SetVars(vars, false, origin); - - return Empty; -} - void ApiEvents::CommentAddedHandler(const Checkable::Ptr& checkable, const Comment::Ptr& comment, const MessageOrigin::Ptr& origin) { ApiListener::Ptr listener = ApiListener::GetInstance(); diff --git a/lib/icinga/apievents.hpp b/lib/icinga/apievents.hpp index e1d92d279..f01754b97 100644 --- a/lib/icinga/apievents.hpp +++ b/lib/icinga/apievents.hpp @@ -52,45 +52,6 @@ public: static void ForceNextNotificationChangedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin); static Value ForceNextNotificationChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params); - static void EnableActiveChecksChangedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin); - static Value EnableActiveChecksChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params); - - static void EnablePassiveChecksChangedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin); - static Value EnablePassiveChecksChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params); - - static void EnableNotificationsChangedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin); - static Value EnableNotificationsChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params); - - static void EnableFlappingChangedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin); - static Value EnableFlappingChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params); - - static void EnableEventHandlerChangedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin); - static Value EnableEventHandlerChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params); - - static void EnablePerfdataChangedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin); - static Value EnablePerfdataChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params); - - static void CheckIntervalChangedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin); - static Value CheckIntervalChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params); - - static void RetryIntervalChangedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin); - static Value RetryIntervalChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params); - - static void MaxCheckAttemptsChangedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin); - static Value MaxCheckAttemptsChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params); - - static void EventCommandChangedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin); - static Value EventCommandChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params); - - static void CheckCommandChangedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin); - static Value CheckCommandChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params); - - static void CheckPeriodChangedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin); - static Value CheckPeriodChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params); - - static void VarsChangedHandler(const CustomVarObject::Ptr& object, const MessageOrigin::Ptr& origin); - static Value VarsChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params); - static void CommentAddedHandler(const Checkable::Ptr& checkable, const Comment::Ptr& comment, const MessageOrigin::Ptr& origin); static Value CommentAddedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params); -- 2.40.0