]> granicus.if.org Git - icinga2/commitdiff
Fix notify flag is ignored in ACKNOWLEDGE_*_PROBLEM commands
authorMichael Friedrich <michael.friedrich@gmail.com>
Sat, 7 Feb 2015 20:39:19 +0000 (21:39 +0100)
committerMichael Friedrich <michael.friedrich@gmail.com>
Sat, 7 Feb 2015 20:39:19 +0000 (21:39 +0100)
fixes #8298

lib/icinga/apievents.cpp
lib/icinga/apievents.hpp
lib/icinga/checkable.cpp
lib/icinga/checkable.hpp
lib/icinga/externalcommandprocessor.cpp

index c38284f541cb5594bcafa74b403f4407e4d0600f..6e21c7f8637e4e7a269503dad409e02a5e1cc4d8 100644 (file)
@@ -1392,7 +1392,7 @@ Value ApiEvents::DowntimeRemovedAPIHandler(const MessageOrigin& origin, const Di
 
 void ApiEvents::AcknowledgementSetHandler(const Checkable::Ptr& checkable,
     const String& author, const String& comment, AcknowledgementType type,
-    double expiry, const MessageOrigin& origin)
+    bool notify, double expiry, const MessageOrigin& origin)
 {
        ApiListener::Ptr listener = ApiListener::GetInstance();
 
@@ -1410,6 +1410,7 @@ void ApiEvents::AcknowledgementSetHandler(const Checkable::Ptr& checkable,
        params->Set("author", author);
        params->Set("comment", comment);
        params->Set("acktype", type);
+       params->Set("notify", notify);
        params->Set("expiry", expiry);
 
        Dictionary::Ptr message = new Dictionary();
@@ -1448,7 +1449,7 @@ Value ApiEvents::AcknowledgementSetAPIHandler(const MessageOrigin& origin, const
 
        checkable->AcknowledgeProblem(params->Get("author"), params->Get("comment"),
            static_cast<AcknowledgementType>(static_cast<int>(params->Get("acktype"))),
-           params->Get("expiry"), origin);
+           params->Get("notify"), params->Get("expiry"), origin);
 
        return Empty;
 }
index 0979e00118f0e753fb5115dda73a883d57b94707..289e1193d64f126073ec8444f8b6e6436e76a2d6 100644 (file)
@@ -103,7 +103,8 @@ public:
        static void DowntimeRemovedHandler(const Checkable::Ptr& checkable, const Downtime::Ptr& downtime, const MessageOrigin& origin);
        static Value DowntimeRemovedAPIHandler(const MessageOrigin& origin, const Dictionary::Ptr& params);
 
-       static void AcknowledgementSetHandler(const Checkable::Ptr& checkable, const String& author, const String& comment, AcknowledgementType type, double expiry, const MessageOrigin& origin);
+       static void AcknowledgementSetHandler(const Checkable::Ptr& checkable, const String& author, const String& comment, AcknowledgementType type,
+           bool notify, double expiry, const MessageOrigin& origin);
        static Value AcknowledgementSetAPIHandler(const MessageOrigin& origin, const Dictionary::Ptr& params);
 
        static void AcknowledgementClearedHandler(const Checkable::Ptr& checkable, const MessageOrigin& origin);
index 6cbe90bde19ea93cdb05d221824a049ec82dc700..d54aa8ec514b8b434cb37760438b014f70f1afae 100644 (file)
@@ -31,7 +31,7 @@ REGISTER_TYPE(Checkable);
 REGISTER_SCRIPTFUNCTION(ValidateCheckableCheckInterval, &Checkable::ValidateCheckInterval);
 
 boost::signals2::signal<void (const Checkable::Ptr&, bool, const MessageOrigin&)> Checkable::OnEnablePerfdataChanged;
-boost::signals2::signal<void (const Checkable::Ptr&, const String&, const String&, AcknowledgementType, double, const MessageOrigin&)> Checkable::OnAcknowledgementSet;
+boost::signals2::signal<void (const Checkable::Ptr&, const String&, const String&, AcknowledgementType, bool, double, const MessageOrigin&)> Checkable::OnAcknowledgementSet;
 boost::signals2::signal<void (const Checkable::Ptr&, const MessageOrigin&)> Checkable::OnAcknowledgementCleared;
 
 Checkable::Checkable(void)
@@ -121,7 +121,7 @@ bool Checkable::IsAcknowledged(void)
        return GetAcknowledgement() != AcknowledgementNone;
 }
 
