2014-05-03 20:02:22 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2015-01-22 12:00:23 +01:00
|
|
|
* Copyright (C) 2012-2015 Icinga Development Team (http://www.icinga.org) *
|
2014-05-03 20:02:22 +02:00
|
|
|
* *
|
|
|
|
* 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. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "icinga/apievents.hpp"
|
|
|
|
#include "icinga/service.hpp"
|
2014-10-28 15:24:35 +01:00
|
|
|
#include "icinga/perfdatavalue.hpp"
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "remote/apilistener.hpp"
|
|
|
|
#include "remote/endpoint.hpp"
|
|
|
|
#include "remote/messageorigin.hpp"
|
|
|
|
#include "remote/zone.hpp"
|
|
|
|
#include "remote/apifunction.hpp"
|
|
|
|
#include "base/application.hpp"
|
|
|
|
#include "base/dynamictype.hpp"
|
|
|
|
#include "base/utility.hpp"
|
|
|
|
#include "base/exception.hpp"
|
|
|
|
#include "base/initialize.hpp"
|
2014-10-26 19:59:49 +01:00
|
|
|
#include "base/serializer.hpp"
|
|
|
|
#include "base/json.hpp"
|
2014-05-03 20:02:22 +02:00
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
|
|
|
INITIALIZE_ONCE(&ApiEvents::StaticInitialize);
|
|
|
|
|
|
|
|
REGISTER_APIFUNCTION(CheckResult, event, &ApiEvents::CheckResultAPIHandler);
|
|
|
|
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);
|
2014-08-26 15:29:55 +02:00
|
|
|
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);
|
2014-05-03 20:02:22 +02:00
|
|
|
REGISTER_APIFUNCTION(AddComment, event, &ApiEvents::CommentAddedAPIHandler);
|
|
|
|
REGISTER_APIFUNCTION(RemoveComment, event, &ApiEvents::CommentRemovedAPIHandler);
|
|
|
|
REGISTER_APIFUNCTION(AddDowntime, event, &ApiEvents::DowntimeAddedAPIHandler);
|
|
|
|
REGISTER_APIFUNCTION(RemoveDowntime, event, &ApiEvents::DowntimeRemovedAPIHandler);
|
|
|
|
REGISTER_APIFUNCTION(SetAcknowledgement, event, &ApiEvents::AcknowledgementSetAPIHandler);
|
|
|
|
REGISTER_APIFUNCTION(ClearAcknowledgement, event, &ApiEvents::AcknowledgementClearedAPIHandler);
|
|
|
|
REGISTER_APIFUNCTION(UpdateRepository, event, &ApiEvents::UpdateRepositoryAPIHandler);
|
2014-11-13 11:23:57 +01:00
|
|
|
REGISTER_APIFUNCTION(ExecuteCommand, event, &ApiEvents::ExecuteCommandAPIHandler);
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
static Timer::Ptr l_RepositoryTimer;
|
|
|
|
|
|
|
|
void ApiEvents::StaticInitialize(void)
|
|
|
|
{
|
|
|
|
Checkable::OnNewCheckResult.connect(&ApiEvents::CheckResultHandler);
|
|
|
|
Checkable::OnNextCheckChanged.connect(&ApiEvents::NextCheckChangedHandler);
|
|
|
|
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);
|
2014-08-26 15:29:55 +02:00
|
|
|
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::OnEventCommandChanged.connect(&ApiEvents::EventCommandChangedHandler);
|
|
|
|
Checkable::OnCheckCommandChanged.connect(&ApiEvents::CheckCommandChangedHandler);
|
|
|
|
Checkable::OnCheckPeriodChanged.connect(&ApiEvents::CheckPeriodChangedHandler);
|
|
|
|
Checkable::OnVarsChanged.connect(&ApiEvents::VarsChangedHandler);
|
2014-05-03 20:02:22 +02:00
|
|
|
Checkable::OnCommentAdded.connect(&ApiEvents::CommentAddedHandler);
|
|
|
|
Checkable::OnCommentRemoved.connect(&ApiEvents::CommentRemovedHandler);
|
|
|
|
Checkable::OnDowntimeAdded.connect(&ApiEvents::DowntimeAddedHandler);
|
|
|
|
Checkable::OnDowntimeRemoved.connect(&ApiEvents::DowntimeRemovedHandler);
|
|
|
|
Checkable::OnAcknowledgementSet.connect(&ApiEvents::AcknowledgementSetHandler);
|
|
|
|
Checkable::OnAcknowledgementCleared.connect(&ApiEvents::AcknowledgementClearedHandler);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
l_RepositoryTimer = new Timer();
|
2014-05-08 15:46:47 +02:00
|
|
|
l_RepositoryTimer->SetInterval(30);
|
2014-05-03 20:02:22 +02:00
|
|
|
l_RepositoryTimer->OnTimerExpired.connect(boost::bind(&ApiEvents::RepositoryTimerHandler));
|
|
|
|
l_RepositoryTimer->Start();
|
|
|
|
l_RepositoryTimer->Reschedule(0);
|
|
|
|
}
|
|
|
|
|
2014-11-13 11:23:57 +01:00
|
|
|
Dictionary::Ptr ApiEvents::MakeCheckResultMessage(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr)
|
2014-05-03 20:02:22 +02:00
|
|
|
{
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr message = new Dictionary();
|
2014-05-03 20:02:22 +02:00
|
|
|
message->Set("jsonrpc", "2.0");
|
|
|
|
message->Set("method", "event::CheckResult");
|
|
|
|
|
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr params = new Dictionary();
|
2014-08-22 12:59:24 +02:00
|
|
|
params->Set("host", host->GetName());
|
2014-05-03 20:02:22 +02:00
|
|
|
if (service)
|
|
|
|
params->Set("service", service->GetShortName());
|
2014-11-13 11:23:57 +01:00
|
|
|
else {
|
|
|
|
Value agent_service_name = checkable->GetExtension("agent_service_name");
|
|
|
|
|
|
|
|
if (!agent_service_name.IsEmpty())
|
|
|
|
params->Set("service", agent_service_name);
|
|
|
|
}
|
2014-05-03 20:02:22 +02:00
|
|
|
params->Set("cr", Serialize(cr));
|
|
|
|
|
|
|
|
message->Set("params", params);
|
|
|
|
|
2014-11-13 11:23:57 +01:00
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiEvents::CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const MessageOrigin& origin)
|
|
|
|
{
|
|
|
|
ApiListener::Ptr listener = ApiListener::GetInstance();
|
|
|
|
|
|
|
|
if (!listener)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Dictionary::Ptr message = MakeCheckResultMessage(checkable, cr);
|
2014-05-03 20:02:22 +02:00
|
|
|
listener->RelayMessage(origin, checkable, message, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
Value ApiEvents::CheckResultAPIHandler(const MessageOrigin& origin, const Dictionary::Ptr& params)
|
|
|
|
{
|
2014-11-13 11:23:57 +01:00
|
|
|
Endpoint::Ptr endpoint = origin.FromClient->GetEndpoint();
|
|
|
|
|
2015-07-02 13:04:38 +02:00
|
|
|
if (!endpoint) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'check result' message from '" << origin.FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
|
2014-10-16 13:04:04 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-10-16 13:04:04 +02:00
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
if (!params)
|
|
|
|
return Empty;
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
CheckResult::Ptr cr = new CheckResult();
|
2014-10-28 15:24:35 +01:00
|
|
|
|
|
|
|
Dictionary::Ptr vcr = params->Get("cr");
|
|
|
|
Array::Ptr vperf = vcr->Get("performance_data");
|
|
|
|
vcr->Remove("performance_data");
|
|
|
|
|
2014-10-25 09:14:56 +02:00
|
|
|
Deserialize(cr, params->Get("cr"), true);
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Array::Ptr rperf = new Array();
|
2014-10-28 15:24:35 +01:00
|
|
|
|
2014-11-05 09:58:43 +01:00
|
|
|
if (vperf) {
|
|
|
|
ObjectLock olock(vperf);
|
|
|
|
BOOST_FOREACH(const Value& vp, vperf) {
|
|
|
|
Value p;
|
|
|
|
|
|
|
|
if (vp.IsObjectType<Dictionary>()) {
|
2014-11-08 21:17:16 +01:00
|
|
|
PerfdataValue::Ptr val = new PerfdataValue();
|
2014-11-05 09:58:43 +01:00
|
|
|
Deserialize(val, vp, true);
|
|
|
|
rperf->Add(val);
|
|
|
|
} else
|
|
|
|
rperf->Add(vp);
|
|
|
|
}
|
2014-10-28 15:24:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cr->SetPerformanceData(rperf);
|
|
|
|
|
2014-10-28 14:05:17 +01:00
|
|
|
Host::Ptr host = Host::GetByName(params->Get("host"));
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
if (!host)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
Checkable::Ptr checkable;
|
|
|
|
|
|
|
|
if (params->Contains("service"))
|
|
|
|
checkable = host->GetServiceByShortName(params->Get("service"));
|
|
|
|
else
|
|
|
|
checkable = host;
|
|
|
|
|
|
|
|
if (!checkable)
|
|
|
|
return Empty;
|
|
|
|
|
2015-07-02 13:04:38 +02:00
|
|
|
if (origin.FromZone && !origin.FromZone->CanAccessObject(checkable) && endpoint != checkable->GetCommandEndpoint()) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'check result' message from '" << origin.FromClient->GetIdentity() << "': Unauthorized access.";
|
2014-05-03 20:02:22 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2015-03-30 13:39:24 +02:00
|
|
|
if (endpoint == checkable->GetCommandEndpoint())
|
|
|
|
checkable->ProcessCheckResult(cr);
|
|
|
|
else
|
|
|
|
checkable->ProcessCheckResult(cr, origin);
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
return Empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiEvents::NextCheckChangedHandler(const Checkable::Ptr& checkable, double nextCheck, const MessageOrigin& origin)
|
|
|
|
{
|
|
|
|
ApiListener::Ptr listener = ApiListener::GetInstance();
|
|
|
|
|
|
|
|
if (!listener)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr params = new Dictionary();
|
2014-08-22 12:59:24 +02:00
|
|
|
params->Set("host", host->GetName());
|
2014-05-03 20:02:22 +02:00
|
|
|
if (service)
|
|
|
|
params->Set("service", service->GetShortName());
|
|
|
|
params->Set("next_check", nextCheck);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr message = new Dictionary();
|
2014-05-03 20:02:22 +02:00
|
|
|
message->Set("jsonrpc", "2.0");
|
|
|
|
message->Set("method", "event::SetNextCheck");
|
|
|
|
message->Set("params", params);
|
|
|
|
|
|
|
|
listener->RelayMessage(origin, checkable, message, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
Value ApiEvents::NextCheckChangedAPIHandler(const MessageOrigin& origin, const Dictionary::Ptr& params)
|
|
|
|
{
|
2015-07-02 13:04:38 +02:00
|
|
|
Endpoint::Ptr endpoint = origin.FromClient->GetEndpoint();
|
|
|
|
|
|
|
|
if (!endpoint) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'next check changed' message from '" << origin.FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
|
2014-10-16 13:04:04 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-10-16 13:04:04 +02:00
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
if (!params)
|
|
|
|
return Empty;
|
|
|
|
|
2014-10-28 14:05:17 +01:00
|
|
|
Host::Ptr host = Host::GetByName(params->Get("host"));
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
if (!host)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
Checkable::Ptr checkable;
|
|
|
|
|
|
|
|
if (params->Contains("service"))
|
|
|
|
checkable = host->GetServiceByShortName(params->Get("service"));
|
|
|
|
else
|
|
|
|
checkable = host;
|
|
|
|
|
|
|
|
if (!checkable)
|
|
|
|
return Empty;
|
|
|
|
|
2015-07-02 13:04:38 +02:00
|
|
|
if (origin.FromZone && !origin.FromZone->CanAccessObject(checkable)) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'next check changed' message from '" << origin.FromClient->GetIdentity() << "': Unauthorized access.";
|
2014-05-03 20:02:22 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
checkable->SetNextCheck(params->Get("next_check"), origin);
|
|
|
|
|
|
|
|
return Empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiEvents::NextNotificationChangedHandler(const Notification::Ptr& notification, double nextNotification, const MessageOrigin& origin)
|
|
|
|
{
|
|
|
|
ApiListener::Ptr listener = ApiListener::GetInstance();
|
|
|
|
|
|
|
|
if (!listener)
|
|
|
|
return;
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr params = new Dictionary();
|
2014-05-03 20:02:22 +02:00
|
|
|
params->Set("notification", notification->GetName());
|
|
|
|
params->Set("next_notification", nextNotification);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr message = new Dictionary();
|
2014-05-03 20:02:22 +02:00
|
|
|
message->Set("jsonrpc", "2.0");
|
|
|
|
message->Set("method", "event::SetNextNotification");
|
|
|
|
message->Set("params", params);
|
|
|
|
|
|
|
|
listener->RelayMessage(origin, notification, message, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
Value ApiEvents::NextNotificationChangedAPIHandler(const MessageOrigin& origin, const Dictionary::Ptr& params)
|
|
|
|
{
|
2015-07-02 13:04:38 +02:00
|
|
|
Endpoint::Ptr endpoint = origin.FromClient->GetEndpoint();
|
|
|
|
|
|
|
|
if (!endpoint) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'next notification changed' message from '" << origin.FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
|
2014-10-16 13:04:04 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-10-16 13:04:04 +02:00
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
if (!params)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
Notification::Ptr notification = Notification::GetByName(params->Get("notification"));
|
|
|
|
|
|
|
|
if (!notification)
|
|
|
|
return Empty;
|
|
|
|
|
2015-07-02 13:04:38 +02:00
|
|
|
if (origin.FromZone && !origin.FromZone->CanAccessObject(notification)) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'next notification changed' message from '" << origin.FromClient->GetIdentity() << "': Unauthorized access.";
|
2014-05-03 20:02:22 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
notification->SetNextNotification(params->Get("next_notification"), origin);
|
|
|
|
|
|
|
|
return Empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiEvents::ForceNextCheckChangedHandler(const Checkable::Ptr& checkable, bool forced, const MessageOrigin& origin)
|
|
|
|
{
|
|
|
|
ApiListener::Ptr listener = ApiListener::GetInstance();
|
|
|
|
|
|
|
|
if (!listener)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr params = new Dictionary();
|
2014-08-22 12:59:24 +02:00
|
|
|
params->Set("host", host->GetName());
|
2014-05-03 20:02:22 +02:00
|
|
|
if (service)
|
|
|
|
params->Set("service", service->GetShortName());
|
|
|
|
params->Set("forced", forced);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr message = new Dictionary();
|
2014-05-03 20:02:22 +02:00
|
|
|
message->Set("jsonrpc", "2.0");
|
|
|
|
message->Set("method", "event::SetForceNextCheck");
|
|
|
|
message->Set("params", params);
|
|
|
|
|
|
|
|
listener->RelayMessage(origin, checkable, message, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
Value ApiEvents::ForceNextCheckChangedAPIHandler(const MessageOrigin& origin, const Dictionary::Ptr& params)
|
|
|
|
{
|
2015-07-02 13:04:38 +02:00
|
|
|
Endpoint::Ptr endpoint = origin.FromClient->GetEndpoint();
|
|
|
|
|
|
|
|
if (!endpoint) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'force next check changed' message from '" << origin.FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
|
2014-10-16 13:04:04 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-10-16 13:04:04 +02:00
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
if (!params)
|
|
|
|
return Empty;
|
|
|
|
|
2014-10-28 14:05:17 +01:00
|
|
|
Host::Ptr host = Host::GetByName(params->Get("host"));
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
if (!host)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
Checkable::Ptr checkable;
|
|
|
|
|
|
|
|
if (params->Contains("service"))
|
|
|
|
checkable = host->GetServiceByShortName(params->Get("service"));
|
|
|
|
else
|
|
|
|
checkable = host;
|
|
|
|
|
|
|
|
if (!checkable)
|
|
|
|
return Empty;
|
|
|
|
|
2015-07-02 13:04:38 +02:00
|
|
|
if (origin.FromZone && !origin.FromZone->CanAccessObject(checkable)) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'force next check' message from '" << origin.FromClient->GetIdentity() << "': Unauthorized access.";
|
2014-05-03 20:02:22 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
checkable->SetForceNextCheck(params->Get("forced"), origin);
|
|
|
|
|
|
|
|
return Empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiEvents::ForceNextNotificationChangedHandler(const Checkable::Ptr& checkable, bool forced, const MessageOrigin& origin)
|
|
|
|
{
|
|
|
|
ApiListener::Ptr listener = ApiListener::GetInstance();
|
|
|
|
|
|
|
|
if (!listener)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr params = new Dictionary();
|
2014-08-22 12:59:24 +02:00
|
|
|
params->Set("host", host->GetName());
|
2014-05-03 20:02:22 +02:00
|
|
|
if (service)
|
|
|
|
params->Set("service", service->GetShortName());
|
|
|
|
params->Set("forced", forced);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr message = new Dictionary();
|
2014-05-03 20:02:22 +02:00
|
|
|
message->Set("jsonrpc", "2.0");
|
|
|
|
message->Set("method", "event::SetForceNextNotification");
|
|
|
|
message->Set("params", params);
|
|
|
|
|
|
|
|
listener->RelayMessage(origin, checkable, message, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
Value ApiEvents::ForceNextNotificationChangedAPIHandler(const MessageOrigin& origin, const Dictionary::Ptr& params)
|
|
|
|
{
|
2015-07-02 13:04:38 +02:00
|
|
|
Endpoint::Ptr endpoint = origin.FromClient->GetEndpoint();
|
|
|
|
|
|
|
|
if (!endpoint) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'force next notification changed' message from '" << origin.FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
|
2014-10-16 13:04:04 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-10-16 13:04:04 +02:00
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
if (!params)
|
|
|
|
return Empty;
|
|
|
|
|
2014-10-28 14:05:17 +01:00
|
|
|
Host::Ptr host = Host::GetByName(params->Get("host"));
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
if (!host)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
Checkable::Ptr checkable;
|
|
|
|
|
|
|
|
if (params->Contains("service"))
|
|
|
|
checkable = host->GetServiceByShortName(params->Get("service"));
|
|
|
|
else
|
|
|
|
checkable = host;
|
|
|
|
|
|
|
|
if (!checkable)
|
|
|
|
return Empty;
|
|
|
|
|
2015-07-02 13:04:38 +02:00
|
|
|
if (origin.FromZone && !origin.FromZone->CanAccessObject(checkable)) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'force next notification' message from '" << origin.FromClient->GetIdentity() << "': Unauthorized access.";
|
2014-05-03 20:02:22 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
checkable->SetForceNextNotification(params->Get("forced"), origin);
|
|
|
|
|
|
|
|
return Empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiEvents::EnableActiveChecksChangedHandler(const Checkable::Ptr& checkable, bool enabled, const MessageOrigin& origin)
|
|
|
|
{
|
|
|
|
ApiListener::Ptr listener = ApiListener::GetInstance();
|
|
|
|
|
|
|
|
if (!listener)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr params = new Dictionary();
|
2014-08-22 12:59:24 +02:00
|
|
|
params->Set("host", host->GetName());
|
2014-05-03 20:02:22 +02:00
|
|
|
if (service)
|
|
|
|
params->Set("service", service->GetShortName());
|
|
|
|
params->Set("enabled", enabled);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr message = new Dictionary();
|
2014-05-03 20:02:22 +02:00
|
|
|
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& origin, const Dictionary::Ptr& params)
|
|
|
|
{
|
2015-07-02 13:04:38 +02:00
|
|
|
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).";
|
2014-10-16 13:04:04 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-10-16 13:04:04 +02:00
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
if (!params)
|
|
|
|
return Empty;
|
|
|
|
|
2014-10-28 14:05:17 +01:00
|
|
|
Host::Ptr host = Host::GetByName(params->Get("host"));
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
if (!host)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
Checkable::Ptr checkable;
|
|
|
|
|
|
|
|
if (params->Contains("service"))
|
|
|
|
checkable = host->GetServiceByShortName(params->Get("service"));
|
|
|
|
else
|
|
|
|
checkable = host;
|
|
|
|
|
|
|
|
if (!checkable)
|
|
|
|
return Empty;
|
|
|
|
|
2015-07-02 13:04:38 +02:00
|
|
|
if (origin.FromZone && !origin.FromZone->CanAccessObject(checkable)) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'enable active checks' changed message from '" << origin.FromClient->GetIdentity() << "': Unauthorized access.";
|
2014-05-03 20:02:22 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
checkable->SetEnableActiveChecks(params->Get("enabled"), origin);
|
|
|
|
|
|
|
|
return Empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiEvents::EnablePassiveChecksChangedHandler(const Checkable::Ptr& checkable, bool enabled, const MessageOrigin& origin)
|
|
|
|
{
|
|
|
|
ApiListener::Ptr listener = ApiListener::GetInstance();
|
|
|
|
|
|
|
|
if (!listener)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr params = new Dictionary();
|
2014-08-22 12:59:24 +02:00
|
|
|
params->Set("host", host->GetName());
|
2014-05-03 20:02:22 +02:00
|
|
|
if (service)
|
|
|
|
params->Set("service", service->GetShortName());
|
|
|
|
params->Set("enabled", enabled);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr message = new Dictionary();
|
2014-05-03 20:02:22 +02:00
|
|
|
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& origin, const Dictionary::Ptr& params)
|
|
|
|
{
|
2015-07-02 13:04:38 +02:00
|
|
|
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).";
|
2014-10-16 13:04:04 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-10-16 13:04:04 +02:00
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
if (!params)
|
|
|
|
return Empty;
|
|
|
|
|
2014-10-28 14:05:17 +01:00
|
|
|
Host::Ptr host = Host::GetByName(params->Get("host"));
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
if (!host)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
Checkable::Ptr checkable;
|
|
|
|
|
|
|
|
if (params->Contains("service"))
|
|
|
|
checkable = host->GetServiceByShortName(params->Get("service"));
|
|
|
|
else
|
|
|
|
checkable = host;
|
|
|
|
|
|
|
|
if (!checkable)
|
|
|
|
return Empty;
|
|
|
|
|
2015-07-02 13:04:38 +02:00
|
|
|
if (origin.FromZone && !origin.FromZone->CanAccessObject(checkable)) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'enable passive checks changed' message from '" << origin.FromClient->GetIdentity() << "': Unauthorized access.";
|
2014-05-03 20:02:22 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
checkable->SetEnablePassiveChecks(params->Get("enabled"), origin);
|
|
|
|
|
|
|
|
return Empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiEvents::EnableNotificationsChangedHandler(const Checkable::Ptr& checkable, bool enabled, const MessageOrigin& origin)
|
|
|
|
{
|
|
|
|
ApiListener::Ptr listener = ApiListener::GetInstance();
|
|
|
|
|
|
|
|
if (!listener)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr params = new Dictionary();
|
2014-08-22 12:59:24 +02:00
|
|
|
params->Set("host", host->GetName());
|
2014-05-03 20:02:22 +02:00
|
|
|
if (service)
|
|
|
|
params->Set("service", service->GetShortName());
|
|
|
|
params->Set("enabled", enabled);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr message = new Dictionary();
|
2014-05-03 20:02:22 +02:00
|
|
|
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& origin, const Dictionary::Ptr& params)
|
|
|
|
{
|
2015-07-02 13:04:38 +02:00
|
|
|
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).";
|
2014-10-16 13:04:04 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-10-16 13:04:04 +02:00
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
if (!params)
|
|
|
|
return Empty;
|
|
|
|
|
2014-10-28 14:05:17 +01:00
|
|
|
Host::Ptr host = Host::GetByName(params->Get("host"));
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
if (!host)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
Checkable::Ptr checkable;
|
|
|
|
|
|
|
|
if (params->Contains("service"))
|
|
|
|
checkable = host->GetServiceByShortName(params->Get("service"));
|
|
|
|
else
|
|
|
|
checkable = host;
|
|
|
|
|
|
|
|
if (!checkable)
|
|
|
|
return Empty;
|
|
|
|
|
2015-07-02 13:04:38 +02:00
|
|
|
if (origin.FromZone && !origin.FromZone->CanAccessObject(checkable)) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'enable notifications changed' message from '" << origin.FromClient->GetIdentity() << "': Unauthorized access.";
|
2014-05-03 20:02:22 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
checkable->SetEnableNotifications(params->Get("enabled"), origin);
|
|
|
|
|
|
|
|
return Empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiEvents::EnableFlappingChangedHandler(const Checkable::Ptr& checkable, bool enabled, const MessageOrigin& origin)
|
|
|
|
{
|
|
|
|
ApiListener::Ptr listener = ApiListener::GetInstance();
|
|
|
|
|
|
|
|
if (!listener)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr params = new Dictionary();
|
2014-08-22 12:59:24 +02:00
|
|
|
params->Set("host", host->GetName());
|
2014-05-03 20:02:22 +02:00
|
|
|
if (service)
|
|
|
|
params->Set("service", service->GetShortName());
|
|
|
|
params->Set("enabled", enabled);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr message = new Dictionary();
|
2014-05-03 20:02:22 +02:00
|
|
|
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& origin, const Dictionary::Ptr& params)
|
|
|
|
{
|
2015-07-02 13:04:38 +02:00
|
|
|
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).";
|
2014-10-16 13:04:04 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-10-16 13:04:04 +02:00
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
if (!params)
|
|
|
|
return Empty;
|
|
|
|
|
2014-10-28 14:05:17 +01:00
|
|
|
Host::Ptr host = Host::GetByName(params->Get("host"));
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
if (!host)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
Checkable::Ptr checkable;
|
|
|
|
|
|
|
|
if (params->Contains("service"))
|
|
|
|
checkable = host->GetServiceByShortName(params->Get("service"));
|
|
|
|
else
|
|
|
|
checkable = host;
|
|
|
|
|
|
|
|
if (!checkable)
|
|
|
|
return Empty;
|
|
|
|
|
2015-07-02 13:04:38 +02:00
|
|
|
if (origin.FromZone && !origin.FromZone->CanAccessObject(checkable)) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'enable flapping changed' message from '" << origin.FromClient->GetIdentity() << "': Unauthorized access.";
|
2014-05-03 20:02:22 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
checkable->SetEnableFlapping(params->Get("enabled"), origin);
|
|
|
|
|
|
|
|
return Empty;
|
|
|
|
}
|
|
|
|
|
2014-08-26 15:29:55 +02:00
|
|
|
void ApiEvents::EnableEventHandlerChangedHandler(const Checkable::Ptr& checkable, bool enabled, const MessageOrigin& origin)
|
|
|
|
{
|
|
|
|
ApiListener::Ptr listener = ApiListener::GetInstance();
|
|
|
|
|
|
|
|
if (!listener)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr params = new Dictionary();
|
2014-08-26 15:29:55 +02:00
|
|
|
params->Set("host", host->GetName());
|
|
|
|
if (service)
|
|
|
|
params->Set("service", service->GetShortName());
|
|
|
|
params->Set("enabled", enabled);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr message = new Dictionary();
|
2014-08-26 15:29:55 +02:00
|
|
|
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& origin, const Dictionary::Ptr& params)
|
|
|
|
{
|
2015-07-02 13:04:38 +02:00
|
|
|
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).";
|
2014-10-16 13:04:04 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-10-16 13:04:04 +02:00
|
|
|
|
2014-08-26 15:29:55 +02:00
|
|
|
if (!params)
|
|
|
|
return Empty;
|
|
|
|
|
2014-10-28 14:05:17 +01:00
|
|
|
Host::Ptr host = Host::GetByName(params->Get("host"));
|
2014-08-26 15:29:55 +02:00
|
|
|
|
|
|
|
if (!host)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
Checkable::Ptr checkable;
|
|
|
|
|
|
|
|
if (params->Contains("service"))
|
|
|
|
checkable = host->GetServiceByShortName(params->Get("service"));
|
|
|
|
else
|
|
|
|
checkable = host;
|
|
|
|
|
|
|
|
if (!checkable)
|
|
|
|
return Empty;
|
|
|
|
|
2015-07-02 13:04:38 +02:00
|
|
|
if (origin.FromZone && !origin.FromZone->CanAccessObject(checkable)) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'enable event handler' message from '" << origin.FromClient->GetIdentity() << "': Unauthorized access.";
|
2014-08-26 15:29:55 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-08-26 15:29:55 +02:00
|
|
|
|
|
|
|
checkable->SetEnableEventHandler(params->Get("enabled"), origin);
|
|
|
|
|
|
|
|
return Empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiEvents::EnablePerfdataChangedHandler(const Checkable::Ptr& checkable, bool enabled, const MessageOrigin& origin)
|
|
|
|
{
|
|
|
|
ApiListener::Ptr listener = ApiListener::GetInstance();
|
|
|
|
|
|
|
|
if (!listener)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr params = new Dictionary();
|
2014-08-26 15:29:55 +02:00
|
|
|
params->Set("host", host->GetName());
|
|
|
|
if (service)
|
|
|
|
params->Set("service", service->GetShortName());
|
|
|
|
params->Set("enabled", enabled);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr message = new Dictionary();
|
2014-08-26 15:29:55 +02:00
|
|
|
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& origin, const Dictionary::Ptr& params)
|
|
|
|
{
|
2015-07-02 13:04:38 +02:00
|
|
|
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).";
|
2014-10-16 13:04:04 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-10-16 13:04:04 +02:00
|
|
|
|
2014-08-26 15:29:55 +02:00
|
|
|
if (!params)
|
|
|
|
return Empty;
|
|
|
|
|
2014-10-28 14:05:17 +01:00
|
|
|
Host::Ptr host = Host::GetByName(params->Get("host"));
|
2014-08-26 15:29:55 +02:00
|
|
|
|
|
|
|
if (!host)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
Checkable::Ptr checkable;
|
|
|
|
|
|
|
|
if (params->Contains("service"))
|
|
|
|
checkable = host->GetServiceByShortName(params->Get("service"));
|
|
|
|
else
|
|
|
|
checkable = host;
|
|
|
|
|
|
|
|
if (!checkable)
|
|
|
|
return Empty;
|
|
|
|
|
2015-07-02 13:04:38 +02:00
|
|
|
if (origin.FromZone && !origin.FromZone->CanAccessObject(checkable)) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'enable perfdata changed' message from '" << origin.FromClient->GetIdentity() << "': Unauthorized access.";
|
2014-08-26 15:29:55 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-08-26 15:29:55 +02:00
|
|
|
|
|
|
|
checkable->SetEnablePerfdata(params->Get("enabled"), origin);
|
|
|
|
|
|
|
|
return Empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiEvents::CheckIntervalChangedHandler(const Checkable::Ptr& checkable, double interval, const MessageOrigin& origin)
|
|
|
|
{
|
|
|
|
ApiListener::Ptr listener = ApiListener::GetInstance();
|
|
|
|
|
|
|
|
if (!listener)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr params = new Dictionary();
|
2014-08-26 15:29:55 +02:00
|
|
|
params->Set("host", host->GetName());
|
|
|
|
if (service)
|
|
|
|
params->Set("service", service->GetShortName());
|
|
|
|
params->Set("interval", interval);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr message = new Dictionary();
|
2014-08-26 15:29:55 +02:00
|
|
|
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& origin, const Dictionary::Ptr& params)
|
|
|
|
{
|
2015-07-02 13:04:38 +02:00
|
|
|
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).";
|
2014-10-16 13:04:04 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-10-16 13:04:04 +02:00
|
|
|
|
2014-08-26 15:29:55 +02:00
|
|
|
if (!params)
|
|
|
|
return Empty;
|
|
|
|
|
2014-10-28 14:05:17 +01:00
|
|
|
Host::Ptr host = Host::GetByName(params->Get("host"));
|
2014-08-26 15:29:55 +02:00
|
|
|
|
|
|
|
if (!host)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
Checkable::Ptr checkable;
|
|
|
|
|
|
|
|
if (params->Contains("service"))
|
|
|
|
checkable = host->GetServiceByShortName(params->Get("service"));
|
|
|
|
else
|
|
|
|
checkable = host;
|
|
|
|
|
|
|
|
if (!checkable)
|
|
|
|
return Empty;
|
|
|
|
|
2015-07-02 13:04:38 +02:00
|
|
|
if (origin.FromZone && !origin.FromZone->CanAccessObject(checkable)) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'check interval' changed message from '" << origin.FromClient->GetIdentity() << "': Unauthorized access.";
|
2014-08-26 15:29:55 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-08-26 15:29:55 +02:00
|
|
|
|
|
|
|
checkable->SetCheckInterval(params->Get("interval"), origin);
|
|
|
|
|
|
|
|
return Empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiEvents::RetryIntervalChangedHandler(const Checkable::Ptr& checkable, double interval, const MessageOrigin& origin)
|
|
|
|
{
|
|
|
|
ApiListener::Ptr listener = ApiListener::GetInstance();
|
|
|
|
|
|
|
|
if (!listener)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr params = new Dictionary();
|
2014-08-26 15:29:55 +02:00
|
|
|
params->Set("host", host->GetName());
|
|
|
|
if (service)
|
|
|
|
params->Set("service", service->GetShortName());
|
|
|
|
params->Set("interval", interval);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr message = new Dictionary();
|
2014-08-26 15:29:55 +02:00
|
|
|
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& origin, const Dictionary::Ptr& params)
|
|
|
|
{
|
2015-07-02 13:04:38 +02:00
|
|
|
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).";
|
2014-10-16 13:04:04 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-10-16 13:04:04 +02:00
|
|
|
|
2014-08-26 15:29:55 +02:00
|
|
|
if (!params)
|
|
|
|
return Empty;
|
|
|
|
|
2014-10-28 14:05:17 +01:00
|
|
|
Host::Ptr host = Host::GetByName(params->Get("host"));
|
2014-08-26 15:29:55 +02:00
|
|
|
|
|
|
|
if (!host)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
Checkable::Ptr checkable;
|
|
|
|
|
|
|
|
if (params->Contains("service"))
|
|
|
|
checkable = host->GetServiceByShortName(params->Get("service"));
|
|
|
|
else
|
|
|
|
checkable = host;
|
|
|
|
|
|
|
|
if (!checkable)
|
|
|
|
return Empty;
|
|
|
|
|
2015-07-02 13:04:38 +02:00
|
|
|
if (origin.FromZone && !origin.FromZone->CanAccessObject(checkable)) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'retry interval' changed message from '" << origin.FromClient->GetIdentity() << "': Unauthorized access.";
|
2014-08-26 15:29:55 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-08-26 15:29:55 +02:00
|
|
|
|
|
|
|
checkable->SetRetryInterval(params->Get("interval"), origin);
|
|
|
|
|
|
|
|
return Empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiEvents::MaxCheckAttemptsChangedHandler(const Checkable::Ptr& checkable, int attempts, const MessageOrigin& origin)
|
|
|
|
{
|
|
|
|
ApiListener::Ptr listener = ApiListener::GetInstance();
|
|
|
|
|
|
|
|
if (!listener)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr params = new Dictionary();
|
2014-08-26 15:29:55 +02:00
|
|
|
params->Set("host", host->GetName());
|
|
|
|
if (service)
|
|
|
|
params->Set("service", service->GetShortName());
|
|
|
|
params->Set("attempts", attempts);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr message = new Dictionary();
|
2014-08-26 15:29:55 +02:00
|
|
|
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& origin, const Dictionary::Ptr& params)
|
|
|
|
{
|
2015-07-02 13:04:38 +02:00
|
|
|
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).";
|
2014-10-16 13:04:04 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-10-16 13:04:04 +02:00
|
|
|
|
2014-08-26 15:29:55 +02:00
|
|
|
if (!params)
|
|
|
|
return Empty;
|
|
|
|
|
2014-10-28 14:05:17 +01:00
|
|
|
Host::Ptr host = Host::GetByName(params->Get("host"));
|
2014-08-26 15:29:55 +02:00
|
|
|
|
|
|
|
if (!host)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
Checkable::Ptr checkable;
|
|
|
|
|
|
|
|
if (params->Contains("service"))
|
|
|
|
checkable = host->GetServiceByShortName(params->Get("service"));
|
|
|
|
else
|
|
|
|
checkable = host;
|
|
|
|
|
|
|
|
if (!checkable)
|
|
|
|
return Empty;
|
|
|
|
|
2015-07-02 13:04:38 +02:00
|
|
|
if (origin.FromZone && !origin.FromZone->CanAccessObject(checkable)) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'max check attempts changed' message from '" << origin.FromClient->GetIdentity() << "': Unauthorized access.";
|
2014-08-26 15:29:55 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-08-26 15:29:55 +02:00
|
|
|
|
|
|
|
checkable->SetMaxCheckAttempts(params->Get("attempts"), origin);
|
|
|
|
|
|
|
|
return Empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiEvents::EventCommandChangedHandler(const Checkable::Ptr& checkable, const EventCommand::Ptr& command, const MessageOrigin& origin)
|
|
|
|
{
|
|
|
|
ApiListener::Ptr listener = ApiListener::GetInstance();
|
|
|
|
|
|
|
|
if (!listener)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr params = new Dictionary();
|
2014-08-26 15:29:55 +02:00
|
|
|
params->Set("host", host->GetName());
|
|
|
|
if (service)
|
|
|
|
params->Set("service", service->GetShortName());
|
|
|
|
params->Set("command", command->GetName());
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr message = new Dictionary();
|
2014-08-26 15:29:55 +02:00
|
|
|
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& origin, const Dictionary::Ptr& params)
|
|
|
|
{
|
2015-07-02 13:04:38 +02:00
|
|
|
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).";
|
2014-10-16 13:04:04 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-10-16 13:04:04 +02:00
|
|
|
|
2014-08-26 15:29:55 +02:00
|
|
|
if (!params)
|
|
|
|
return Empty;
|
|
|
|
|
2014-10-28 14:05:17 +01:00
|
|
|
Host::Ptr host = Host::GetByName(params->Get("host"));
|
2014-08-26 15:29:55 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2015-07-02 13:04:38 +02:00
|
|
|
if (origin.FromZone && !origin.FromZone->CanAccessObject(checkable)) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'event command changed' message from '" << origin.FromClient->GetIdentity() << "': Unauthorized access.";
|
2014-08-26 15:29:55 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-08-26 15:29:55 +02:00
|
|
|
|
|
|
|
checkable->SetEventCommand(command, origin);
|
|
|
|
|
|
|
|
return Empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiEvents::CheckCommandChangedHandler(const Checkable::Ptr& checkable, const CheckCommand::Ptr& command, const MessageOrigin& origin)
|
|
|
|
{
|
|
|
|
ApiListener::Ptr listener = ApiListener::GetInstance();
|
|
|
|
|
|
|
|
if (!listener)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr params = new Dictionary();
|
2014-08-26 15:29:55 +02:00
|
|
|
params->Set("host", host->GetName());
|
|
|
|
if (service)
|
|
|
|
params->Set("service", service->GetShortName());
|
|
|
|
params->Set("command", command->GetName());
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr message = new Dictionary();
|
2014-08-26 15:29:55 +02:00
|
|
|
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& origin, const Dictionary::Ptr& params)
|
|
|
|
{
|
2015-07-02 13:04:38 +02:00
|
|
|
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).";
|
2014-10-16 13:04:04 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-10-16 13:04:04 +02:00
|
|
|
|
2014-08-26 15:29:55 +02:00
|
|
|
if (!params)
|
|
|
|
return Empty;
|
|
|
|
|
2014-10-28 14:05:17 +01:00
|
|
|
Host::Ptr host = Host::GetByName(params->Get("host"));
|
2014-08-26 15:29:55 +02:00
|
|
|
|
|
|
|
if (!host)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
Checkable::Ptr checkable;
|
|
|
|
|
|
|
|
if (params->Contains("service"))
|
|
|
|
checkable = host->GetServiceByShortName(params->Get("service"));
|
|
|
|
else
|
|
|
|
checkable = host;
|
|
|
|
|
|
|
|
if (!checkable)
|
|
|
|
return Empty;
|
|
|
|
|
2015-07-02 13:04:38 +02:00
|
|
|
if (origin.FromZone && !origin.FromZone->CanAccessObject(checkable)) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'check command changed' message from '" << origin.FromClient->GetIdentity() << "': Unauthorized access.";
|
2014-08-26 15:29:55 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-08-26 15:29:55 +02:00
|
|
|
|
|
|
|
CheckCommand::Ptr command = CheckCommand::GetByName(params->Get("command"));
|
|
|
|
|
|
|
|
if (!command)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
checkable->SetCheckCommand(command, origin);
|
|
|
|
|
|
|
|
return Empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiEvents::CheckPeriodChangedHandler(const Checkable::Ptr& checkable, const TimePeriod::Ptr& timeperiod, const MessageOrigin& origin)
|
|
|
|
{
|
|
|
|
ApiListener::Ptr listener = ApiListener::GetInstance();
|
|
|
|
|
|
|
|
if (!listener)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr params = new Dictionary();
|
2014-08-26 15:29:55 +02:00
|
|
|
params->Set("host", host->GetName());
|
|
|
|
if (service)
|
|
|
|
params->Set("service", service->GetShortName());
|
|
|
|
params->Set("timeperiod", timeperiod->GetName());
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr message = new Dictionary();
|
2014-08-26 15:29:55 +02:00
|
|
|
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& origin, const Dictionary::Ptr& params)
|
|
|
|
{
|
2015-07-02 13:04:38 +02:00
|
|
|
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).";
|
2014-10-16 13:04:04 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-10-16 13:04:04 +02:00
|
|
|
|
2014-08-26 15:29:55 +02:00
|
|
|
if (!params)
|
|
|
|
return Empty;
|
|
|
|
|
2014-10-28 14:05:17 +01:00
|
|
|
Host::Ptr host = Host::GetByName(params->Get("host"));
|
2014-08-26 15:29:55 +02:00
|
|
|
|
|
|
|
if (!host)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
Checkable::Ptr checkable;
|
|
|
|
|
|
|
|
if (params->Contains("service"))
|
|
|
|
checkable = host->GetServiceByShortName(params->Get("service"));
|
|
|
|
else
|
|
|
|
checkable = host;
|
|
|
|
|
|
|
|
if (!checkable)
|
|
|
|
return Empty;
|
|
|
|
|
2015-07-02 13:04:38 +02:00
|
|
|
if (origin.FromZone && !origin.FromZone->CanAccessObject(checkable)) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'check period changed' message from '" << origin.FromClient->GetIdentity() << "': Unauthorized access.";
|
2014-08-26 15:29:55 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-08-26 15:29:55 +02:00
|
|
|
|
|
|
|
TimePeriod::Ptr timeperiod = TimePeriod::GetByName(params->Get("timeperiod"));
|
|
|
|
|
|
|
|
if (!timeperiod)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
checkable->SetCheckPeriod(timeperiod, origin);
|
|
|
|
|
|
|
|
return Empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiEvents::VarsChangedHandler(const CustomVarObject::Ptr& object, const Dictionary::Ptr& vars, const MessageOrigin& origin)
|
|
|
|
{
|
|
|
|
ApiListener::Ptr listener = ApiListener::GetInstance();
|
|
|
|
|
|
|
|
if (!listener)
|
|
|
|
return;
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr params = new Dictionary();
|
2014-08-26 15:29:55 +02:00
|
|
|
params->Set("object", object->GetName());
|
|
|
|
params->Set("vars", Serialize(vars));
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr message = new Dictionary();
|
2014-08-26 15:29:55 +02:00
|
|
|
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& origin, const Dictionary::Ptr& params)
|
|
|
|
{
|
2015-07-02 13:04:38 +02:00
|
|
|
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).";
|
2014-10-16 13:04:04 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-10-16 13:04:04 +02:00
|
|
|
|
2014-08-26 15:29:55 +02:00
|
|
|
if (!params)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
String objectName = params->Get("object");
|
|
|
|
|
|
|
|
if (objectName.IsEmpty())
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
/* ugly, but there is no other way currently */
|
|
|
|
CustomVarObject::Ptr 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);
|
|
|
|
if (!object)
|
|
|
|
return Empty;
|
|
|
|
|
2015-07-02 13:04:38 +02:00
|
|
|
if (origin.FromZone && !origin.FromZone->CanAccessObject(object)) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'vars changed' message from '" << origin.FromClient->GetIdentity() << "': Unauthorized access.";
|
2014-08-26 15:29:55 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-08-26 15:29:55 +02:00
|
|
|
|
2014-10-25 09:14:56 +02:00
|
|
|
Dictionary::Ptr vars = params->Get("vars");
|
2014-08-26 15:29:55 +02:00
|
|
|
|
|
|
|
if (!vars)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
object->SetVars(vars, origin);
|
|
|
|
|
|
|
|
return Empty;
|
|
|
|
}
|
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
void ApiEvents::CommentAddedHandler(const Checkable::Ptr& checkable, const Comment::Ptr& comment, const MessageOrigin& origin)
|
|
|
|
{
|
|
|
|
ApiListener::Ptr listener = ApiListener::GetInstance();
|
|
|
|
|
|
|
|
if (!listener)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr params = new Dictionary();
|
2014-08-22 12:59:24 +02:00
|
|
|
params->Set("host", host->GetName());
|
2014-05-03 20:02:22 +02:00
|
|
|
if (service)
|
|
|
|
params->Set("service", service->GetShortName());
|
|
|
|
params->Set("comment", Serialize(comment));
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr message = new Dictionary();
|
2014-05-03 20:02:22 +02:00
|
|
|
message->Set("jsonrpc", "2.0");
|
|
|
|
message->Set("method", "event::AddComment");
|
|
|
|
message->Set("params", params);
|
|
|
|
|
|
|
|
listener->RelayMessage(origin, checkable, message, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
Value ApiEvents::CommentAddedAPIHandler(const MessageOrigin& origin, const Dictionary::Ptr& params)
|
|
|
|
{
|
2015-07-02 13:04:38 +02:00
|
|
|
Endpoint::Ptr endpoint = origin.FromClient->GetEndpoint();
|
|
|
|
|
|
|
|
if (!endpoint) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'comment added' message from '" << origin.FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
|
2014-10-16 13:04:04 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-10-16 13:04:04 +02:00
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
if (!params)
|
|
|
|
return Empty;
|
|
|
|
|
2014-10-28 14:05:17 +01:00
|
|
|
Host::Ptr host = Host::GetByName(params->Get("host"));
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
if (!host)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
Checkable::Ptr checkable;
|
|
|
|
|
|
|
|
if (params->Contains("service"))
|
|
|
|
checkable = host->GetServiceByShortName(params->Get("service"));
|
|
|
|
else
|
|
|
|
checkable = host;
|
|
|
|
|
|
|
|
if (!checkable)
|
|
|
|
return Empty;
|
|
|
|
|
2015-07-02 13:04:38 +02:00
|
|
|
if (origin.FromZone && !origin.FromZone->CanAccessObject(checkable)) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'comment added' message from '" << origin.FromClient->GetIdentity() << "': Unauthorized access.";
|
2014-05-03 20:02:22 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Comment::Ptr comment = new Comment();
|
2014-10-25 09:14:56 +02:00
|
|
|
Deserialize(comment, params->Get("comment"), true);
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
checkable->AddComment(comment->GetEntryType(), comment->GetAuthor(),
|
|
|
|
comment->GetText(), comment->GetExpireTime(), comment->GetId(), origin);
|
|
|
|
|
|
|
|
return Empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiEvents::CommentRemovedHandler(const Checkable::Ptr& checkable, const Comment::Ptr& comment, const MessageOrigin& origin)
|
|
|
|
{
|
|
|
|
ApiListener::Ptr listener = ApiListener::GetInstance();
|
|
|
|
|
|
|
|
if (!listener)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr params = new Dictionary();
|
2014-08-22 12:59:24 +02:00
|
|
|
params->Set("host", host->GetName());
|
2014-05-03 20:02:22 +02:00
|
|
|
if (service)
|
|
|
|
params->Set("service", service->GetShortName());
|
|
|
|
params->Set("id", comment->GetId());
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr message = new Dictionary();
|
2014-05-03 20:02:22 +02:00
|
|
|
message->Set("jsonrpc", "2.0");
|
|
|
|
message->Set("method", "event::RemoveComment");
|
|
|
|
message->Set("params", params);
|
|
|
|
|
|
|
|
listener->RelayMessage(origin, checkable, message, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
Value ApiEvents::CommentRemovedAPIHandler(const MessageOrigin& origin, const Dictionary::Ptr& params)
|
|
|
|
{
|
2015-07-02 13:04:38 +02:00
|
|
|
Endpoint::Ptr endpoint = origin.FromClient->GetEndpoint();
|
|
|
|
|
|
|
|
if (!endpoint) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'comment removed' message from '" << origin.FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
|
2014-10-16 13:04:04 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-10-16 13:04:04 +02:00
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
if (!params)
|
|
|
|
return Empty;
|
|
|
|
|
2014-10-28 14:05:17 +01:00
|
|
|
Host::Ptr host = Host::GetByName(params->Get("host"));
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
if (!host)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
Checkable::Ptr checkable;
|
|
|
|
|
|
|
|
if (params->Contains("service"))
|
|
|
|
checkable = host->GetServiceByShortName(params->Get("service"));
|
|
|
|
else
|
|
|
|
checkable = host;
|
|
|
|
|
|
|
|
if (!checkable)
|
|
|
|
return Empty;
|
|
|
|
|
2015-07-02 13:04:38 +02:00
|
|
|
if (origin.FromZone && !origin.FromZone->CanAccessObject(checkable)) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'comment removed' message from '" << origin.FromClient->GetIdentity() << "': Unauthorized access.";
|
2014-05-03 20:02:22 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
checkable->RemoveComment(params->Get("id"), origin);
|
|
|
|
|
|
|
|
return Empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiEvents::DowntimeAddedHandler(const Checkable::Ptr& checkable, const Downtime::Ptr& downtime, const MessageOrigin& origin)
|
|
|
|
{
|
|
|
|
ApiListener::Ptr listener = ApiListener::GetInstance();
|
|
|
|
|
|
|
|
if (!listener)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr params = new Dictionary();
|
2014-08-22 12:59:24 +02:00
|
|
|
params->Set("host", host->GetName());
|
2014-05-03 20:02:22 +02:00
|
|
|
if (service)
|
|
|
|
params->Set("service", service->GetShortName());
|
|
|
|
params->Set("downtime", Serialize(downtime));
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr message = new Dictionary();
|
2014-05-03 20:02:22 +02:00
|
|
|
message->Set("jsonrpc", "2.0");
|
|
|
|
message->Set("method", "event::AddDowntime");
|
|
|
|
message->Set("params", params);
|
|
|
|
|
|
|
|
listener->RelayMessage(origin, checkable, message, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
Value ApiEvents::DowntimeAddedAPIHandler(const MessageOrigin& origin, const Dictionary::Ptr& params)
|
|
|
|
{
|
2015-07-02 13:04:38 +02:00
|
|
|
Endpoint::Ptr endpoint = origin.FromClient->GetEndpoint();
|
|
|
|
|
|
|
|
if (!endpoint) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'downtime added' message from '" << origin.FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
|
2014-10-16 13:04:04 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-10-16 13:04:04 +02:00
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
if (!params)
|
|
|
|
return Empty;
|
|
|
|
|
2014-10-28 14:05:17 +01:00
|
|
|
Host::Ptr host = Host::GetByName(params->Get("host"));
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
if (!host)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
Checkable::Ptr checkable;
|
|
|
|
|
|
|
|
if (params->Contains("service"))
|
|
|
|
checkable = host->GetServiceByShortName(params->Get("service"));
|
|
|
|
else
|
|
|
|
checkable = host;
|
|
|
|
|
|
|
|
if (!checkable)
|
|
|
|
return Empty;
|
|
|
|
|
2015-07-02 13:04:38 +02:00
|
|
|
if (origin.FromZone && !origin.FromZone->CanAccessObject(checkable)) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'downtime added' message from '" << origin.FromClient->GetIdentity() << "': Unauthorized access.";
|
2014-05-03 20:02:22 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Downtime::Ptr downtime = new Downtime();
|
2014-10-25 09:14:56 +02:00
|
|
|
Deserialize(downtime, params->Get("downtime"), true);
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
checkable->AddDowntime(downtime->GetAuthor(), downtime->GetComment(),
|
|
|
|
downtime->GetStartTime(), downtime->GetEndTime(),
|
|
|
|
downtime->GetFixed(), downtime->GetTriggeredBy(),
|
|
|
|
downtime->GetDuration(), downtime->GetScheduledBy(),
|
|
|
|
downtime->GetId(), origin);
|
|
|
|
|
|
|
|
return Empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiEvents::DowntimeRemovedHandler(const Checkable::Ptr& checkable, const Downtime::Ptr& downtime, const MessageOrigin& origin)
|
|
|
|
{
|
|
|
|
ApiListener::Ptr listener = ApiListener::GetInstance();
|
|
|
|
|
|
|
|
if (!listener)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr params = new Dictionary();
|
2014-08-22 12:59:24 +02:00
|
|
|
params->Set("host", host->GetName());
|
2014-05-03 20:02:22 +02:00
|
|
|
if (service)
|
|
|
|
params->Set("service", service->GetShortName());
|
|
|
|
params->Set("id", downtime->GetId());
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr message = new Dictionary();
|
2014-05-03 20:02:22 +02:00
|
|
|
message->Set("jsonrpc", "2.0");
|
|
|
|
message->Set("method", "event::RemoveDowntime");
|
|
|
|
message->Set("params", params);
|
|
|
|
|
|
|
|
listener->RelayMessage(origin, checkable, message, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
Value ApiEvents::DowntimeRemovedAPIHandler(const MessageOrigin& origin, const Dictionary::Ptr& params)
|
|
|
|
{
|
2015-07-02 13:04:38 +02:00
|
|
|
Endpoint::Ptr endpoint = origin.FromClient->GetEndpoint();
|
|
|
|
|
|
|
|
if (!endpoint) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'downtime removed' message from '" << origin.FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
|
2014-10-16 13:04:04 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-10-16 13:04:04 +02:00
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
if (!params)
|
|
|
|
return Empty;
|
|
|
|
|
2014-10-28 14:05:17 +01:00
|
|
|
Host::Ptr host = Host::GetByName(params->Get("host"));
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
if (!host)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
Checkable::Ptr checkable;
|
|
|
|
|
|
|
|
if (params->Contains("service"))
|
|
|
|
checkable = host->GetServiceByShortName(params->Get("service"));
|
|
|
|
else
|
|
|
|
checkable = host;
|
|
|
|
|
|
|
|
if (!checkable)
|
|
|
|
return Empty;
|
|
|
|
|
2015-07-02 13:04:38 +02:00
|
|
|
if (origin.FromZone && !origin.FromZone->CanAccessObject(checkable)) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'downtime removed' message from '" << origin.FromClient->GetIdentity() << "': Unauthorized access.";
|
2014-05-03 20:02:22 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
checkable->RemoveDowntime(params->Get("id"), false, origin);
|
|
|
|
|
|
|
|
return Empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiEvents::AcknowledgementSetHandler(const Checkable::Ptr& checkable,
|
|
|
|
const String& author, const String& comment, AcknowledgementType type,
|
2015-02-07 21:39:19 +01:00
|
|
|
bool notify, double expiry, const MessageOrigin& origin)
|
2014-05-03 20:02:22 +02:00
|
|
|
{
|
|
|
|
ApiListener::Ptr listener = ApiListener::GetInstance();
|
|
|
|
|
|
|
|
if (!listener)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr params = new Dictionary();
|
2014-08-22 12:59:24 +02:00
|
|
|
params->Set("host", host->GetName());
|
2014-05-03 20:02:22 +02:00
|
|
|
if (service)
|
|
|
|
params->Set("service", service->GetShortName());
|
|
|
|
params->Set("author", author);
|
|
|
|
params->Set("comment", comment);
|
|
|
|
params->Set("acktype", type);
|
2015-02-07 21:39:19 +01:00
|
|
|
params->Set("notify", notify);
|
2014-05-03 20:02:22 +02:00
|
|
|
params->Set("expiry", expiry);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr message = new Dictionary();
|
2014-05-03 20:02:22 +02:00
|
|
|
message->Set("jsonrpc", "2.0");
|
|
|
|
message->Set("method", "event::SetAcknowledgement");
|
|
|
|
message->Set("params", params);
|
|
|
|
|
|
|
|
listener->RelayMessage(origin, checkable, message, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
Value ApiEvents::AcknowledgementSetAPIHandler(const MessageOrigin& origin, const Dictionary::Ptr& params)
|
|
|
|
{
|
2015-07-02 13:04:38 +02:00
|
|
|
Endpoint::Ptr endpoint = origin.FromClient->GetEndpoint();
|
|
|
|
|
|
|
|
if (!endpoint) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'acknowledgement set' message from '" << origin.FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
|
2014-10-16 13:04:04 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-10-16 13:04:04 +02:00
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
if (!params)
|
|
|
|
return Empty;
|
|
|
|
|
2014-10-28 14:05:17 +01:00
|
|
|
Host::Ptr host = Host::GetByName(params->Get("host"));
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
if (!host)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
Checkable::Ptr checkable;
|
|
|
|
|
|
|
|
if (params->Contains("service"))
|
|
|
|
checkable = host->GetServiceByShortName(params->Get("service"));
|
|
|
|
else
|
|
|
|
checkable = host;
|
|
|
|
|
|
|
|
if (!checkable)
|
|
|
|
return Empty;
|
|
|
|
|
2015-07-02 13:04:38 +02:00
|
|
|
if (origin.FromZone && !origin.FromZone->CanAccessObject(checkable)) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'acknowledgement set' message from '" << origin.FromClient->GetIdentity() << "': Unauthorized access.";
|
2014-05-03 20:02:22 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
checkable->AcknowledgeProblem(params->Get("author"), params->Get("comment"),
|
|
|
|
static_cast<AcknowledgementType>(static_cast<int>(params->Get("acktype"))),
|
2015-02-07 21:39:19 +01:00
|
|
|
params->Get("notify"), params->Get("expiry"), origin);
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
return Empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiEvents::AcknowledgementClearedHandler(const Checkable::Ptr& checkable, const MessageOrigin& origin)
|
|
|
|
{
|
|
|
|
ApiListener::Ptr listener = ApiListener::GetInstance();
|
|
|
|
|
|
|
|
if (!listener)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Host::Ptr host;
|
|
|
|
Service::Ptr service;
|
|
|
|
tie(host, service) = GetHostService(checkable);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr params = new Dictionary();
|
2014-08-22 12:59:24 +02:00
|
|
|
params->Set("host", host->GetName());
|
2014-05-03 20:02:22 +02:00
|
|
|
if (service)
|
|
|
|
params->Set("service", service->GetShortName());
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr message = new Dictionary();
|
2014-05-03 20:02:22 +02:00
|
|
|
message->Set("jsonrpc", "2.0");
|
|
|
|
message->Set("method", "event::ClearAcknowledgement");
|
|
|
|
message->Set("params", params);
|
|
|
|
|
|
|
|
listener->RelayMessage(origin, checkable, message, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
Value ApiEvents::AcknowledgementClearedAPIHandler(const MessageOrigin& origin, const Dictionary::Ptr& params)
|
|
|
|
{
|
2015-07-02 13:04:38 +02:00
|
|
|
Endpoint::Ptr endpoint = origin.FromClient->GetEndpoint();
|
|
|
|
|
|
|
|
if (!endpoint) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'acknowledgement cleared' message from '" << origin.FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
|
2014-10-16 13:04:04 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-10-16 13:04:04 +02:00
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
if (!params)
|
|
|
|
return Empty;
|
|
|
|
|
2014-10-28 14:05:17 +01:00
|
|
|
Host::Ptr host = Host::GetByName(params->Get("host"));
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
if (!host)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
Checkable::Ptr checkable;
|
|
|
|
|
|
|
|
if (params->Contains("service"))
|
|
|
|
checkable = host->GetServiceByShortName(params->Get("service"));
|
|
|
|
else
|
|
|
|
checkable = host;
|
|
|
|
|
|
|
|
if (!checkable)
|
|
|
|
return Empty;
|
|
|
|
|
2015-07-02 13:04:38 +02:00
|
|
|
if (origin.FromZone && !origin.FromZone->CanAccessObject(checkable)) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'acknowledgement cleared' message from '" << origin.FromClient->GetIdentity() << "': Unauthorized access.";
|
2014-05-03 20:02:22 +02:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
checkable->ClearAcknowledgement(origin);
|
|
|
|
|
|
|
|
return Empty;
|
|
|
|
}
|
|
|
|
|
2014-11-13 11:23:57 +01:00
|
|
|
Value ApiEvents::ExecuteCommandAPIHandler(const MessageOrigin& origin, const Dictionary::Ptr& params)
|
|
|
|
{
|
2015-01-18 22:15:35 +01:00
|
|
|
Endpoint::Ptr sourceEndpoint = origin.FromClient->GetEndpoint();
|
2014-11-13 11:23:57 +01:00
|
|
|
|
2015-07-02 13:04:38 +02:00
|
|
|
if (!sourceEndpoint || (origin.FromZone && !Zone::GetLocalZone()->IsChildOf(origin.FromZone))) {
|
|
|
|
Log(LogNotice, "ApiEvents")
|
|
|
|
<< "Discarding 'execute command' message from '" << origin.FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
|
2014-11-13 11:23:57 +01:00
|
|
|
return Empty;
|
2015-07-02 13:04:38 +02:00
|
|
|
}
|
2014-11-13 11:23:57 +01:00
|
|
|
|
|
|
|
ApiListener::Ptr listener = ApiListener::GetInstance();
|
|
|
|
|
|
|
|
if (!listener) {
|
|
|
|
Log(LogCritical, "ApiListener", "No instance available.");
|
|
|
|
return Empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!listener->GetAcceptCommands()) {
|
|
|
|
Log(LogWarning, "ApiListener")
|
|
|
|
<< "Ignoring command. '" << listener->GetName() << "' does not accept commands.";
|
2015-02-05 15:17:56 +01:00
|
|
|
|
|
|
|
Host::Ptr host = new Host();
|
|
|
|
Dictionary::Ptr attrs = new Dictionary();
|
|
|
|
|
|
|
|
attrs->Set("__name", params->Get("host"));
|
|
|
|
attrs->Set("type", "Host");
|
|
|
|
|
|
|
|
Deserialize(host, attrs, false, FAConfig);
|
|
|
|
|
2015-03-05 20:50:27 +01:00
|
|
|
if (params->Contains("service"))
|
|
|
|
host->SetExtension("agent_service_name", params->Get("service"));
|
|
|
|
|
2015-02-05 15:17:56 +01:00
|
|
|
CheckResult::Ptr cr = new CheckResult();
|
|
|
|
cr->SetState(ServiceUnknown);
|
2015-03-05 20:50:27 +01:00
|
|
|
cr->SetOutput("Endpoint '" + Endpoint::GetLocalEndpoint()->GetName() + "' does not accept commands.");
|
2015-02-05 15:17:56 +01:00
|
|
|
Dictionary::Ptr message = MakeCheckResultMessage(host, cr);
|
2015-01-18 22:15:35 +01:00
|
|
|
listener->SyncSendMessage(sourceEndpoint, message);
|
2015-02-05 15:17:56 +01:00
|
|
|
|
2014-11-13 11:23:57 +01:00
|
|
|
return Empty;
|
|
|
|
}
|
|
|
|
|
2015-01-18 22:15:35 +01:00
|
|
|
/* use a virtual host object for executing the command */
|
2014-11-13 11:23:57 +01:00
|
|
|
Host::Ptr host = new Host();
|
|
|
|
Dictionary::Ptr attrs = new Dictionary();
|
|
|
|
|
|
|
|
attrs->Set("__name", params->Get("host"));
|
|
|
|
attrs->Set("type", "Host");
|
|
|
|
|
2015-03-05 20:50:27 +01:00
|
|
|
Deserialize(host, attrs, false, FAConfig);
|
|
|
|
|
|
|
|
if (params->Contains("service"))
|
|
|
|
host->SetExtension("agent_service_name", params->Get("service"));
|
|
|
|
|
2014-11-13 11:23:57 +01:00
|
|
|
String command = params->Get("command");
|
|
|
|
String command_type = params->Get("command_type");
|
|
|
|
|
|
|
|
if (command_type == "check_command") {
|
|
|
|
if (!CheckCommand::GetByName(command)) {
|
|
|
|
CheckResult::Ptr cr = new CheckResult();
|
|
|
|
cr->SetState(ServiceUnknown);
|
|
|
|
cr->SetOutput("Check command '" + command + "' does not exist.");
|
|
|
|
Dictionary::Ptr message = MakeCheckResultMessage(host, cr);
|
2015-01-18 22:15:35 +01:00
|
|
|
listener->SyncSendMessage(sourceEndpoint, message);
|
2014-11-13 11:23:57 +01:00
|
|
|
return Empty;
|
|
|
|
}
|
|
|
|
} else if (command_type == "event_command") {
|
2015-07-31 16:04:03 +02:00
|
|
|
if (!EventCommand::GetByName(command)) {
|
|
|
|
Log(LogWarning, "ApiEvents")
|
|
|
|
<< "Event command '" << command << "' does not exist.";
|
2014-11-13 11:23:57 +01:00
|
|
|
return Empty;
|
2015-07-31 16:04:03 +02:00
|
|
|
}
|
2014-11-13 11:23:57 +01:00
|
|
|
} else
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
attrs->Set(command_type, params->Get("command"));
|
2015-01-18 22:15:35 +01:00
|
|
|
attrs->Set("command_endpoint", sourceEndpoint->GetName());
|
2014-11-13 11:23:57 +01:00
|
|
|
|
|
|
|
Deserialize(host, attrs, false, FAConfig);
|
|
|
|
|
|
|
|
host->SetExtension("agent_check", true);
|
|
|
|
|
|
|
|
Dictionary::Ptr macros = params->Get("macros");
|
|
|
|
|
2015-02-05 15:36:17 +01:00
|
|
|
if (command_type == "check_command") {
|
|
|
|
try {
|
2015-01-18 22:15:35 +01:00
|
|
|
host->ExecuteRemoteCheck(macros);
|
2015-02-05 15:36:17 +01:00
|
|
|
} catch (const std::exception& ex) {
|
|
|
|
CheckResult::Ptr cr = new CheckResult();
|
|
|
|
cr->SetState(ServiceUnknown);
|
|
|
|
|
|
|
|
String output = "Exception occured while checking '" + host->GetName() + "': " + DiagnosticInformation(ex);
|
|
|
|
cr->SetOutput(output);
|
|
|
|
|
|
|
|
double now = Utility::GetTime();
|
|
|
|
cr->SetScheduleStart(now);
|
|
|
|
cr->SetScheduleEnd(now);
|
|
|
|
cr->SetExecutionStart(now);
|
|
|
|
cr->SetExecutionEnd(now);
|
|
|
|
|
|
|
|
Dictionary::Ptr message = MakeCheckResultMessage(host, cr);
|
2015-01-18 22:15:35 +01:00
|
|
|
listener->SyncSendMessage(sourceEndpoint, message);
|
2015-02-05 15:36:17 +01:00
|
|
|
|
|
|
|
Log(LogCritical, "checker", output);
|
|
|
|
}
|
|
|
|
} else if (command_type == "event_command") {
|
2014-11-13 11:23:57 +01:00
|
|
|
host->ExecuteEventHandler(macros, true);
|
2015-02-05 15:36:17 +01:00
|
|
|
}
|
2014-11-13 11:23:57 +01:00
|
|
|
|
|
|
|
return Empty;
|
|
|
|
}
|
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
void ApiEvents::RepositoryTimerHandler(void)
|
|
|
|
{
|
|
|
|
ApiListener::Ptr listener = ApiListener::GetInstance();
|
|
|
|
|
|
|
|
if (!listener)
|
|
|
|
return;
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr repository = new Dictionary();
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2014-09-02 13:02:22 +02:00
|
|
|
BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjectsByType<Host>()) {
|
2014-11-08 21:17:16 +01:00
|
|
|
Array::Ptr services = new Array();
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
|
2014-05-08 12:17:21 +02:00
|
|
|
services->Add(service->GetShortName());
|
2014-05-03 20:02:22 +02:00
|
|
|
}
|
|
|
|
|
2014-08-22 12:59:24 +02:00
|
|
|
repository->Set(host->GetName(), services);
|
2014-05-03 20:02:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Endpoint::Ptr my_endpoint = Endpoint::GetLocalEndpoint();
|
2014-08-04 14:03:37 +02:00
|
|
|
|
|
|
|
if (!my_endpoint) {
|
|
|
|
Log(LogWarning, "ApiEvents", "No local endpoint defined. Bailing out.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
Zone::Ptr my_zone = my_endpoint->GetZone();
|
|
|
|
|
2015-02-25 13:59:18 +01:00
|
|
|
if (!my_zone)
|
|
|
|
return;
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr params = new Dictionary();
|
2014-05-08 12:17:21 +02:00
|
|
|
params->Set("seen", Utility::GetTime());
|
2014-05-03 20:02:22 +02:00
|
|
|
params->Set("endpoint", my_endpoint->GetName());
|
|
|
|
|
|
|
|
Zone::Ptr parent_zone = my_zone->GetParent();
|
|
|
|
if (parent_zone)
|
|
|
|
params->Set("parent_zone", parent_zone->GetName());
|
|
|
|
|
|
|
|
params->Set("zone", my_zone->GetName());
|
|
|
|
params->Set("repository", repository);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr message = new Dictionary();
|
2014-05-03 20:02:22 +02:00
|
|
|
message->Set("jsonrpc", "2.0");
|
|
|
|
message->Set("method", "event::UpdateRepository");
|
|
|
|
message->Set("params", params);
|
|
|
|
|
2014-05-08 15:46:47 +02:00
|
|
|
listener->RelayMessage(MessageOrigin(), my_zone, message, false);
|
2014-05-03 20:02:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String ApiEvents::GetRepositoryDir(void)
|
|
|
|
{
|
|
|
|
return Application::GetLocalStateDir() + "/lib/icinga2/api/repository/";
|
|
|
|
}
|
|
|
|
|
|
|
|
Value ApiEvents::UpdateRepositoryAPIHandler(const MessageOrigin& origin, const Dictionary::Ptr& params)
|
|
|
|
{
|
|
|
|
if (!params)
|
|
|
|
return Empty;
|
|
|
|
|
2014-08-22 12:59:24 +02:00
|
|
|
Value vrepository = params->Get("repository");
|
|
|
|
if (vrepository.IsEmpty() || !vrepository.IsObjectType<Dictionary>())
|
|
|
|
return Empty;
|
|
|
|
|
2014-10-18 21:06:28 +02:00
|
|
|
String repositoryFile = GetRepositoryDir() + SHA256(params->Get("endpoint")) + ".repo";
|
2014-05-03 20:02:22 +02:00
|
|
|
String repositoryTempFile = repositoryFile + ".tmp";
|
|
|
|
|
|
|
|
std::ofstream fp(repositoryTempFile.CStr(), std::ofstream::out | std::ostream::trunc);
|
2014-10-26 19:59:49 +01:00
|
|
|
fp << JsonEncode(params);
|
2014-05-03 20:02:22 +02:00
|
|
|
fp.close();
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2014-05-10 11:26:56 +02:00
|
|
|
_unlink(repositoryFile.CStr());
|
2014-05-03 20:02:22 +02:00
|
|
|
#endif /* _WIN32 */
|
|
|
|
|
|
|
|
if (rename(repositoryTempFile.CStr(), repositoryFile.CStr()) < 0) {
|
|
|
|
BOOST_THROW_EXCEPTION(posix_error()
|
|
|
|
<< boost::errinfo_api_function("rename")
|
|
|
|
<< boost::errinfo_errno(errno)
|
|
|
|
<< boost::errinfo_file_name(repositoryTempFile));
|
|
|
|
}
|
|
|
|
|
|
|
|
ApiListener::Ptr listener = ApiListener::GetInstance();
|
|
|
|
|
|
|
|
if (!listener)
|
|
|
|
return Empty;
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr message = new Dictionary();
|
2014-05-03 20:02:22 +02:00
|
|
|
message->Set("jsonrpc", "2.0");
|
|
|
|
message->Set("method", "event::UpdateRepository");
|
|
|
|
message->Set("params", params);
|
|
|
|
|
|
|
|
listener->RelayMessage(origin, Zone::GetLocalZone(), message, true);
|
|
|
|
|
|
|
|
return Empty;
|
|
|
|
}
|
2014-05-08 13:08:34 +02:00
|
|
|
|