From a1f04992f322835211b13a4444c0f1b9f5f5fbe6 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Sat, 7 Feb 2015 21:39:19 +0100 Subject: [PATCH] Fix notify flag is ignored in ACKNOWLEDGE_*_PROBLEM commands fixes #8298 --- lib/icinga/apievents.cpp | 5 +++-- lib/icinga/apievents.hpp | 3 ++- lib/icinga/checkable.cpp | 9 +++++---- lib/icinga/checkable.hpp | 4 ++-- lib/icinga/externalcommandprocessor.cpp | 20 ++++++++++++-------- 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/lib/icinga/apievents.cpp b/lib/icinga/apievents.cpp index c38284f54..6e21c7f86 100644 --- a/lib/icinga/apievents.cpp +++ b/lib/icinga/apievents.cpp @@ -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(static_cast(params->Get("acktype"))), - params->Get("expiry"), origin); + params->Get("notify"), params->Get("expiry"), origin); return Empty; } diff --git a/lib/icinga/apievents.hpp b/lib/icinga/apievents.hpp index 0979e0011..289e1193d 100644 --- a/lib/icinga/apievents.hpp +++ b/lib/icinga/apievents.hpp @@ -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); diff --git a/lib/icinga/checkable.cpp b/lib/icinga/checkable.cpp index 6cbe90bde..d54aa8ec5 100644 --- a/lib/icinga/checkable.cpp +++ b/lib/icinga/checkable.cpp @@ -31,7 +31,7 @@ REGISTER_TYPE(Checkable); REGISTER_SCRIPTFUNCTION(ValidateCheckableCheckInterval, &Checkable::ValidateCheckInterval); boost::signals2::signal Checkable::OnEnablePerfdataChanged; -boost::signals2::signal Checkable::OnAcknowledgementSet; +boost::signals2::signal Checkable::OnAcknowledgementSet; boost::signals2::signal 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) diff --git a/lib/icinga/checkable.hpp b/lib/icinga/checkable.hpp index eb2e2dc90..1968c5d88 100644 --- a/lib/icinga/checkable.hpp +++ b/lib/icinga/checkable.hpp @@ -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 OnFlappingChanged; static boost::signals2::signal OnDowntimeTriggered; static boost::signals2::signal OnAcknowledgementSet; + bool, double, const MessageOrigin&)> OnAcknowledgementSet; static boost::signals2::signal OnAcknowledgementCleared; static boost::signals2::signal OnEventCommandExecuted; diff --git a/lib/icinga/externalcommandprocessor.cpp b/lib/icinga/externalcommandprocessor.cpp index 4a01ff15a..a9f8943e0 100644 --- a/lib/icinga/externalcommandprocessor.cpp +++ b/lib/icinga/externalcommandprocessor.cpp @@ -641,6 +641,7 @@ void ExternalCommandProcessor::DisableHostSvcChecks(double, const std::vector& 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::vectorGetName() << "'"; + << "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& 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& arguments) @@ -698,6 +700,7 @@ void ExternalCommandProcessor::RemoveSvcAcknowledgement(double, const std::vecto void ExternalCommandProcessor::AcknowledgeHostProblem(double, const std::vector& 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& 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& arguments)