From f2474e2dc6bc69bc80e8ed9d28e1a94ebbdbae85 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 19 Feb 2020 10:58:42 +0100 Subject: [PATCH 1/6] Revert "Fix license headers" This reverts commit 48b3d25ce2ea9c6b48115f4bed2f9ac90a748c70. --- lib/icinga/notificationresult.cpp | 19 ++++++++++++++++++- lib/icinga/notificationresult.hpp | 19 ++++++++++++++++++- lib/icinga/notificationresult.ti | 19 ++++++++++++++++++- 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/lib/icinga/notificationresult.cpp b/lib/icinga/notificationresult.cpp index d57ad4bb0..699270e01 100644 --- a/lib/icinga/notificationresult.cpp +++ b/lib/icinga/notificationresult.cpp @@ -1,4 +1,21 @@ -/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ +/****************************************************************************** + * Icinga 2 * + * Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/) * + * * + * 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. * + ******************************************************************************/ #include "icinga/notificationresult.hpp" #include "icinga/notificationresult-ti.cpp" diff --git a/lib/icinga/notificationresult.hpp b/lib/icinga/notificationresult.hpp index bb7049f18..af7cfe665 100644 --- a/lib/icinga/notificationresult.hpp +++ b/lib/icinga/notificationresult.hpp @@ -1,4 +1,21 @@ -/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ +/****************************************************************************** + * Icinga 2 * + * Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/) * + * * + * 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. * + ******************************************************************************/ #ifndef NOTIFICATIONRESULT_H #define NOTIFICATIONRESULT_H diff --git a/lib/icinga/notificationresult.ti b/lib/icinga/notificationresult.ti index 0b77c938f..69abebf53 100644 --- a/lib/icinga/notificationresult.ti +++ b/lib/icinga/notificationresult.ti @@ -1,4 +1,21 @@ -/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ +/****************************************************************************** + * Icinga 2 * + * Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/) * + * * + * 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. * + ******************************************************************************/ library icinga; From f43073cc1ca5c490caf47cac361be054333f2546 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 19 Feb 2020 10:58:52 +0100 Subject: [PATCH 2/6] Revert "Add docs for NotificationResult value type" This reverts commit 0611f3e009f548c204edc1460c7391541fbb0eb6. --- doc/08-advanced-topics.md | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/doc/08-advanced-topics.md b/doc/08-advanced-topics.md index fe427abfb..411531304 100644 --- a/doc/08-advanced-topics.md +++ b/doc/08-advanced-topics.md @@ -1190,16 +1190,3 @@ Icinga 2 parses performance data strings returned by check plugins and makes the warn | Value | Warning threshold value. min | Value | Minimum value returned by the check. max | Value | Maximum value returned by the check. - -### NotificationResult - - Name | Type | Description - --------------------------|-----------------------|---------------------------------- - exit\_status | Number | The exit status returned by the check execution. - output | String | The notification command output. - execution\_endpoint | String | Name of the node executing the check. - command | Value | Array of command with shell-escaped arguments or command line string. - execution\_start | Timestamp | Check execution start time (as a UNIX timestamp). - execution\_end | Timestamp | Check execution end time (as a UNIX timestamp). - active | Boolean | Whether the result is from an active or passive check. - From e79e3507401cc7cbdaeb187f482f05f626e8ee21 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 19 Feb 2020 10:59:00 +0100 Subject: [PATCH 3/6] Revert "Make NotificationResult available for events: Cluster and Features" This reverts commit 566e59bbfa385ec1a023c32a1feb895791950032. --- lib/compat/compatlogger.cpp | 4 ++-- lib/compat/compatlogger.hpp | 4 ++-- lib/db_ido/dbevents.cpp | 4 ++-- lib/db_ido/dbevents.hpp | 4 ++-- lib/icinga/checkable-notification.cpp | 4 ++-- lib/icinga/checkable.hpp | 4 ++-- lib/icinga/clusterevents.cpp | 13 ++----------- lib/icinga/clusterevents.hpp | 3 +-- lib/icinga/notification.cpp | 2 +- lib/perfdata/gelfwriter.cpp | 8 ++++---- lib/perfdata/gelfwriter.hpp | 4 ++-- 11 files changed, 22 insertions(+), 32 deletions(-) diff --git a/lib/compat/compatlogger.cpp b/lib/compat/compatlogger.cpp index 75e94dc95..2e44f7727 100644 --- a/lib/compat/compatlogger.cpp +++ b/lib/compat/compatlogger.cpp @@ -50,7 +50,7 @@ void CompatLogger::Start(bool runtimeCreated) << "This feature is DEPRECATED and will be removed in future releases. Check the roadmap at https://github.com/Icinga/icinga2/milestones"; Checkable::OnNewCheckResult.connect(std::bind(&CompatLogger::CheckResultHandler, this, _1, _2)); - Checkable::OnNotificationSentToUser.connect(std::bind(&CompatLogger::NotificationSentHandler, this, _1, _2, _3, _4, _5, _6, _7, _8, _9)); + Checkable::OnNotificationSentToUser.connect(std::bind(&CompatLogger::NotificationSentHandler, this, _1, _2, _3, _4, _5, _6, _7, _8)); Downtime::OnDowntimeTriggered.connect(std::bind(&CompatLogger::TriggerDowntimeHandler, this, _1)); Downtime::OnDowntimeRemoved.connect(std::bind(&CompatLogger::RemoveDowntimeHandler, this, _1)); Checkable::OnEventCommandExecuted.connect(std::bind(&CompatLogger::EventCommandHandler, this, _1)); @@ -230,7 +230,7 @@ void CompatLogger::RemoveDowntimeHandler(const Downtime::Ptr& downtime) * @threadsafety Always. */ void CompatLogger::NotificationSentHandler(const Notification::Ptr& notification, const Checkable::Ptr& checkable, - const User::Ptr& user, NotificationType notification_type, const CheckResult::Ptr& cr, const NotificationResult::Ptr& nr, + const User::Ptr& user, NotificationType notification_type, CheckResult::Ptr const& cr, const String& author, const String& comment_text, const String& command_name) { Host::Ptr host; diff --git a/lib/compat/compatlogger.hpp b/lib/compat/compatlogger.hpp index 748bb90a9..9fb0b2978 100644 --- a/lib/compat/compatlogger.hpp +++ b/lib/compat/compatlogger.hpp @@ -36,8 +36,8 @@ private: void CheckResultHandler(const Checkable::Ptr& service, const CheckResult::Ptr& cr); void NotificationSentHandler(const Notification::Ptr& notification, const Checkable::Ptr& service, - const User::Ptr& user, NotificationType notification_type, const CheckResult::Ptr& cr, - const NotificationResult::Ptr& nr, const String& author, const String& comment_text, const String& command_name); + const User::Ptr& user, NotificationType notification_type, CheckResult::Ptr const& cr, + const String& author, const String& comment_text, const String& command_name); void FlappingChangedHandler(const Checkable::Ptr& checkable); void EnableFlappingChangedHandler(const Checkable::Ptr& checkable); void TriggerDowntimeHandler(const Downtime::Ptr& downtime); diff --git a/lib/db_ido/dbevents.cpp b/lib/db_ido/dbevents.cpp index 68bef4f8a..04b9b1b49 100644 --- a/lib/db_ido/dbevents.cpp +++ b/lib/db_ido/dbevents.cpp @@ -56,7 +56,7 @@ void DbEvents::StaticInitialize() Checkable::OnStateChange.connect(std::bind(&DbEvents::AddStateChangeHistory, _1, _2, _3)); Checkable::OnNewCheckResult.connect(std::bind(&DbEvents::AddCheckResultLogHistory, _1, _2)); - Checkable::OnNotificationSentToUser.connect(std::bind(&DbEvents::AddNotificationSentLogHistory, _1, _2, _3, _4, _5, _6, _7, _8)); + Checkable::OnNotificationSentToUser.connect(std::bind(&DbEvents::AddNotificationSentLogHistory, _1, _2, _3, _4, _5, _6, _7)); Checkable::OnFlappingChanged.connect(std::bind(&DbEvents::AddFlappingChangedLogHistory, _1)); Checkable::OnEnableFlappingChanged.connect(std::bind(&DbEvents::AddEnableFlappingChangedLogHistory, _1)); Downtime::OnDowntimeTriggered.connect(std::bind(&DbEvents::AddTriggerDowntimeLogHistory, _1)); @@ -1061,7 +1061,7 @@ void DbEvents::AddRemoveDowntimeLogHistory(const Downtime::Ptr& downtime) } void DbEvents::AddNotificationSentLogHistory(const Notification::Ptr& notification, const Checkable::Ptr& checkable, const User::Ptr& user, - NotificationType notification_type, const CheckResult::Ptr& cr, const NotificationResult::Ptr& nr, + NotificationType notification_type, const CheckResult::Ptr& cr, const String& author, const String& comment_text) { CheckCommand::Ptr commandObj = checkable->GetCheckCommand(); diff --git a/lib/db_ido/dbevents.hpp b/lib/db_ido/dbevents.hpp index 6e620ddfa..858f3b3da 100644 --- a/lib/db_ido/dbevents.hpp +++ b/lib/db_ido/dbevents.hpp @@ -94,8 +94,8 @@ public: static void AddTriggerDowntimeLogHistory(const Downtime::Ptr& downtime); static void AddRemoveDowntimeLogHistory(const Downtime::Ptr& downtime); static void AddNotificationSentLogHistory(const Notification::Ptr& notification, const Checkable::Ptr& checkable, - const User::Ptr& user, NotificationType notification_type, const CheckResult::Ptr& cr, const NotificationResult::Ptr& nr, - const String& author, const String& comment_text); + const User::Ptr& user, NotificationType notification_type, const CheckResult::Ptr& cr, const String& author, + const String& comment_text); static void AddFlappingChangedLogHistory(const Checkable::Ptr& checkable); static void AddEnableFlappingChangedLogHistory(const Checkable::Ptr& checkable); diff --git a/lib/icinga/checkable-notification.cpp b/lib/icinga/checkable-notification.cpp index 9aac0e7a4..43b4589fa 100644 --- a/lib/icinga/checkable-notification.cpp +++ b/lib/icinga/checkable-notification.cpp @@ -18,8 +18,8 @@ boost::signals2::signal Checkable::OnNotificationSentToAllUsers; boost::signals2::signal Checkable::OnNotificationSentToUser; + const NotificationType&, const CheckResult::Ptr&, const String&, const String&, const String&, + const MessageOrigin::Ptr&)> Checkable::OnNotificationSentToUser; void Checkable::ResetNotificationNumbers() { diff --git a/lib/icinga/checkable.hpp b/lib/icinga/checkable.hpp index caddd63f4..99d255ee2 100644 --- a/lib/icinga/checkable.hpp +++ b/lib/icinga/checkable.hpp @@ -122,8 +122,8 @@ public: static boost::signals2::signal OnNotificationsRequested; static boost::signals2::signal OnNotificationSentToUser; + const NotificationType&, const CheckResult::Ptr&, const String&, const String&, const String&, + const MessageOrigin::Ptr&)> OnNotificationSentToUser; static boost::signals2::signal&, const NotificationType&, const CheckResult::Ptr&, const String&, const String&, const MessageOrigin::Ptr&)> OnNotificationSentToAllUsers; diff --git a/lib/icinga/clusterevents.cpp b/lib/icinga/clusterevents.cpp index 313adb1eb..1651dde71 100644 --- a/lib/icinga/clusterevents.cpp +++ b/lib/icinga/clusterevents.cpp @@ -688,7 +688,7 @@ Value ClusterEvents::SendNotificationsAPIHandler(const MessageOrigin::Ptr& origi } void ClusterEvents::NotificationSentUserHandler(const Notification::Ptr& notification, const Checkable::Ptr& checkable, const User::Ptr& user, - NotificationType notificationType, const CheckResult::Ptr& cr, const NotificationResult::Ptr& nr, const String& author, const String& commentText, const String& command, + NotificationType notificationType, const CheckResult::Ptr& cr, const String& author, const String& commentText, const String& command, const MessageOrigin::Ptr& origin) { ApiListener::Ptr listener = ApiListener::GetInstance(); @@ -708,7 +708,6 @@ void ClusterEvents::NotificationSentUserHandler(const Notification::Ptr& notific params->Set("user", user->GetName()); params->Set("type", notificationType); params->Set("cr", Serialize(cr)); - params->Set("nr", Serialize(nr)); params->Set("author", author); params->Set("text", commentText); params->Set("command", command); @@ -770,14 +769,6 @@ Value ClusterEvents::NotificationSentUserAPIHandler(const MessageOrigin::Ptr& or } } - NotificationResult::Ptr nr; - if (params->Contains("nr")) { - nr = new NotificationResult(); - Dictionary::Ptr vnr = params->Get("nr"); - - Deserialize(nr, vnr, true); - } - NotificationType type = static_cast(static_cast(params->Get("type"))); String author = params->Get("author"); String text = params->Get("text"); @@ -794,7 +785,7 @@ Value ClusterEvents::NotificationSentUserAPIHandler(const MessageOrigin::Ptr& or String command = params->Get("command"); - Checkable::OnNotificationSentToUser(notification, checkable, user, type, cr, nr, author, text, command, origin); + Checkable::OnNotificationSentToUser(notification, checkable, user, type, cr, author, text, command, origin); return Empty; } diff --git a/lib/icinga/clusterevents.hpp b/lib/icinga/clusterevents.hpp index 8dc6f48b9..12fc8228d 100644 --- a/lib/icinga/clusterevents.hpp +++ b/lib/icinga/clusterevents.hpp @@ -54,8 +54,7 @@ public: static Value SendNotificationsAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params); static void NotificationSentUserHandler(const Notification::Ptr& notification, const Checkable::Ptr& checkable, const User::Ptr& user, - NotificationType notificationType, const CheckResult::Ptr& cr, const NotificationResult::Ptr& nr, - const String& author, const String& commentText, const String& command, const MessageOrigin::Ptr& origin); + NotificationType notificationType, const CheckResult::Ptr& cr, const String& author, const String& commentText, const String& command, const MessageOrigin::Ptr& origin); static Value NotificationSentUserAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params); static void NotificationSentToAllUsersHandler(const Notification::Ptr& notification, const Checkable::Ptr& checkable, const std::set& users, diff --git a/lib/icinga/notification.cpp b/lib/icinga/notification.cpp index df509c376..23deed590 100644 --- a/lib/icinga/notification.cpp +++ b/lib/icinga/notification.cpp @@ -516,7 +516,7 @@ void Notification::ExecuteNotificationHelper(NotificationType type, const User:: command->Execute(this, user, cr, nr, type, author, text); /* required by compatlogger */ - Checkable::OnNotificationSentToUser(this, GetCheckable(), user, type, cr, nr, author, text, command->GetName(), nullptr); + Checkable::OnNotificationSentToUser(this, GetCheckable(), user, type, cr, author, text, command->GetName(), nullptr); Log(LogInformation, "Notification") << "Completed sending '" << NotificationTypeToString(type) diff --git a/lib/perfdata/gelfwriter.cpp b/lib/perfdata/gelfwriter.cpp index c778a3813..3f5fc4403 100644 --- a/lib/perfdata/gelfwriter.cpp +++ b/lib/perfdata/gelfwriter.cpp @@ -91,7 +91,7 @@ void GelfWriter::Resume() /* Register event handlers. */ Checkable::OnNewCheckResult.connect(std::bind(&GelfWriter::CheckResultHandler, this, _1, _2)); - Checkable::OnNotificationSentToUser.connect(std::bind(&GelfWriter::NotificationToUserHandler, this, _1, _2, _3, _4, _5, _6, _7, _8, _9)); + Checkable::OnNotificationSentToUser.connect(std::bind(&GelfWriter::NotificationToUserHandler, this, _1, _2, _3, _4, _5, _6, _7, _8)); Checkable::OnStateChange.connect(std::bind(&GelfWriter::StateChangeHandler, this, _1, _2, _3)); } @@ -346,18 +346,18 @@ void GelfWriter::CheckResultHandlerInternal(const Checkable::Ptr& checkable, con } void GelfWriter::NotificationToUserHandler(const Notification::Ptr& notification, const Checkable::Ptr& checkable, - const User::Ptr& user, NotificationType notificationType, const CheckResult::Ptr& cr, const NotificationResult::Ptr& nr, + const User::Ptr& user, NotificationType notificationType, CheckResult::Ptr const& cr, const String& author, const String& commentText, const String& commandName) { if (IsPaused()) return; m_WorkQueue.Enqueue(std::bind(&GelfWriter::NotificationToUserHandlerInternal, this, - notification, checkable, user, notificationType, cr, nr, author, commentText, commandName)); + notification, checkable, user, notificationType, cr, author, commentText, commandName)); } void GelfWriter::NotificationToUserHandlerInternal(const Notification::Ptr& notification, const Checkable::Ptr& checkable, - const User::Ptr& user, NotificationType notificationType, const CheckResult::Ptr& cr, const NotificationResult::Ptr& nr, + const User::Ptr& user, NotificationType notificationType, CheckResult::Ptr const& cr, const String& author, const String& commentText, const String& commandName) { AssertOnWorkQueue(); diff --git a/lib/perfdata/gelfwriter.hpp b/lib/perfdata/gelfwriter.hpp index f729c0c5c..1fee2f0e7 100644 --- a/lib/perfdata/gelfwriter.hpp +++ b/lib/perfdata/gelfwriter.hpp @@ -41,10 +41,10 @@ private: void CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr); void CheckResultHandlerInternal(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr); void NotificationToUserHandler(const Notification::Ptr& notification, const Checkable::Ptr& checkable, - const User::Ptr& user, NotificationType notificationType, const CheckResult::Ptr& cr, const NotificationResult::Ptr& nr, + const User::Ptr& user, NotificationType notificationType, const CheckResult::Ptr& cr, const String& author, const String& commentText, const String& commandName); void NotificationToUserHandlerInternal(const Notification::Ptr& notification, const Checkable::Ptr& checkable, - const User::Ptr& user, NotificationType notification_type, const CheckResult::Ptr& cr, const NotificationResult::Ptr& nr, + const User::Ptr& user, NotificationType notification_type, const CheckResult::Ptr& cr, const String& author, const String& comment_text, const String& command_name); void StateChangeHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type); void StateChangeHandlerInternal(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type); From 685ac2f6d721103ac23c317abc60469491f0e800 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 19 Feb 2020 10:59:07 +0100 Subject: [PATCH 4/6] Revert "Implement last_notification_result handling for Notification objects" This reverts commit 1706b297a50aceafdbbfe8ed8d46c8d01c114464. --- lib/icinga/notification.cpp | 29 ++------------------------ lib/icinga/notification.hpp | 2 +- lib/icinga/notification.ti | 4 ---- lib/icinga/notificationcommand.cpp | 7 +++---- lib/icinga/notificationcommand.hpp | 4 ++-- lib/icinga/notificationresult.cpp | 1 + lib/methods/pluginnotificationtask.cpp | 26 +++++++---------------- lib/methods/pluginnotificationtask.hpp | 5 ++--- 8 files changed, 18 insertions(+), 60 deletions(-) diff --git a/lib/icinga/notification.cpp b/lib/icinga/notification.cpp index 23deed590..dff07699e 100644 --- a/lib/icinga/notification.cpp +++ b/lib/icinga/notification.cpp @@ -509,14 +509,10 @@ void Notification::ExecuteNotificationHelper(NotificationType type, const User:: String commandName = command->GetName(); try { - NotificationResult::Ptr nr = new NotificationResult(); - - nr->SetExecutionStart(Utility::GetTime()); - - command->Execute(this, user, cr, nr, type, author, text); + command->Execute(this, user, cr, type, author, text); /* required by compatlogger */ - Checkable::OnNotificationSentToUser(this, GetCheckable(), user, type, cr, author, text, command->GetName(), nullptr); + Service::OnNotificationSentToUser(this, GetCheckable(), user, type, cr, author, text, commandName, nullptr); Log(LogInformation, "Notification") << "Completed sending '" << NotificationTypeToString(type) @@ -537,27 +533,6 @@ void Notification::ProcessNotificationResult(const NotificationResult::Ptr& nr, if (!nr) return; - double now = Utility::GetTime(); - - if (nr->GetExecutionStart() == 0) - nr->SetExecutionStart(now); - - if (nr->GetExecutionEnd() == 0) - nr->SetExecutionEnd(now); - - /* Determine the execution endpoint from a locally executed check. */ - if (!origin || origin->IsLocal()) - nr->SetExecutionEndpoint(IcingaApplication::GetInstance()->GetNodeName()); - - if (!IsActive()) - return; - - { - ObjectLock olock(this); - - SetLastNotificationResult(nr); - } - /* Notify cluster, API and feature events. */ OnNewNotificationResult(this, nr, origin); } diff --git a/lib/icinga/notification.hpp b/lib/icinga/notification.hpp index 5fcb6fd2a..d9f6ff960 100644 --- a/lib/icinga/notification.hpp +++ b/lib/icinga/notification.hpp @@ -83,7 +83,7 @@ public: Endpoint::Ptr GetCommandEndpoint() const; - void ProcessNotificationResult(const NotificationResult::Ptr& nr, const MessageOrigin::Ptr& origin = nullptr); + void ProcessNotificationResult(const NotificationResult::Ptr& nr, const MessageOrigin::Ptr& origin); // Logging, etc. static String NotificationTypeToString(NotificationType type); diff --git a/lib/icinga/notification.ti b/lib/icinga/notification.ti index 0212a144a..a283bbb84 100644 --- a/lib/icinga/notification.ti +++ b/lib/icinga/notification.ti @@ -1,8 +1,6 @@ /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ #include "icinga/customvarobject.hpp" -#include "icinga/notificationresult.hpp" -#include "base/array.hpp" #impl_include "icinga/notificationcommand.hpp" #impl_include "icinga/service.hpp" @@ -18,7 +16,6 @@ public: virtual String MakeName(const String& shortName, const Object::Ptr& context) const; virtual Dictionary::Ptr ParseName(const String& name) const; }; - }}} class Notification : CustomVarObject < NotificationNameComposer @@ -88,7 +85,6 @@ class Notification : CustomVarObject < NotificationNameComposer [state] Timestamp next_notification; [state] int notification_number; [state] Timestamp last_problem_notification; - [state] NotificationResult::Ptr last_notification_result; [config, navigation] name(Endpoint) command_endpoint (CommandEndpointRaw) { navigate {{{ diff --git a/lib/icinga/notificationcommand.cpp b/lib/icinga/notificationcommand.cpp index dc9edb4f3..8ae3e82a5 100644 --- a/lib/icinga/notificationcommand.cpp +++ b/lib/icinga/notificationcommand.cpp @@ -8,15 +8,14 @@ using namespace icinga; REGISTER_TYPE(NotificationCommand); Dictionary::Ptr NotificationCommand::Execute(const Notification::Ptr& notification, - const User::Ptr& user, const CheckResult::Ptr& cr, const NotificationResult::Ptr& nr, - const NotificationType& type, const String& author, const String& comment, - const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) + const User::Ptr& user, const CheckResult::Ptr& cr, const NotificationType& type, + const String& author, const String& comment, const Dictionary::Ptr& resolvedMacros, + bool useResolvedMacros) { return GetExecute()->Invoke({ notification, user, cr, - nr, type, author, comment, diff --git a/lib/icinga/notificationcommand.hpp b/lib/icinga/notificationcommand.hpp index 0c76a0142..210c91e86 100644 --- a/lib/icinga/notificationcommand.hpp +++ b/lib/icinga/notificationcommand.hpp @@ -23,8 +23,8 @@ public: DECLARE_OBJECTNAME(NotificationCommand); virtual Dictionary::Ptr Execute(const intrusive_ptr& notification, - const User::Ptr& user, const CheckResult::Ptr& cr, const NotificationResult::Ptr& nr, - const NotificationType& type, const String& author, const String& comment, + const User::Ptr& user, const CheckResult::Ptr& cr, const NotificationType& type, + const String& author, const String& comment, const Dictionary::Ptr& resolvedMacros = nullptr, bool useResolvedMacros = false); }; diff --git a/lib/icinga/notificationresult.cpp b/lib/icinga/notificationresult.cpp index 699270e01..30b466075 100644 --- a/lib/icinga/notificationresult.cpp +++ b/lib/icinga/notificationresult.cpp @@ -19,6 +19,7 @@ #include "icinga/notificationresult.hpp" #include "icinga/notificationresult-ti.cpp" +#include "base/scriptglobal.hpp" using namespace icinga; diff --git a/lib/methods/pluginnotificationtask.cpp b/lib/methods/pluginnotificationtask.cpp index ab84e726a..0fcc95dc2 100644 --- a/lib/methods/pluginnotificationtask.cpp +++ b/lib/methods/pluginnotificationtask.cpp @@ -15,12 +15,12 @@ using namespace icinga; -REGISTER_FUNCTION_NONCONST(Internal, PluginNotification, &PluginNotificationTask::ScriptFunc, "notification:user:cr:nr:itype:author:comment:resolvedMacros:useResolvedMacros"); +REGISTER_FUNCTION_NONCONST(Internal, PluginNotification, &PluginNotificationTask::ScriptFunc, "notification:user:cr:itype:author:comment:resolvedMacros:useResolvedMacros"); void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification, - const User::Ptr& user, const CheckResult::Ptr& cr, const NotificationResult::Ptr& nr, - int itype, const String& author, const String& comment, - const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) + const User::Ptr& user, const CheckResult::Ptr& cr, int itype, + const String& author, const String& comment, const Dictionary::Ptr& resolvedMacros, + bool useResolvedMacros) { REQUIRE_NOT_NULL(notification); REQUIRE_NOT_NULL(user); @@ -55,28 +55,16 @@ void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification, PluginUtility::ExecuteCommand(commandObj, checkable, cr, resolvers, resolvedMacros, useResolvedMacros, timeout, - std::bind(&PluginNotificationTask::ProcessFinishedHandler, checkable, notification, nr, _1, _2)); + std::bind(&PluginNotificationTask::ProcessFinishedHandler, checkable, _1, _2)); } -void PluginNotificationTask::ProcessFinishedHandler(const Checkable::Ptr& checkable, - const Notification::Ptr& notification, const NotificationResult::Ptr& nr, const Value& commandLine, const ProcessResult& pr) +void PluginNotificationTask::ProcessFinishedHandler(const Checkable::Ptr& checkable, const Value& commandLine, const ProcessResult& pr) { if (pr.ExitStatus != 0) { Process::Arguments parguments = Process::PrepareCommand(commandLine); Log(LogWarning, "PluginNotificationTask") - << "Notification command for checkable '" << checkable->GetName() - << "' and notification '" << notification->GetName() << "' (PID: " << pr.PID + << "Notification command for object '" << checkable->GetName() << "' (PID: " << pr.PID << ", arguments: " << Process::PrettyPrintArguments(parguments) << ") terminated with exit code " << pr.ExitStatus << ", output: " << pr.Output; } - - String output = pr.Output.Trim(); - - nr->SetCommand(commandLine); - nr->SetOutput(output); - nr->SetExitStatus(pr.ExitStatus); - nr->SetExecutionStart(pr.ExecutionStart); - nr->SetExecutionEnd(pr.ExecutionEnd); - - notification->ProcessNotificationResult(nr); } diff --git a/lib/methods/pluginnotificationtask.hpp b/lib/methods/pluginnotificationtask.hpp index 6a741b73b..66d653924 100644 --- a/lib/methods/pluginnotificationtask.hpp +++ b/lib/methods/pluginnotificationtask.hpp @@ -20,15 +20,14 @@ class PluginNotificationTask { public: static void ScriptFunc(const Notification::Ptr& notification, - const User::Ptr& user, const CheckResult::Ptr& cr, const NotificationResult::Ptr& nr, - int itype, const String& author, const String& comment, + const User::Ptr& user, const CheckResult::Ptr& cr, int itype, + const String& author, const String& comment, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros); private: PluginNotificationTask(); static void ProcessFinishedHandler(const Checkable::Ptr& checkable, - const Notification::Ptr& notification, const NotificationResult::Ptr& nr, const Value& commandLine, const ProcessResult& pr); }; From 1183010b45b86ec3a893abd6f9cb4c03bb9cc850 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 19 Feb 2020 11:00:47 +0100 Subject: [PATCH 5/6] Revert "Add OnNewNotificationResult signal and ProcessNotificationResult handler" This reverts commit ac483f2a8a07e4962068408d18b10a17204b6454. --- lib/icinga/notification.cpp | 10 ---------- lib/icinga/notification.hpp | 4 ---- 2 files changed, 14 deletions(-) diff --git a/lib/icinga/notification.cpp b/lib/icinga/notification.cpp index dff07699e..9c2ae7ec8 100644 --- a/lib/icinga/notification.cpp +++ b/lib/icinga/notification.cpp @@ -23,7 +23,6 @@ std::map Notification::m_StateFilterMap; std::map Notification::m_TypeFilterMap; boost::signals2::signal Notification::OnNextNotificationChanged; -boost::signals2::signal Notification::OnNewNotificationResult; String NotificationNameComposer::MakeName(const String& shortName, const Object::Ptr& context) const { @@ -528,15 +527,6 @@ void Notification::ExecuteNotificationHelper(NotificationType type, const User:: } } -void Notification::ProcessNotificationResult(const NotificationResult::Ptr& nr, const MessageOrigin::Ptr& origin) -{ - if (!nr) - return; - - /* Notify cluster, API and feature events. */ - OnNewNotificationResult(this, nr, origin); -} - int icinga::ServiceStateToFilter(ServiceState state) { switch (state) { diff --git a/lib/icinga/notification.hpp b/lib/icinga/notification.hpp index d9f6ff960..2922308c8 100644 --- a/lib/icinga/notification.hpp +++ b/lib/icinga/notification.hpp @@ -10,7 +10,6 @@ #include "icinga/usergroup.hpp" #include "icinga/timeperiod.hpp" #include "icinga/checkresult.hpp" -#include "icinga/notificationresult.hpp" #include "remote/endpoint.hpp" #include "remote/messageorigin.hpp" #include "base/array.hpp" @@ -83,8 +82,6 @@ public: Endpoint::Ptr GetCommandEndpoint() const; - void ProcessNotificationResult(const NotificationResult::Ptr& nr, const MessageOrigin::Ptr& origin); - // Logging, etc. static String NotificationTypeToString(NotificationType type); // Compat, used for notifications, etc. @@ -95,7 +92,6 @@ public: static String NotificationHostStateToString(HostState state); static boost::signals2::signal OnNextNotificationChanged; - static boost::signals2::signal OnNewNotificationResult; void Validate(int types, const ValidationUtils& utils) override; From 18c1f1c4e517cafa9f729d10c3e03b8a95f1dce8 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 19 Feb 2020 11:00:56 +0100 Subject: [PATCH 6/6] Revert "Add NotificationResult class" This reverts commit 9621fd2e4bc337befb46a4c885d80ccfce95f5ab. --- lib/icinga/CMakeLists.txt | 2 -- lib/icinga/notificationresult.cpp | 31 ---------------------- lib/icinga/notificationresult.hpp | 44 ------------------------------- lib/icinga/notificationresult.ti | 41 ---------------------------- 4 files changed, 118 deletions(-) delete mode 100644 lib/icinga/notificationresult.cpp delete mode 100644 lib/icinga/notificationresult.hpp delete mode 100644 lib/icinga/notificationresult.ti diff --git a/lib/icinga/CMakeLists.txt b/lib/icinga/CMakeLists.txt index 00951609b..7079d84e5 100644 --- a/lib/icinga/CMakeLists.txt +++ b/lib/icinga/CMakeLists.txt @@ -13,7 +13,6 @@ mkclass_target(host.ti host-ti.cpp host-ti.hpp) mkclass_target(icingaapplication.ti icingaapplication-ti.cpp icingaapplication-ti.hpp) mkclass_target(customvarobject.ti customvarobject-ti.cpp customvarobject-ti.hpp) mkclass_target(notificationcommand.ti notificationcommand-ti.cpp notificationcommand-ti.hpp) -mkclass_target(notificationresult.ti notificationresult-ti.cpp notificationresult-ti.hpp) mkclass_target(notification.ti notification-ti.cpp notification-ti.hpp) mkclass_target(scheduleddowntime.ti scheduleddowntime-ti.cpp scheduleddowntime-ti.hpp) mkclass_target(servicegroup.ti servicegroup-ti.cpp servicegroup-ti.hpp) @@ -52,7 +51,6 @@ set(icinga_SOURCES macroresolver.hpp notification.cpp notification.hpp notification-ti.hpp notification-apply.cpp notificationcommand.cpp notificationcommand.hpp notificationcommand-ti.hpp - notificationresult.cpp notificationresult.hpp notificationresult-ti.hpp objectutils.cpp objectutils.hpp pluginutility.cpp pluginutility.hpp scheduleddowntime.cpp scheduleddowntime.hpp scheduleddowntime-ti.hpp scheduleddowntime-apply.cpp diff --git a/lib/icinga/notificationresult.cpp b/lib/icinga/notificationresult.cpp deleted file mode 100644 index 30b466075..000000000 --- a/lib/icinga/notificationresult.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/****************************************************************************** - * Icinga 2 * - * Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/) * - * * - * 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. * - ******************************************************************************/ - -#include "icinga/notificationresult.hpp" -#include "icinga/notificationresult-ti.cpp" -#include "base/scriptglobal.hpp" - -using namespace icinga; - -REGISTER_TYPE(NotificationResult); - -double NotificationResult::CalculateExecutionTime() const -{ - return GetExecutionEnd() - GetExecutionStart(); -} diff --git a/lib/icinga/notificationresult.hpp b/lib/icinga/notificationresult.hpp deleted file mode 100644 index af7cfe665..000000000 --- a/lib/icinga/notificationresult.hpp +++ /dev/null @@ -1,44 +0,0 @@ -/****************************************************************************** - * Icinga 2 * - * Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/) * - * * - * 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. * - ******************************************************************************/ - -#ifndef NOTIFICATIONRESULT_H -#define NOTIFICATIONRESULT_H - -#include "icinga/i2-icinga.hpp" -#include "icinga/notificationresult-ti.hpp" - -namespace icinga -{ - -/** - * A notification result. - * - * @ingroup icinga - */ -class NotificationResult final : public ObjectImpl -{ -public: - DECLARE_OBJECT(NotificationResult); - - double CalculateExecutionTime() const; -}; - -} - -#endif /* NOTIFICATIONRESULT_H */ diff --git a/lib/icinga/notificationresult.ti b/lib/icinga/notificationresult.ti deleted file mode 100644 index 69abebf53..000000000 --- a/lib/icinga/notificationresult.ti +++ /dev/null @@ -1,41 +0,0 @@ -/****************************************************************************** - * Icinga 2 * - * Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/) * - * * - * 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. * - ******************************************************************************/ - -library icinga; - -namespace icinga -{ - -class NotificationResult -{ - [state] Timestamp execution_start; - [state] Timestamp execution_end; - - [state] Value command; - [state] int exit_status; - [state] String output; - - [state] bool active { - default {{{ return true; }}} - }; - - [state] String execution_endpoint; -}; - -}