diff --git a/lib/icinga/externalcommandprocessor.cpp b/lib/icinga/externalcommandprocessor.cpp index e5ce06d59..dc4e04aad 100644 --- a/lib/icinga/externalcommandprocessor.cpp +++ b/lib/icinga/externalcommandprocessor.cpp @@ -492,7 +492,7 @@ void ExternalCommandProcessor::AcknowledgeSvcProblem(double, const std::vectorGetName() + "'"); - service->AcknowledgeProblem(sticky ? AcknowledgementSticky : AcknowledgementNormal); + service->AcknowledgeProblem(arguments[5], arguments[6], sticky ? AcknowledgementSticky : AcknowledgementNormal); } void ExternalCommandProcessor::AcknowledgeSvcProblemExpire(double, const std::vector& arguments) @@ -510,7 +510,7 @@ void ExternalCommandProcessor::AcknowledgeSvcProblemExpire(double, const std::ve Log(LogInformation, "icinga", "Setting timed acknowledgement for service '" + service->GetName() + "'"); - service->AcknowledgeProblem(sticky ? AcknowledgementSticky : AcknowledgementNormal, timestamp); + service->AcknowledgeProblem(arguments[6], arguments[7], sticky ? AcknowledgementSticky : AcknowledgementNormal, timestamp); } void ExternalCommandProcessor::RemoveSvcAcknowledgement(double, const std::vector& arguments) @@ -540,7 +540,7 @@ void ExternalCommandProcessor::AcknowledgeHostProblem(double, const std::vector< if (service->GetState() == StateOK) BOOST_THROW_EXCEPTION(std::invalid_argument("The host '" + arguments[0] + "' is OK.")); - service->AcknowledgeProblem(sticky ? AcknowledgementSticky : AcknowledgementNormal); + service->AcknowledgeProblem(arguments[4], arguments[5], sticky ? AcknowledgementSticky : AcknowledgementNormal); } } @@ -560,7 +560,7 @@ void ExternalCommandProcessor::AcknowledgeHostProblemExpire(double, const std::v if (service->GetState() == StateOK) BOOST_THROW_EXCEPTION(std::invalid_argument("The host '" + arguments[0] + "' is OK.")); - service->AcknowledgeProblem(sticky ? AcknowledgementSticky : AcknowledgementNormal, timestamp); + service->AcknowledgeProblem(arguments[5], arguments[6], sticky ? AcknowledgementSticky : AcknowledgementNormal, timestamp); } } diff --git a/lib/icinga/service-check.cpp b/lib/icinga/service-check.cpp index 4270d8a27..0ccb50662 100644 --- a/lib/icinga/service-check.cpp +++ b/lib/icinga/service-check.cpp @@ -397,6 +397,11 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr) call_eventhandler = true; } + bool remove_acknowledgement_comments = false; + + if (GetAcknowledgement() == AcknowledgementNone) + remove_acknowledgement_comments = true; + bool hardChange = (GetStateType() == StateTypeHard && old_stateType == StateTypeSoft); if (old_state != GetState() && old_stateType == StateTypeHard && GetStateType() == StateTypeHard) @@ -425,6 +430,9 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr) olock.Unlock(); + if (remove_acknowledgement_comments) + RemoveCommentsByType(CommentAcknowledgement); + Dictionary::Ptr vars_after = boost::make_shared(); vars_after->Set("state", GetState()); vars_after->Set("state_type", GetStateType()); diff --git a/lib/icinga/service-comment.cpp b/lib/icinga/service-comment.cpp index 0a02be8bd..972b71c8d 100644 --- a/lib/icinga/service-comment.cpp +++ b/lib/icinga/service-comment.cpp @@ -239,6 +239,36 @@ void Service::RefreshCommentsCache(void) } } +void Service::RemoveCommentsByType(int type) +{ + Dictionary::Ptr comments = GetComments(); + + if (!comments) + return; + + std::vector removedComments; + + { + ObjectLock olock(comments); + + String id; + Dictionary::Ptr comment; + BOOST_FOREACH(tie(id, comment), comments) { + if (comment->Get("entry_type") == type) + removedComments.push_back(id); + } + } + + if (!removedComments.empty()) { + BOOST_FOREACH(const String& id, removedComments) { + comments->Remove(id); + } + + ObjectLock olock(this); + Touch("comments"); + } +} + void Service::RemoveExpiredComments(void) { Dictionary::Ptr comments = GetComments(); diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp index 4bd5aeda1..76dc134ce 100644 --- a/lib/icinga/service.cpp +++ b/lib/icinga/service.cpp @@ -280,7 +280,7 @@ void Service::SetAcknowledgementExpiry(double timestamp) Touch("acknowledgement_expiry"); } -void Service::AcknowledgeProblem(AcknowledgementType type, double expiry) +void Service::AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, double expiry) { { ObjectLock olock(this); @@ -289,6 +289,8 @@ void Service::AcknowledgeProblem(AcknowledgementType type, double expiry) SetAcknowledgementExpiry(expiry); } + (void) AddComment(CommentAcknowledgement, author, comment, 0); + RequestNotifications(NotificationAcknowledgement, GetLastCheckResult()); } diff --git a/lib/icinga/service.h b/lib/icinga/service.h index 0db3e4dd1..42d9489a0 100644 --- a/lib/icinga/service.h +++ b/lib/icinga/service.h @@ -162,7 +162,7 @@ public: static void UpdateStatistics(const Dictionary::Ptr& cr); - void AcknowledgeProblem(AcknowledgementType type, double expiry = 0); + void AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, double expiry = 0); void ClearAcknowledgement(void); void ExecuteCheck(void); @@ -217,6 +217,7 @@ public: const String& text, double expireTime); void RemoveAllComments(void); + void RemoveCommentsByType(int type); static void RemoveComment(const String& id); static String GetCommentIDFromLegacyID(int id);