"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lib/icinga/clusterevents.cpp" between
icinga2-2.11.5.tar.gz and icinga2-2.12.0.tar.gz

About: Icinga 2 is an enterprise grade monitoring system which keeps watch over networks and any conceivable network resource.

clusterevents.cpp  (icinga2-2.11.5):clusterevents.cpp  (icinga2-2.12.0)
skipping to change at line 27 skipping to change at line 27
#include "base/serializer.hpp" #include "base/serializer.hpp"
#include "base/json.hpp" #include "base/json.hpp"
#include <fstream> #include <fstream>
using namespace icinga; using namespace icinga;
INITIALIZE_ONCE(&ClusterEvents::StaticInitialize); INITIALIZE_ONCE(&ClusterEvents::StaticInitialize);
REGISTER_APIFUNCTION(CheckResult, event, &ClusterEvents::CheckResultAPIHandler); REGISTER_APIFUNCTION(CheckResult, event, &ClusterEvents::CheckResultAPIHandler);
REGISTER_APIFUNCTION(SetNextCheck, event, &ClusterEvents::NextCheckChangedAPIHan dler); REGISTER_APIFUNCTION(SetNextCheck, event, &ClusterEvents::NextCheckChangedAPIHan dler);
REGISTER_APIFUNCTION(SetLastCheckStarted, event, &ClusterEvents::LastCheckStarte dChangedAPIHandler);
REGISTER_APIFUNCTION(SetSuppressedNotifications, event, &ClusterEvents::Suppress edNotificationsChangedAPIHandler); REGISTER_APIFUNCTION(SetSuppressedNotifications, event, &ClusterEvents::Suppress edNotificationsChangedAPIHandler);
REGISTER_APIFUNCTION(SetSuppressedNotificationTypes, event, &ClusterEvents::Supp ressedNotificationTypesChangedAPIHandler);
REGISTER_APIFUNCTION(SetNextNotification, event, &ClusterEvents::NextNotificatio nChangedAPIHandler); REGISTER_APIFUNCTION(SetNextNotification, event, &ClusterEvents::NextNotificatio nChangedAPIHandler);
REGISTER_APIFUNCTION(SetForceNextCheck, event, &ClusterEvents::ForceNextCheckCha ngedAPIHandler); REGISTER_APIFUNCTION(SetForceNextCheck, event, &ClusterEvents::ForceNextCheckCha ngedAPIHandler);
REGISTER_APIFUNCTION(SetForceNextNotification, event, &ClusterEvents::ForceNextN otificationChangedAPIHandler); REGISTER_APIFUNCTION(SetForceNextNotification, event, &ClusterEvents::ForceNextN otificationChangedAPIHandler);
REGISTER_APIFUNCTION(SetAcknowledgement, event, &ClusterEvents::AcknowledgementS etAPIHandler); REGISTER_APIFUNCTION(SetAcknowledgement, event, &ClusterEvents::AcknowledgementS etAPIHandler);
REGISTER_APIFUNCTION(ClearAcknowledgement, event, &ClusterEvents::Acknowledgemen tClearedAPIHandler); REGISTER_APIFUNCTION(ClearAcknowledgement, event, &ClusterEvents::Acknowledgemen tClearedAPIHandler);
REGISTER_APIFUNCTION(ExecuteCommand, event, &ClusterEvents::ExecuteCommandAPIHan dler); REGISTER_APIFUNCTION(ExecuteCommand, event, &ClusterEvents::ExecuteCommandAPIHan dler);
REGISTER_APIFUNCTION(SendNotifications, event, &ClusterEvents::SendNotifications APIHandler); REGISTER_APIFUNCTION(SendNotifications, event, &ClusterEvents::SendNotifications APIHandler);
REGISTER_APIFUNCTION(NotificationSentUser, event, &ClusterEvents::NotificationSe ntUserAPIHandler); REGISTER_APIFUNCTION(NotificationSentUser, event, &ClusterEvents::NotificationSe ntUserAPIHandler);
REGISTER_APIFUNCTION(NotificationSentToAllUsers, event, &ClusterEvents::Notifica tionSentToAllUsersAPIHandler); REGISTER_APIFUNCTION(NotificationSentToAllUsers, event, &ClusterEvents::Notifica tionSentToAllUsersAPIHandler);
void ClusterEvents::StaticInitialize() void ClusterEvents::StaticInitialize()
{ {
Checkable::OnNewCheckResult.connect(&ClusterEvents::CheckResultHandler); Checkable::OnNewCheckResult.connect(&ClusterEvents::CheckResultHandler);
Checkable::OnNextCheckChanged.connect(&ClusterEvents::NextCheckChangedHan dler); Checkable::OnNextCheckChanged.connect(&ClusterEvents::NextCheckChangedHan dler);
Checkable::OnLastCheckStartedChanged.connect(&ClusterEvents::LastCheckSta rtedChangedHandler);
Checkable::OnSuppressedNotificationsChanged.connect(&ClusterEvents::Suppr essedNotificationsChangedHandler); Checkable::OnSuppressedNotificationsChanged.connect(&ClusterEvents::Suppr essedNotificationsChangedHandler);
Notification::OnSuppressedNotificationsChanged.connect(&ClusterEvents::Su ppressedNotificationTypesChangedHandler);
Notification::OnNextNotificationChanged.connect(&ClusterEvents::NextNotif icationChangedHandler); Notification::OnNextNotificationChanged.connect(&ClusterEvents::NextNotif icationChangedHandler);
Checkable::OnForceNextCheckChanged.connect(&ClusterEvents::ForceNextCheck ChangedHandler); Checkable::OnForceNextCheckChanged.connect(&ClusterEvents::ForceNextCheck ChangedHandler);
Checkable::OnForceNextNotificationChanged.connect(&ClusterEvents::ForceNe xtNotificationChangedHandler); Checkable::OnForceNextNotificationChanged.connect(&ClusterEvents::ForceNe xtNotificationChangedHandler);
Checkable::OnNotificationsRequested.connect(&ClusterEvents::SendNotificat ionsHandler); Checkable::OnNotificationsRequested.connect(&ClusterEvents::SendNotificat ionsHandler);
Checkable::OnNotificationSentToUser.connect(&ClusterEvents::NotificationS entUserHandler); Checkable::OnNotificationSentToUser.connect(&ClusterEvents::NotificationS entUserHandler);
Checkable::OnNotificationSentToAllUsers.connect(&ClusterEvents::Notificat ionSentToAllUsersHandler); Checkable::OnNotificationSentToAllUsers.connect(&ClusterEvents::Notificat ionSentToAllUsersHandler);
Checkable::OnAcknowledgementSet.connect(&ClusterEvents::AcknowledgementSe tHandler); Checkable::OnAcknowledgementSet.connect(&ClusterEvents::AcknowledgementSe tHandler);
Checkable::OnAcknowledgementCleared.connect(&ClusterEvents::Acknowledgeme ntClearedHandler); Checkable::OnAcknowledgementCleared.connect(&ClusterEvents::Acknowledgeme ntClearedHandler);
} }
skipping to change at line 237 skipping to change at line 241
double nextCheck = params->Get("next_check"); double nextCheck = params->Get("next_check");
if (nextCheck < Application::GetStartTime() + 60) if (nextCheck < Application::GetStartTime() + 60)
return Empty; return Empty;
checkable->SetNextCheck(params->Get("next_check"), false, origin); checkable->SetNextCheck(params->Get("next_check"), false, origin);
return Empty; return Empty;
} }
void ClusterEvents::LastCheckStartedChangedHandler(const Checkable::Ptr& checkab
le, 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("last_check_started", checkable->GetLastCheckStarted());
Dictionary::Ptr message = new Dictionary();
message->Set("jsonrpc", "2.0");
message->Set("method", "event::SetLastCheckStarted");
message->Set("params", params);
listener->RelayMessage(origin, checkable, message, true);
}
Value ClusterEvents::LastCheckStartedChangedAPIHandler(const MessageOrigin::Ptr&
origin, const Dictionary::Ptr& params)
{
Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint();
if (!endpoint) {
Log(LogNotice, "ClusterEvents")
<< "Discarding 'last_check_started changed' message from
'" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client n
ot allowed).";
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, "ClusterEvents")
<< "Discarding 'last_check_started changed' message for c
heckable '" << checkable->GetName()
<< "' from '" << origin->FromClient->GetIdentity() << "':
Unauthorized access.";
return Empty;
}
checkable->SetLastCheckStarted(params->Get("last_check_started"), false,
origin);
return Empty;
}
void ClusterEvents::SuppressedNotificationsChangedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin) void ClusterEvents::SuppressedNotificationsChangedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin)
{ {
ApiListener::Ptr listener = ApiListener::GetInstance(); ApiListener::Ptr listener = ApiListener::GetInstance();
if (!listener) if (!listener)
return; return;
Host::Ptr host; Host::Ptr host;
Service::Ptr service; Service::Ptr service;
tie(host, service) = GetHostService(checkable); tie(host, service) = GetHostService(checkable);
skipping to change at line 299 skipping to change at line 365
<< "Discarding 'suppressed notifications changed' message for checkable '" << checkable->GetName() << "Discarding 'suppressed notifications changed' message for checkable '" << checkable->GetName()
<< "' from '" << origin->FromClient->GetIdentity() << "': Unauthorized access."; << "' from '" << origin->FromClient->GetIdentity() << "': Unauthorized access.";
return Empty; return Empty;
} }
checkable->SetSuppressedNotifications(params->Get("suppressed_notificatio ns"), false, origin); checkable->SetSuppressedNotifications(params->Get("suppressed_notificatio ns"), false, origin);
return Empty; return Empty;
} }
void ClusterEvents::SuppressedNotificationTypesChangedHandler(const Notification
::Ptr& notification, const MessageOrigin::Ptr& origin)
{
ApiListener::Ptr listener = ApiListener::GetInstance();
if (!listener)
return;
Dictionary::Ptr params = new Dictionary();
params->Set("notification", notification->GetName());
params->Set("suppressed_notifications", notification->GetSuppressedNotifi
cations());
Dictionary::Ptr message = new Dictionary();
message->Set("jsonrpc", "2.0");
message->Set("method", "event::SetSuppressedNotificationTypes");
message->Set("params", params);
listener->RelayMessage(origin, notification, message, true);
}
Value ClusterEvents::SuppressedNotificationTypesChangedAPIHandler(const MessageO
rigin::Ptr& origin, const Dictionary::Ptr& params)
{
Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint();
if (!endpoint) {
Log(LogNotice, "ClusterEvents")
<< "Discarding 'suppressed notifications changed' message
from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (cl
ient not allowed).";
return Empty;
}
auto notification (Notification::GetByName(params->Get("notification")));
if (!notification)
return Empty;
if (origin->FromZone && !origin->FromZone->CanAccessObject(notification))
{
Log(LogNotice, "ClusterEvents")
<< "Discarding 'suppressed notification types changed' me
ssage for notification '" << notification->GetName()
<< "' from '" << origin->FromClient->GetIdentity() << "':
Unauthorized access.";
return Empty;
}
notification->SetSuppressedNotifications(params->Get("suppressed_notifica
tions"), false, origin);
return Empty;
}
void ClusterEvents::NextNotificationChangedHandler(const Notification::Ptr& noti fication, const MessageOrigin::Ptr& origin) void ClusterEvents::NextNotificationChangedHandler(const Notification::Ptr& noti fication, const MessageOrigin::Ptr& origin)
{ {
ApiListener::Ptr listener = ApiListener::GetInstance(); ApiListener::Ptr listener = ApiListener::GetInstance();
if (!listener) if (!listener)
return; return;
Dictionary::Ptr params = new Dictionary(); Dictionary::Ptr params = new Dictionary();
params->Set("notification", notification->GetName()); params->Set("notification", notification->GetName());
params->Set("next_notification", notification->GetNextNotification()); params->Set("next_notification", notification->GetNextNotification());
skipping to change at line 476 skipping to change at line 588
return Empty; return Empty;
} }
checkable->SetForceNextNotification(params->Get("forced"), false, origin) ; checkable->SetForceNextNotification(params->Get("forced"), false, origin) ;
return Empty; return Empty;
} }
void ClusterEvents::AcknowledgementSetHandler(const Checkable::Ptr& checkable, void ClusterEvents::AcknowledgementSetHandler(const Checkable::Ptr& checkable,
const String& author, const String& comment, AcknowledgementType type, const String& author, const String& comment, AcknowledgementType type,
bool notify, bool persistent, double expiry, const MessageOrigin::Ptr& or igin) bool notify, bool persistent, double changeTime, double expiry, const Mes sageOrigin::Ptr& origin)
{ {
ApiListener::Ptr listener = ApiListener::GetInstance(); ApiListener::Ptr listener = ApiListener::GetInstance();
if (!listener) if (!listener)
return; return;
Host::Ptr host; Host::Ptr host;
Service::Ptr service; Service::Ptr service;
tie(host, service) = GetHostService(checkable); tie(host, service) = GetHostService(checkable);
Dictionary::Ptr params = new Dictionary(); Dictionary::Ptr params = new Dictionary();
params->Set("host", host->GetName()); params->Set("host", host->GetName());
if (service) if (service)
params->Set("service", service->GetShortName()); params->Set("service", service->GetShortName());
params->Set("author", author); params->Set("author", author);
params->Set("comment", comment); params->Set("comment", comment);
params->Set("acktype", type); params->Set("acktype", type);
params->Set("notify", notify); params->Set("notify", notify);
params->Set("persistent", persistent); params->Set("persistent", persistent);
params->Set("expiry", expiry); params->Set("expiry", expiry);
params->Set("change_time", changeTime);
Dictionary::Ptr message = new Dictionary(); Dictionary::Ptr message = new Dictionary();
message->Set("jsonrpc", "2.0"); message->Set("jsonrpc", "2.0");
message->Set("method", "event::SetAcknowledgement"); message->Set("method", "event::SetAcknowledgement");
message->Set("params", params); message->Set("params", params);
listener->RelayMessage(origin, checkable, message, true); listener->RelayMessage(origin, checkable, message, true);
} }
Value ClusterEvents::AcknowledgementSetAPIHandler(const MessageOrigin::Ptr& orig in, const Dictionary::Ptr& params) Value ClusterEvents::AcknowledgementSetAPIHandler(const MessageOrigin::Ptr& orig in, const Dictionary::Ptr& params)
skipping to change at line 538 skipping to change at line 651
if (!checkable) if (!checkable)
return Empty; return Empty;
if (origin->FromZone && !origin->FromZone->CanAccessObject(checkable)) { if (origin->FromZone && !origin->FromZone->CanAccessObject(checkable)) {
Log(LogNotice, "ClusterEvents") Log(LogNotice, "ClusterEvents")
<< "Discarding 'acknowledgement set' message for checkabl e '" << checkable->GetName() << "Discarding 'acknowledgement set' message for checkabl e '" << checkable->GetName()
<< "' from '" << origin->FromClient->GetIdentity() << "': Unauthorized access."; << "' from '" << origin->FromClient->GetIdentity() << "': Unauthorized access.";
return Empty; return Empty;
} }
ObjectLock oLock (checkable);
if (checkable->IsAcknowledged()) {
Log(LogWarning, "ClusterEvents")
<< "Discarding 'acknowledgement set' message for checkabl
e '" << checkable->GetName()
<< "' from '" << origin->FromClient->GetIdentity() << "':
Checkable is already acknowledged.";
return Empty;
}
checkable->AcknowledgeProblem(params->Get("author"), params->Get("comment "), checkable->AcknowledgeProblem(params->Get("author"), params->Get("comment "),
static_cast<AcknowledgementType>(static_cast<int>(params->Get("ac ktype"))), static_cast<AcknowledgementType>(static_cast<int>(params->Get("ac ktype"))),
params->Get("notify"), params->Get("persistent"), params->Get("ex piry"), origin); params->Get("notify"), params->Get("persistent"), params->Get("ch ange_time"), params->Get("expiry"), origin);
return Empty; return Empty;
} }
void ClusterEvents::AcknowledgementClearedHandler(const Checkable::Ptr& checkabl e, const MessageOrigin::Ptr& origin) void ClusterEvents::AcknowledgementClearedHandler(const Checkable::Ptr& checkabl e, const String& removedBy, double changeTime, const MessageOrigin::Ptr& origin)
{ {
ApiListener::Ptr listener = ApiListener::GetInstance(); ApiListener::Ptr listener = ApiListener::GetInstance();
if (!listener) if (!listener)
return; return;
Host::Ptr host; Host::Ptr host;
Service::Ptr service; Service::Ptr service;
tie(host, service) = GetHostService(checkable); tie(host, service) = GetHostService(checkable);
Dictionary::Ptr params = new Dictionary(); Dictionary::Ptr params = new Dictionary();
params->Set("host", host->GetName()); params->Set("host", host->GetName());
if (service) if (service)
params->Set("service", service->GetShortName()); params->Set("service", service->GetShortName());
params->Set("author", removedBy);
params->Set("change_time", changeTime);
Dictionary::Ptr message = new Dictionary(); Dictionary::Ptr message = new Dictionary();
message->Set("jsonrpc", "2.0"); message->Set("jsonrpc", "2.0");
message->Set("method", "event::ClearAcknowledgement"); message->Set("method", "event::ClearAcknowledgement");
message->Set("params", params); message->Set("params", params);
listener->RelayMessage(origin, checkable, message, true); listener->RelayMessage(origin, checkable, message, true);
} }
Value ClusterEvents::AcknowledgementClearedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params) Value ClusterEvents::AcknowledgementClearedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params)
skipping to change at line 601 skipping to change at line 725
if (!checkable) if (!checkable)
return Empty; return Empty;
if (origin->FromZone && !origin->FromZone->CanAccessObject(checkable)) { if (origin->FromZone && !origin->FromZone->CanAccessObject(checkable)) {
Log(LogNotice, "ClusterEvents") Log(LogNotice, "ClusterEvents")
<< "Discarding 'acknowledgement cleared' message for chec kable '" << checkable->GetName() << "Discarding 'acknowledgement cleared' message for chec kable '" << checkable->GetName()
<< "' from '" << origin->FromClient->GetIdentity() << "': Unauthorized access."; << "' from '" << origin->FromClient->GetIdentity() << "': Unauthorized access.";
return Empty; return Empty;
} }
checkable->ClearAcknowledgement(origin); checkable->ClearAcknowledgement(params->Get("author"), params->Get("chang e_time"), origin);
return Empty; return Empty;
} }
Value ClusterEvents::ExecuteCommandAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params) Value ClusterEvents::ExecuteCommandAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params)
{ {
EnqueueCheck(origin, params); EnqueueCheck(origin, params);
return Empty; return Empty;
} }
 End of changes. 13 change blocks. 
4 lines changed or deleted 146 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)