-void Checkable::AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, double expiry, const MessageOrigin& origin)
+void Checkable::AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, bool notify, double expiry, const MessageOrigin& origin)
 {
        {
                ObjectLock olock(this);
@@ -130,9 +130,10 @@ void Checkable::AcknowledgeProblem(const String& author, const String& comment,
                SetAcknowledgementExpiry(expiry);
        }
 
-       OnNotificationsRequested(this, NotificationAcknowledgement, GetLastCheckResult(), author, comment);
+       if (notify)
+               OnNotificationsRequested(this, NotificationAcknowledgement, GetLastCheckResult(), author, comment);
 
-       OnAcknowledgementSet(this, author, comment, type, expiry, origin);
+       OnAcknowledgementSet(this, author, comment, type, notify, expiry, origin);
 }
 
 void Checkable::ClearAcknowledgement(const MessageOrigin& origin)
index eb2e2dc90c2fc9e6e0686f6721e0a381db6b4607..1968c5d889d860ce468c25f7d12e99024ca6985b 100644 (file)
@@ -94,7 +94,7 @@ public:
 
        AcknowledgementType GetAcknowledgement(void);
 
-       void AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, double expiry = 0, const MessageOrigin& origin = MessageOrigin());
+       void AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, bool notify = true, double expiry = 0, const MessageOrigin& origin = MessageOrigin());
        void ClearAcknowledgement(const MessageOrigin& origin = MessageOrigin());
 
        /* Checks */
@@ -187,7 +187,7 @@ public:
        static boost::signals2::signal<void (const Checkable::Ptr&, FlappingState)> OnFlappingChanged;
        static boost::signals2::signal<void (const Checkable::Ptr&, const Downtime::Ptr&)> OnDowntimeTriggered;
        static boost::signals2::signal<void (const Checkable::Ptr&, const String&, const String&, AcknowledgementType,
-                                            double, const MessageOrigin&)> OnAcknowledgementSet;
+                                            bool, double, const MessageOrigin&)> OnAcknowledgementSet;
        static boost::signals2::signal<void (const Checkable::Ptr&, const MessageOrigin&)> OnAcknowledgementCleared;
        static boost::signals2::signal<void (const Checkable::Ptr&)> OnEventCommandExecuted;
 
