]> granicus.if.org Git - icinga2/commitdiff
Implement support for acknowledgement comments.
authorGunnar Beutner <gunnar.beutner@netways.de>
Wed, 19 Jun 2013 08:57:07 +0000 (10:57 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Wed, 19 Jun 2013 08:57:07 +0000 (10:57 +0200)
Fixes #3585

lib/icinga/externalcommandprocessor.cpp
lib/icinga/service-check.cpp
lib/icinga/service-comment.cpp
lib/icinga/service.cpp
lib/icinga/service.h

index e5ce06d59c3786c6d9f947f296a4995cc6ba5446..dc4e04aad5e8f0e6f4b34c2012cb8928ea204bc9 100644 (file)
@@ -492,7 +492,7 @@ void ExternalCommandProcessor::AcknowledgeSvcProblem(double, const std::vector<S
 
        Log(LogInformation, "icinga", "Setting acknowledgement for service '" + service->GetName() + "'");
 
-       service->AcknowledgeProblem(sticky ? AcknowledgementSticky : AcknowledgementNormal);
+       service->AcknowledgeProblem(arguments[5], arguments[6], sticky ? AcknowledgementSticky : AcknowledgementNormal);
 }
 
 void ExternalCommandProcessor::AcknowledgeSvcProblemExpire(double, const std::vector<String>& 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<String>& 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);
        }
 }
 
index 4270d8a27d7195cf5ecf16717a659fe6daaa5663..0ccb506624663445a7282c5a4e6fdaf776f6952e 100644 (file)
@@ -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<Dictionary>();
        vars_after->Set("state", GetState());
        vars_after->Set("state_type", GetStateType());
index 0a02be8bd53dec9cd657301f5e1771a144fdaa83..972b71c8da166545ad7f4622d7b8d526ab9301c9 100644 (file)
@@ -239,6 +239,36 @@ void Service::RefreshCommentsCache(void)
        }
 }
 
+void Service::RemoveCommentsByType(int type)
+{
+       Dictionary::Ptr comments = GetComments();
+
+       if (!comments)
+               return;
+
+       std::vector<String> 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();
index 4bd5aeda1a2fa2afd293f5d5552c4373cd8c6fc5..76dc134ce3f980e8066d9483b387fad85edce974 100644 (file)
@@ -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());
 }
 
index 0db3e4dd19c4a41a2c52821a4a03aedfabc9fdf7..42d9489a006131eebe9a10714e27cec88170f637 100644 (file)
@@ -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);