1 /******************************************************************************
3 * Copyright (C) 2012-2018 Icinga Development Team (https://icinga.com/) *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License *
7 * as published by the Free Software Foundation; either version 2 *
8 * of the License, or (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software Foundation *
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ******************************************************************************/
20 #include "icinga/clusterevents.hpp"
21 #include "icinga/service.hpp"
22 #include "remote/apilistener.hpp"
23 #include "remote/endpoint.hpp"
24 #include "remote/messageorigin.hpp"
25 #include "remote/zone.hpp"
26 #include "remote/apifunction.hpp"
27 #include "remote/eventqueue.hpp"
28 #include "base/application.hpp"
29 #include "base/configtype.hpp"
30 #include "base/utility.hpp"
31 #include "base/perfdatavalue.hpp"
32 #include "base/exception.hpp"
33 #include "base/initialize.hpp"
34 #include "base/serializer.hpp"
35 #include "base/json.hpp"
38 using namespace icinga;
40 INITIALIZE_ONCE(&ClusterEvents::StaticInitialize);
42 REGISTER_APIFUNCTION(CheckResult, event, &ClusterEvents::CheckResultAPIHandler);
43 REGISTER_APIFUNCTION(SetNextCheck, event, &ClusterEvents::NextCheckChangedAPIHandler);
44 REGISTER_APIFUNCTION(SetNextNotification, event, &ClusterEvents::NextNotificationChangedAPIHandler);
45 REGISTER_APIFUNCTION(SetForceNextCheck, event, &ClusterEvents::ForceNextCheckChangedAPIHandler);
46 REGISTER_APIFUNCTION(SetForceNextNotification, event, &ClusterEvents::ForceNextNotificationChangedAPIHandler);
47 REGISTER_APIFUNCTION(SetAcknowledgement, event, &ClusterEvents::AcknowledgementSetAPIHandler);
48 REGISTER_APIFUNCTION(ClearAcknowledgement, event, &ClusterEvents::AcknowledgementClearedAPIHandler);
49 REGISTER_APIFUNCTION(ExecuteCommand, event, &ClusterEvents::ExecuteCommandAPIHandler);
50 REGISTER_APIFUNCTION(SendNotifications, event, &ClusterEvents::SendNotificationsAPIHandler);
51 REGISTER_APIFUNCTION(NotificationSentUser, event, &ClusterEvents::NotificationSentUserAPIHandler);
52 REGISTER_APIFUNCTION(NotificationSentToAllUsers, event, &ClusterEvents::NotificationSentToAllUsersAPIHandler);
54 void ClusterEvents::StaticInitialize()
56 Checkable::OnNewCheckResult.connect(&ClusterEvents::CheckResultHandler);
57 Checkable::OnNextCheckChanged.connect(&ClusterEvents::NextCheckChangedHandler);
58 Notification::OnNextNotificationChanged.connect(&ClusterEvents::NextNotificationChangedHandler);
59 Checkable::OnForceNextCheckChanged.connect(&ClusterEvents::ForceNextCheckChangedHandler);
60 Checkable::OnForceNextNotificationChanged.connect(&ClusterEvents::ForceNextNotificationChangedHandler);
61 Checkable::OnNotificationsRequested.connect(&ClusterEvents::SendNotificationsHandler);
62 Checkable::OnNotificationSentToUser.connect(&ClusterEvents::NotificationSentUserHandler);
63 Checkable::OnNotificationSentToAllUsers.connect(&ClusterEvents::NotificationSentToAllUsersHandler);
65 Checkable::OnAcknowledgementSet.connect(&ClusterEvents::AcknowledgementSetHandler);
66 Checkable::OnAcknowledgementCleared.connect(&ClusterEvents::AcknowledgementClearedHandler);
69 Dictionary::Ptr ClusterEvents::MakeCheckResultMessage(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr)
71 Dictionary::Ptr message = new Dictionary();
72 message->Set("jsonrpc", "2.0");
73 message->Set("method", "event::CheckResult");
77 tie(host, service) = GetHostService(checkable);
79 Dictionary::Ptr params = new Dictionary();
80 params->Set("host", host->GetName());
82 params->Set("service", service->GetShortName());
84 Value agent_service_name = checkable->GetExtension("agent_service_name");
86 if (!agent_service_name.IsEmpty())
87 params->Set("service", agent_service_name);
89 params->Set("cr", Serialize(cr));
91 message->Set("params", params);
96 void ClusterEvents::CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const MessageOrigin::Ptr& origin)
98 ApiListener::Ptr listener = ApiListener::GetInstance();
103 Dictionary::Ptr message = MakeCheckResultMessage(checkable, cr);
104 listener->RelayMessage(origin, checkable, message, true);
107 Value ClusterEvents::CheckResultAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params)
109 Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint();
112 Log(LogNotice, "ClusterEvents")
113 << "Discarding 'check result' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
120 if (params->Contains("cr")) {
121 cr = new CheckResult();
122 Dictionary::Ptr vcr = params->Get("cr");
124 if (vcr && vcr->Contains("performance_data")) {
125 vperf = vcr->Get("performance_data");
128 vcr->Remove("performance_data");
130 Deserialize(cr, vcr, true);
140 ObjectLock olock(vperf);
141 for (const Value& vp : vperf) {
144 if (vp.IsObjectType<Dictionary>()) {
145 PerfdataValue::Ptr val = new PerfdataValue();
146 Deserialize(val, vp, true);
147 rperf.push_back(val);
153 cr->SetPerformanceData(new Array(std::move(rperf)));
155 Host::Ptr host = Host::GetByName(params->Get("host"));
160 Checkable::Ptr checkable;
162 if (params->Contains("service"))
163 checkable = host->GetServiceByShortName(params->Get("service"));
170 if (origin->FromZone && !origin->FromZone->CanAccessObject(checkable) && endpoint != checkable->GetCommandEndpoint()) {
171 Log(LogNotice, "ClusterEvents")
172 << "Discarding 'check result' message for checkable '" << checkable->GetName()
173 << "' from '" << origin->FromClient->GetIdentity() << "': Unauthorized access.";
177 if (!checkable->IsPaused() && Zone::GetLocalZone() == checkable->GetZone() && endpoint == checkable->GetCommandEndpoint())
178 checkable->ProcessCheckResult(cr);
180 checkable->ProcessCheckResult(cr, origin);
185 void ClusterEvents::NextCheckChangedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin)
187 ApiListener::Ptr listener = ApiListener::GetInstance();
193 Service::Ptr service;
194 tie(host, service) = GetHostService(checkable);
196 Dictionary::Ptr params = new Dictionary();
197 params->Set("host", host->GetName());
199 params->Set("service", service->GetShortName());
200 params->Set("next_check", checkable->GetNextCheck());
202 Dictionary::Ptr message = new Dictionary();
203 message->Set("jsonrpc", "2.0");
204 message->Set("method", "event::SetNextCheck");
205 message->Set("params", params);
207 listener->RelayMessage(origin, checkable, message, true);
210 Value ClusterEvents::NextCheckChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params)
212 Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint();
215 Log(LogNotice, "ClusterEvents")
216 << "Discarding 'next check changed' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
220 Host::Ptr host = Host::GetByName(params->Get("host"));
225 Checkable::Ptr checkable;
227 if (params->Contains("service"))
228 checkable = host->GetServiceByShortName(params->Get("service"));
235 if (origin->FromZone && !origin->FromZone->CanAccessObject(checkable)) {
236 Log(LogNotice, "ClusterEvents")
237 << "Discarding 'next check changed' message for checkable '" << checkable->GetName()
238 << "' from '" << origin->FromClient->GetIdentity() << "': Unauthorized access.";
242 double nextCheck = params->Get("next_check");
244 if (nextCheck < Application::GetStartTime() + 60)
247 checkable->SetNextCheck(params->Get("next_check"), false, origin);
252 void ClusterEvents::NextNotificationChangedHandler(const Notification::Ptr& notification, const MessageOrigin::Ptr& origin)
254 ApiListener::Ptr listener = ApiListener::GetInstance();
259 Dictionary::Ptr params = new Dictionary();
260 params->Set("notification", notification->GetName());
261 params->Set("next_notification", notification->GetNextNotification());
263 Dictionary::Ptr message = new Dictionary();
264 message->Set("jsonrpc", "2.0");
265 message->Set("method", "event::SetNextNotification");
266 message->Set("params", params);
268 listener->RelayMessage(origin, notification, message, true);
271 Value ClusterEvents::NextNotificationChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params)
273 Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint();
276 Log(LogNotice, "ClusterEvents")
277 << "Discarding 'next notification changed' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
281 Notification::Ptr notification = Notification::GetByName(params->Get("notification"));
286 if (origin->FromZone && !origin->FromZone->CanAccessObject(notification)) {
287 Log(LogNotice, "ClusterEvents")
288 << "Discarding 'next notification changed' message for notification '" << notification->GetName()
289 << "' from '" << origin->FromClient->GetIdentity() << "': Unauthorized access.";
293 double nextNotification = params->Get("next_notification");
295 if (nextNotification < Utility::GetTime())
298 notification->SetNextNotification(nextNotification, false, origin);
303 void ClusterEvents::ForceNextCheckChangedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin)
305 ApiListener::Ptr listener = ApiListener::GetInstance();
311 Service::Ptr service;
312 tie(host, service) = GetHostService(checkable);
314 Dictionary::Ptr params = new Dictionary();
315 params->Set("host", host->GetName());
317 params->Set("service", service->GetShortName());
318 params->Set("forced", checkable->GetForceNextCheck());
320 Dictionary::Ptr message = new Dictionary();
321 message->Set("jsonrpc", "2.0");
322 message->Set("method", "event::SetForceNextCheck");
323 message->Set("params", params);
325 listener->RelayMessage(origin, checkable, message, true);
328 Value ClusterEvents::ForceNextCheckChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params)
330 Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint();
333 Log(LogNotice, "ClusterEvents")
334 << "Discarding 'force next check changed' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
338 Host::Ptr host = Host::GetByName(params->Get("host"));
343 Checkable::Ptr checkable;
345 if (params->Contains("service"))
346 checkable = host->GetServiceByShortName(params->Get("service"));
353 if (origin->FromZone && !origin->FromZone->CanAccessObject(checkable)) {
354 Log(LogNotice, "ClusterEvents")
355 << "Discarding 'force next check' message for checkable '" << checkable->GetName()
356 << "' from '" << origin->FromClient->GetIdentity() << "': Unauthorized access.";
360 checkable->SetForceNextCheck(params->Get("forced"), false, origin);
365 void ClusterEvents::ForceNextNotificationChangedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin)
367 ApiListener::Ptr listener = ApiListener::GetInstance();
373 Service::Ptr service;
374 tie(host, service) = GetHostService(checkable);
376 Dictionary::Ptr params = new Dictionary();
377 params->Set("host", host->GetName());
379 params->Set("service", service->GetShortName());
380 params->Set("forced", checkable->GetForceNextNotification());
382 Dictionary::Ptr message = new Dictionary();
383 message->Set("jsonrpc", "2.0");
384 message->Set("method", "event::SetForceNextNotification");
385 message->Set("params", params);
387 listener->RelayMessage(origin, checkable, message, true);
390 Value ClusterEvents::ForceNextNotificationChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params)
392 Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint();
395 Log(LogNotice, "ClusterEvents")
396 << "Discarding 'force next notification changed' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
400 Host::Ptr host = Host::GetByName(params->Get("host"));
405 Checkable::Ptr checkable;
407 if (params->Contains("service"))
408 checkable = host->GetServiceByShortName(params->Get("service"));
415 if (origin->FromZone && !origin->FromZone->CanAccessObject(checkable)) {
416 Log(LogNotice, "ClusterEvents")
417 << "Discarding 'force next notification' message for checkable '" << checkable->GetName()
418 << "' from '" << origin->FromClient->GetIdentity() << "': Unauthorized access.";
422 checkable->SetForceNextNotification(params->Get("forced"), false, origin);
427 void ClusterEvents::AcknowledgementSetHandler(const Checkable::Ptr& checkable,
428 const String& author, const String& comment, AcknowledgementType type,
429 bool notify, bool persistent, double expiry, const MessageOrigin::Ptr& origin)
431 ApiListener::Ptr listener = ApiListener::GetInstance();
437 Service::Ptr service;
438 tie(host, service) = GetHostService(checkable);
440 Dictionary::Ptr params = new Dictionary();
441 params->Set("host", host->GetName());
443 params->Set("service", service->GetShortName());
444 params->Set("author", author);
445 params->Set("comment", comment);
446 params->Set("acktype", type);
447 params->Set("notify", notify);
448 params->Set("expiry", expiry);
450 Dictionary::Ptr message = new Dictionary();
451 message->Set("jsonrpc", "2.0");
452 message->Set("method", "event::SetAcknowledgement");
453 message->Set("params", params);
455 listener->RelayMessage(origin, checkable, message, true);
458 Value ClusterEvents::AcknowledgementSetAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params)
460 Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint();
463 Log(LogNotice, "ClusterEvents")
464 << "Discarding 'acknowledgement set' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
468 Host::Ptr host = Host::GetByName(params->Get("host"));
473 Checkable::Ptr checkable;
475 if (params->Contains("service"))
476 checkable = host->GetServiceByShortName(params->Get("service"));
483 if (origin->FromZone && !origin->FromZone->CanAccessObject(checkable)) {
484 Log(LogNotice, "ClusterEvents")
485 << "Discarding 'acknowledgement set' message for checkable '" << checkable->GetName()
486 << "' from '" << origin->FromClient->GetIdentity() << "': Unauthorized access.";
490 checkable->AcknowledgeProblem(params->Get("author"), params->Get("comment"),
491 static_cast<AcknowledgementType>(static_cast<int>(params->Get("acktype"))),
492 params->Get("notify"), params->Get("persistent"), params->Get("expiry"), origin);
497 void ClusterEvents::AcknowledgementClearedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin)
499 ApiListener::Ptr listener = ApiListener::GetInstance();
505 Service::Ptr service;
506 tie(host, service) = GetHostService(checkable);
508 Dictionary::Ptr params = new Dictionary();
509 params->Set("host", host->GetName());
511 params->Set("service", service->GetShortName());
513 Dictionary::Ptr message = new Dictionary();
514 message->Set("jsonrpc", "2.0");
515 message->Set("method", "event::ClearAcknowledgement");
516 message->Set("params", params);
518 listener->RelayMessage(origin, checkable, message, true);
521 Value ClusterEvents::AcknowledgementClearedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params)
523 Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint();
526 Log(LogNotice, "ClusterEvents")
527 << "Discarding 'acknowledgement cleared' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
531 Host::Ptr host = Host::GetByName(params->Get("host"));
536 Checkable::Ptr checkable;
538 if (params->Contains("service"))
539 checkable = host->GetServiceByShortName(params->Get("service"));
546 if (origin->FromZone && !origin->FromZone->CanAccessObject(checkable)) {
547 Log(LogNotice, "ClusterEvents")
548 << "Discarding 'acknowledgement cleared' message for checkable '" << checkable->GetName()
549 << "' from '" << origin->FromClient->GetIdentity() << "': Unauthorized access.";
553 checkable->ClearAcknowledgement(origin);
558 Value ClusterEvents::ExecuteCommandAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params)
560 EnqueueCheck(origin, params);
565 void ClusterEvents::SendNotificationsHandler(const Checkable::Ptr& checkable, NotificationType type,
566 const CheckResult::Ptr& cr, const String& author, const String& text, const MessageOrigin::Ptr& origin)
568 ApiListener::Ptr listener = ApiListener::GetInstance();
573 Dictionary::Ptr message = MakeCheckResultMessage(checkable, cr);
574 message->Set("method", "event::SendNotifications");
576 Dictionary::Ptr params = message->Get("params");
577 params->Set("type", type);
578 params->Set("author", author);
579 params->Set("text", text);
581 listener->RelayMessage(origin, nullptr, message, true);
584 Value ClusterEvents::SendNotificationsAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params)
586 Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint();
589 Log(LogNotice, "ClusterEvents")
590 << "Discarding 'send notification' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
594 Host::Ptr host = Host::GetByName(params->Get("host"));
599 Checkable::Ptr checkable;
601 if (params->Contains("service"))
602 checkable = host->GetServiceByShortName(params->Get("service"));
609 if (origin->FromZone && origin->FromZone != Zone::GetLocalZone()) {
610 Log(LogNotice, "ClusterEvents")
611 << "Discarding 'send custom notification' message for checkable '" << checkable->GetName()
612 << "' from '" << origin->FromClient->GetIdentity() << "': Unauthorized access.";
619 if (params->Contains("cr")) {
620 cr = new CheckResult();
621 Dictionary::Ptr vcr = params->Get("cr");
623 if (vcr && vcr->Contains("performance_data")) {
624 vperf = vcr->Get("performance_data");
627 vcr->Remove("performance_data");
629 Deserialize(cr, vcr, true);
633 NotificationType type = static_cast<NotificationType>(static_cast<int>(params->Get("type")));
634 String author = params->Get("author");
635 String text = params->Get("text");
637 Checkable::OnNotificationsRequested(checkable, type, cr, author, text, origin);
642 void ClusterEvents::NotificationSentUserHandler(const Notification::Ptr& notification, const Checkable::Ptr& checkable, const User::Ptr& user,
643 NotificationType notificationType, const CheckResult::Ptr& cr, const String& author, const String& commentText, const String& command,
644 const MessageOrigin::Ptr& origin)
646 ApiListener::Ptr listener = ApiListener::GetInstance();
652 Service::Ptr service;
653 tie(host, service) = GetHostService(checkable);
655 Dictionary::Ptr params = new Dictionary();
656 params->Set("host", host->GetName());
658 params->Set("service", service->GetShortName());
659 params->Set("notification", notification->GetName());
660 params->Set("user", user->GetName());
661 params->Set("type", notificationType);
662 params->Set("cr", Serialize(cr));
663 params->Set("author", author);
664 params->Set("text", commentText);
665 params->Set("command", command);
667 Dictionary::Ptr message = new Dictionary();
668 message->Set("jsonrpc", "2.0");
669 message->Set("method", "event::NotificationSentUser");
670 message->Set("params", params);
672 listener->RelayMessage(origin, nullptr, message, true);
675 Value ClusterEvents::NotificationSentUserAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params)
677 Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint();
680 Log(LogNotice, "ClusterEvents")
681 << "Discarding 'sent notification to user' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
685 Host::Ptr host = Host::GetByName(params->Get("host"));
690 Checkable::Ptr checkable;
692 if (params->Contains("service"))
693 checkable = host->GetServiceByShortName(params->Get("service"));
700 if (origin->FromZone && origin->FromZone != Zone::GetLocalZone()) {
701 Log(LogNotice, "ClusterEvents")
702 << "Discarding 'send notification to user' message for checkable '" << checkable->GetName()
703 << "' from '" << origin->FromClient->GetIdentity() << "': Unauthorized access.";
710 if (params->Contains("cr")) {
711 cr = new CheckResult();
712 Dictionary::Ptr vcr = params->Get("cr");
714 if (vcr && vcr->Contains("performance_data")) {
715 vperf = vcr->Get("performance_data");
718 vcr->Remove("performance_data");
720 Deserialize(cr, vcr, true);
724 NotificationType type = static_cast<NotificationType>(static_cast<int>(params->Get("type")));
725 String author = params->Get("author");
726 String text = params->Get("text");
728 Notification::Ptr notification = Notification::GetByName(params->Get("notification"));
733 User::Ptr user = User::GetByName(params->Get("user"));
738 String command = params->Get("command");
740 Checkable::OnNotificationSentToUser(notification, checkable, user, type, cr, author, text, command, origin);
745 void ClusterEvents::NotificationSentToAllUsersHandler(const Notification::Ptr& notification, const Checkable::Ptr& checkable, const std::set<User::Ptr>& users,
746 NotificationType notificationType, const CheckResult::Ptr& cr, const String& author, const String& commentText, const MessageOrigin::Ptr& origin)
748 ApiListener::Ptr listener = ApiListener::GetInstance();
754 Service::Ptr service;
755 tie(host, service) = GetHostService(checkable);
757 Dictionary::Ptr params = new Dictionary();
758 params->Set("host", host->GetName());
760 params->Set("service", service->GetShortName());
761 params->Set("notification", notification->GetName());
764 for (const User::Ptr& user : users) {
765 ausers.push_back(user->GetName());
767 params->Set("users", new Array(std::move(ausers)));
769 params->Set("type", notificationType);
770 params->Set("cr", Serialize(cr));
771 params->Set("author", author);
772 params->Set("text", commentText);
774 params->Set("last_notification", notification->GetLastNotification());
775 params->Set("next_notification", notification->GetNextNotification());
776 params->Set("notification_number", notification->GetNotificationNumber());
777 params->Set("last_problem_notification", notification->GetLastProblemNotification());
778 params->Set("no_more_notifications", notification->GetNoMoreNotifications());
780 Dictionary::Ptr message = new Dictionary();
781 message->Set("jsonrpc", "2.0");
782 message->Set("method", "event::NotificationSentToAllUsers");
783 message->Set("params", params);
785 listener->RelayMessage(origin, nullptr, message, true);
788 Value ClusterEvents::NotificationSentToAllUsersAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params)
790 Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint();
793 Log(LogNotice, "ClusterEvents")
794 << "Discarding 'sent notification to all users' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
798 Host::Ptr host = Host::GetByName(params->Get("host"));
803 Checkable::Ptr checkable;
805 if (params->Contains("service"))
806 checkable = host->GetServiceByShortName(params->Get("service"));
813 if (origin->FromZone && origin->FromZone != Zone::GetLocalZone()) {
814 Log(LogNotice, "ClusterEvents")
815 << "Discarding 'sent notification to all users' message for checkable '" << checkable->GetName()
816 << "' from '" << origin->FromClient->GetIdentity() << "': Unauthorized access.";
823 if (params->Contains("cr")) {
824 cr = new CheckResult();
825 Dictionary::Ptr vcr = params->Get("cr");
827 if (vcr && vcr->Contains("performance_data")) {
828 vperf = vcr->Get("performance_data");
831 vcr->Remove("performance_data");
833 Deserialize(cr, vcr, true);
837 NotificationType type = static_cast<NotificationType>(static_cast<int>(params->Get("type")));
838 String author = params->Get("author");
839 String text = params->Get("text");
841 Notification::Ptr notification = Notification::GetByName(params->Get("notification"));
846 Array::Ptr ausers = params->Get("users");
851 std::set<User::Ptr> users;
854 ObjectLock olock(ausers);
855 for (const String& auser : ausers) {
856 User::Ptr user = User::GetByName(auser);
865 notification->SetLastNotification(params->Get("last_notification"));
866 notification->SetNextNotification(params->Get("next_notification"));
867 notification->SetNotificationNumber(params->Get("notification_number"));
868 notification->SetLastProblemNotification(params->Get("last_problem_notification"));
869 notification->SetNoMoreNotifications(params->Get("no_more_notifications"));
871 ArrayData notifiedProblemUsers;
872 for (const User::Ptr& user : users) {
873 notifiedProblemUsers.push_back(user->GetName());
876 notification->SetNotifiedProblemUsers(new Array(std::move(notifiedProblemUsers)));
878 Checkable::OnNotificationSentToAllUsers(notification, checkable, users, type, cr, author, text, origin);