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("persistent", persistent);
449 params->Set("expiry", expiry);
451 Dictionary::Ptr message = new Dictionary();
452 message->Set("jsonrpc", "2.0");
453 message->Set("method", "event::SetAcknowledgement");
454 message->Set("params", params);
456 listener->RelayMessage(origin, checkable, message, true);
459 Value ClusterEvents::AcknowledgementSetAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params)
461 Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint();
464 Log(LogNotice, "ClusterEvents")
465 << "Discarding 'acknowledgement set' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
469 Host::Ptr host = Host::GetByName(params->Get("host"));
474 Checkable::Ptr checkable;
476 if (params->Contains("service"))
477 checkable = host->GetServiceByShortName(params->Get("service"));
484 if (origin->FromZone && !origin->FromZone->CanAccessObject(checkable)) {
485 Log(LogNotice, "ClusterEvents")
486 << "Discarding 'acknowledgement set' message for checkable '" << checkable->GetName()
487 << "' from '" << origin->FromClient->GetIdentity() << "': Unauthorized access.";
491 checkable->AcknowledgeProblem(params->Get("author"), params->Get("comment"),
492 static_cast<AcknowledgementType>(static_cast<int>(params->Get("acktype"))),
493 params->Get("notify"), params->Get("persistent"), params->Get("expiry"), origin);
498 void ClusterEvents::AcknowledgementClearedHandler(const Checkable::Ptr& checkable, const MessageOrigin::Ptr& origin)
500 ApiListener::Ptr listener = ApiListener::GetInstance();
506 Service::Ptr service;
507 tie(host, service) = GetHostService(checkable);
509 Dictionary::Ptr params = new Dictionary();
510 params->Set("host", host->GetName());
512 params->Set("service", service->GetShortName());
514 Dictionary::Ptr message = new Dictionary();
515 message->Set("jsonrpc", "2.0");
516 message->Set("method", "event::ClearAcknowledgement");
517 message->Set("params", params);
519 listener->RelayMessage(origin, checkable, message, true);
522 Value ClusterEvents::AcknowledgementClearedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params)
524 Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint();
527 Log(LogNotice, "ClusterEvents")
528 << "Discarding 'acknowledgement cleared' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
532 Host::Ptr host = Host::GetByName(params->Get("host"));
537 Checkable::Ptr checkable;
539 if (params->Contains("service"))
540 checkable = host->GetServiceByShortName(params->Get("service"));
547 if (origin->FromZone && !origin->FromZone->CanAccessObject(checkable)) {
548 Log(LogNotice, "ClusterEvents")
549 << "Discarding 'acknowledgement cleared' message for checkable '" << checkable->GetName()
550 << "' from '" << origin->FromClient->GetIdentity() << "': Unauthorized access.";
554 checkable->ClearAcknowledgement(origin);
559 Value ClusterEvents::ExecuteCommandAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params)
561 EnqueueCheck(origin, params);
566 void ClusterEvents::SendNotificationsHandler(const Checkable::Ptr& checkable, NotificationType type,
567 const CheckResult::Ptr& cr, const String& author, const String& text, const MessageOrigin::Ptr& origin)
569 ApiListener::Ptr listener = ApiListener::GetInstance();
574 Dictionary::Ptr message = MakeCheckResultMessage(checkable, cr);
575 message->Set("method", "event::SendNotifications");
577 Dictionary::Ptr params = message->Get("params");
578 params->Set("type", type);
579 params->Set("author", author);
580 params->Set("text", text);
582 listener->RelayMessage(origin, nullptr, message, true);
585 Value ClusterEvents::SendNotificationsAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params)
587 Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint();
590 Log(LogNotice, "ClusterEvents")
591 << "Discarding 'send notification' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
595 Host::Ptr host = Host::GetByName(params->Get("host"));
600 Checkable::Ptr checkable;
602 if (params->Contains("service"))
603 checkable = host->GetServiceByShortName(params->Get("service"));
610 if (origin->FromZone && origin->FromZone != Zone::GetLocalZone()) {
611 Log(LogNotice, "ClusterEvents")
612 << "Discarding 'send custom notification' message for checkable '" << checkable->GetName()
613 << "' from '" << origin->FromClient->GetIdentity() << "': Unauthorized access.";
620 if (params->Contains("cr")) {
621 cr = new CheckResult();
622 Dictionary::Ptr vcr = params->Get("cr");
624 if (vcr && vcr->Contains("performance_data")) {
625 vperf = vcr->Get("performance_data");
628 vcr->Remove("performance_data");
630 Deserialize(cr, vcr, true);
634 NotificationType type = static_cast<NotificationType>(static_cast<int>(params->Get("type")));
635 String author = params->Get("author");
636 String text = params->Get("text");
638 Checkable::OnNotificationsRequested(checkable, type, cr, author, text, origin);
643 void ClusterEvents::NotificationSentUserHandler(const Notification::Ptr& notification, const Checkable::Ptr& checkable, const User::Ptr& user,
644 NotificationType notificationType, const CheckResult::Ptr& cr, const String& author, const String& commentText, const String& command,
645 const MessageOrigin::Ptr& origin)
647 ApiListener::Ptr listener = ApiListener::GetInstance();
653 Service::Ptr service;
654 tie(host, service) = GetHostService(checkable);
656 Dictionary::Ptr params = new Dictionary();
657 params->Set("host", host->GetName());
659 params->Set("service", service->GetShortName());
660 params->Set("notification", notification->GetName());
661 params->Set("user", user->GetName());
662 params->Set("type", notificationType);
663 params->Set("cr", Serialize(cr));
664 params->Set("author", author);
665 params->Set("text", commentText);
666 params->Set("command", command);
668 Dictionary::Ptr message = new Dictionary();
669 message->Set("jsonrpc", "2.0");
670 message->Set("method", "event::NotificationSentUser");
671 message->Set("params", params);
673 listener->RelayMessage(origin, nullptr, message, true);
676 Value ClusterEvents::NotificationSentUserAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params)
678 Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint();
681 Log(LogNotice, "ClusterEvents")
682 << "Discarding 'sent notification to user' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
686 Host::Ptr host = Host::GetByName(params->Get("host"));
691 Checkable::Ptr checkable;
693 if (params->Contains("service"))
694 checkable = host->GetServiceByShortName(params->Get("service"));
701 if (origin->FromZone && origin->FromZone != Zone::GetLocalZone()) {
702 Log(LogNotice, "ClusterEvents")
703 << "Discarding 'send notification to user' message for checkable '" << checkable->GetName()
704 << "' from '" << origin->FromClient->GetIdentity() << "': Unauthorized access.";
711 if (params->Contains("cr")) {
712 cr = new CheckResult();
713 Dictionary::Ptr vcr = params->Get("cr");
715 if (vcr && vcr->Contains("performance_data")) {
716 vperf = vcr->Get("performance_data");
719 vcr->Remove("performance_data");
721 Deserialize(cr, vcr, true);
725 NotificationType type = static_cast<NotificationType>(static_cast<int>(params->Get("type")));
726 String author = params->Get("author");
727 String text = params->Get("text");
729 Notification::Ptr notification = Notification::GetByName(params->Get("notification"));
734 User::Ptr user = User::GetByName(params->Get("user"));
739 String command = params->Get("command");
741 Checkable::OnNotificationSentToUser(notification, checkable, user, type, cr, author, text, command, origin);
746 void ClusterEvents::NotificationSentToAllUsersHandler(const Notification::Ptr& notification, const Checkable::Ptr& checkable, const std::set<User::Ptr>& users,
747 NotificationType notificationType, const CheckResult::Ptr& cr, const String& author, const String& commentText, const MessageOrigin::Ptr& origin)
749 ApiListener::Ptr listener = ApiListener::GetInstance();
755 Service::Ptr service;
756 tie(host, service) = GetHostService(checkable);
758 Dictionary::Ptr params = new Dictionary();
759 params->Set("host", host->GetName());
761 params->Set("service", service->GetShortName());
762 params->Set("notification", notification->GetName());
765 for (const User::Ptr& user : users) {
766 ausers.push_back(user->GetName());
768 params->Set("users", new Array(std::move(ausers)));
770 params->Set("type", notificationType);
771 params->Set("cr", Serialize(cr));
772 params->Set("author", author);
773 params->Set("text", commentText);
775 params->Set("last_notification", notification->GetLastNotification());
776 params->Set("next_notification", notification->GetNextNotification());
777 params->Set("notification_number", notification->GetNotificationNumber());
778 params->Set("last_problem_notification", notification->GetLastProblemNotification());
779 params->Set("no_more_notifications", notification->GetNoMoreNotifications());
781 Dictionary::Ptr message = new Dictionary();
782 message->Set("jsonrpc", "2.0");
783 message->Set("method", "event::NotificationSentToAllUsers");
784 message->Set("params", params);
786 listener->RelayMessage(origin, nullptr, message, true);
789 Value ClusterEvents::NotificationSentToAllUsersAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params)
791 Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint();
794 Log(LogNotice, "ClusterEvents")
795 << "Discarding 'sent notification to all users' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
799 Host::Ptr host = Host::GetByName(params->Get("host"));
804 Checkable::Ptr checkable;
806 if (params->Contains("service"))
807 checkable = host->GetServiceByShortName(params->Get("service"));
814 if (origin->FromZone && origin->FromZone != Zone::GetLocalZone()) {
815 Log(LogNotice, "ClusterEvents")
816 << "Discarding 'sent notification to all users' message for checkable '" << checkable->GetName()
817 << "' from '" << origin->FromClient->GetIdentity() << "': Unauthorized access.";
824 if (params->Contains("cr")) {
825 cr = new CheckResult();
826 Dictionary::Ptr vcr = params->Get("cr");
828 if (vcr && vcr->Contains("performance_data")) {
829 vperf = vcr->Get("performance_data");
832 vcr->Remove("performance_data");
834 Deserialize(cr, vcr, true);
838 NotificationType type = static_cast<NotificationType>(static_cast<int>(params->Get("type")));
839 String author = params->Get("author");
840 String text = params->Get("text");
842 Notification::Ptr notification = Notification::GetByName(params->Get("notification"));
847 Array::Ptr ausers = params->Get("users");
852 std::set<User::Ptr> users;
855 ObjectLock olock(ausers);
856 for (const String& auser : ausers) {
857 User::Ptr user = User::GetByName(auser);
866 notification->SetLastNotification(params->Get("last_notification"));
867 notification->SetNextNotification(params->Get("next_notification"));
868 notification->SetNotificationNumber(params->Get("notification_number"));
869 notification->SetLastProblemNotification(params->Get("last_problem_notification"));
870 notification->SetNoMoreNotifications(params->Get("no_more_notifications"));
872 ArrayData notifiedProblemUsers;
873 for (const User::Ptr& user : users) {
874 notifiedProblemUsers.push_back(user->GetName());
877 notification->SetNotifiedProblemUsers(new Array(std::move(notifiedProblemUsers)));
879 Checkable::OnNotificationSentToAllUsers(notification, checkable, users, type, cr, author, text, origin);