index 4a01ff15a895f8ada736aac3f766a0fba4dbe6e0..a9f8943e0b01806f9271d58787101f4b61283c57 100644 (file)
@@ -641,6 +641,7 @@ void ExternalCommandProcessor::DisableHostSvcChecks(double, const std::vector<St
 void ExternalCommandProcessor::AcknowledgeSvcProblem(double, const std::vector<String>& arguments)
 {
        bool sticky = (Convert::ToLong(arguments[2]) == 2 ? true : false);
+       bool notify = (Convert::ToLong(arguments[3]) > 0 ? true : false);
 
        Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
 
@@ -651,15 +652,16 @@ void ExternalCommandProcessor::AcknowledgeSvcProblem(double, const std::vector<S
                BOOST_THROW_EXCEPTION(std::invalid_argument("The service '" + arguments[1] + "' is OK."));
 
        Log(LogNotice, "ExternalCommandProcessor")
-           << "Setting acknowledgement for service '" << service->GetName() << "'";
+           << "Setting acknowledgement for service '" << service->GetName() << "'" << (notify ? "" : ". Disabled notification");
 
        service->AddComment(CommentAcknowledgement, arguments[5], arguments[6], 0);
-       service->AcknowledgeProblem(arguments[5], arguments[6], sticky ? AcknowledgementSticky : AcknowledgementNormal);
+       service->AcknowledgeProblem(arguments[5], arguments[6], sticky ? AcknowledgementSticky : AcknowledgementNormal, notify);
 }
 
 void ExternalCommandProcessor::AcknowledgeSvcProblemExpire(double, const std::vector<String>& arguments)
 {
        bool sticky = (Convert::ToLong(arguments[2]) == 2 ? true : false);
+       bool notify = (Convert::ToLong(arguments[3]) > 0 ? true : false);
        double timestamp = Convert::ToDouble(arguments[5]);
 
        Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
@@ -671,10 +673,10 @@ void ExternalCommandProcessor::AcknowledgeSvcProblemExpire(double, const std::ve
                BOOST_THROW_EXCEPTION(std::invalid_argument("The service '" + arguments[1] + "' is OK."));
 
        Log(LogNotice, "ExternalCommandProcessor")
-           << "Setting timed acknowledgement for service '" << service->GetName() << "'";
+           << "Setting timed acknowledgement for service '" << service->GetName() << "'" << (notify ? "" : ". Disabled notification");
 
        service->AddComment(CommentAcknowledgement, arguments[6], arguments[7], 0);
-       service->AcknowledgeProblem(arguments[6], arguments[7], sticky ? AcknowledgementSticky : AcknowledgementNormal, timestamp);
+       service->AcknowledgeProblem(arguments[6], arguments[7], sticky ? AcknowledgementSticky : AcknowledgementNormal, notify, timestamp);
 }
 
 void ExternalCommandProcessor::RemoveSvcAcknowledgement(double, const std::vector<String>& arguments)
@@ -698,6 +700,7 @@ void ExternalCommandProcessor::RemoveSvcAcknowledgement(double, const std::vecto
 void ExternalCommandProcessor::AcknowledgeHostProblem(double, const std::vector<String>& arguments)
 {
        bool sticky = (Convert::ToLong(arguments[1]) == 2 ? true : false);
+       bool notify = (Convert::ToLong(arguments[2]) > 0 ? true : false);
 
        Host::Ptr host = Host::GetByName(arguments[0]);
 
@@ -705,18 +708,19 @@ void ExternalCommandProcessor::AcknowledgeHostProblem(double, const std::vector<
                BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot acknowledge host problem for non-existent host '" + arguments[0] + "'"));
 
        Log(LogNotice, "ExternalCommandProcessor")
-           << "Setting acknowledgement for host '" << host->GetName() << "'";
+           << "Setting acknowledgement for host '" << host->GetName() << "'" << (notify ? "" : ". Disabled notification");
 
        if (host->GetState() == HostUp)
                BOOST_THROW_EXCEPTION(std::invalid_argument("The host '" + arguments[0] + "' is OK."));
 
        host->AddComment(CommentAcknowledgement, arguments[4], arguments[5], 0);
-       host->AcknowledgeProblem(arguments[4], arguments[5], sticky ? AcknowledgementSticky : AcknowledgementNormal);
+       host->AcknowledgeProblem(arguments[4], arguments[5], sticky ? AcknowledgementSticky : AcknowledgementNormal, notify);
 }
 
 void ExternalCommandProcessor::AcknowledgeHostProblemExpire(double, const std::vector<String>& arguments)
 {
        bool sticky = (Convert::ToLong(arguments[1]) == 2 ? true : false);
+       bool notify = (Convert::ToLong(arguments[2]) > 0 ? true : false);
        double timestamp = Convert::ToDouble(arguments[4]);
 
        Host::Ptr host = Host::GetByName(arguments[0]);
@@ -725,13 +729,13 @@ void ExternalCommandProcessor::AcknowledgeHostProblemExpire(double, const std::v
                BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot acknowledge host problem with expire time for non-existent host '" + arguments[0] + "'"));
 
        Log(LogNotice, "ExternalCommandProcessor")
-           << "Setting timed acknowledgement for host '" << host->GetName() << "'";
+           << "Setting timed acknowledgement for host '" << host->GetName() << "'" << (notify ? "" : ". Disabled notification");
 
        if (host->GetState() == HostUp)
                BOOST_THROW_EXCEPTION(std::invalid_argument("The host '" + arguments[0] + "' is OK."));
 
        host->AddComment(CommentAcknowledgement, arguments[5], arguments[6], 0);
-       host->AcknowledgeProblem(arguments[5], arguments[6], sticky ? AcknowledgementSticky : AcknowledgementNormal, timestamp);
+       host->AcknowledgeProblem(arguments[5], arguments[6], sticky ? AcknowledgementSticky : AcknowledgementNormal, notify, timestamp);
 }
 
 void ExternalCommandProcessor::RemoveHostAcknowledgement(double, const std::vector<String>& arguments)