Implement support for acknowledgement comments.

Fixes #3585
This commit is contained in:
Gunnar Beutner 2013-06-19 10:57:07 +02:00
parent e13a6ac23d
commit 1d7428b237
5 changed files with 47 additions and 6 deletions

View File

@ -492,7 +492,7 @@ void ExternalCommandProcessor::AcknowledgeSvcProblem(double, const std::vector<S
Log(LogInformation, "icinga", "Setting acknowledgement for service '" + service->GetName() + "'"); 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) 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() + "'"); 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) void ExternalCommandProcessor::RemoveSvcAcknowledgement(double, const std::vector<String>& arguments)
@ -540,7 +540,7 @@ void ExternalCommandProcessor::AcknowledgeHostProblem(double, const std::vector<
if (service->GetState() == StateOK) if (service->GetState() == StateOK)
BOOST_THROW_EXCEPTION(std::invalid_argument("The host '" + arguments[0] + "' is OK.")); 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) if (service->GetState() == StateOK)
BOOST_THROW_EXCEPTION(std::invalid_argument("The host '" + arguments[0] + "' is OK.")); 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);
} }
} }

View File

@ -397,6 +397,11 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr)
call_eventhandler = true; call_eventhandler = true;
} }
bool remove_acknowledgement_comments = false;
if (GetAcknowledgement() == AcknowledgementNone)
remove_acknowledgement_comments = true;
bool hardChange = (GetStateType() == StateTypeHard && old_stateType == StateTypeSoft); bool hardChange = (GetStateType() == StateTypeHard && old_stateType == StateTypeSoft);
if (old_state != GetState() && old_stateType == StateTypeHard && GetStateType() == StateTypeHard) if (old_state != GetState() && old_stateType == StateTypeHard && GetStateType() == StateTypeHard)
@ -425,6 +430,9 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr)
olock.Unlock(); olock.Unlock();
if (remove_acknowledgement_comments)
RemoveCommentsByType(CommentAcknowledgement);
Dictionary::Ptr vars_after = boost::make_shared<Dictionary>(); Dictionary::Ptr vars_after = boost::make_shared<Dictionary>();
vars_after->Set("state", GetState()); vars_after->Set("state", GetState());
vars_after->Set("state_type", GetStateType()); vars_after->Set("state_type", GetStateType());

View 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) void Service::RemoveExpiredComments(void)
{ {
Dictionary::Ptr comments = GetComments(); Dictionary::Ptr comments = GetComments();

View File

@ -280,7 +280,7 @@ void Service::SetAcknowledgementExpiry(double timestamp)
Touch("acknowledgement_expiry"); 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); ObjectLock olock(this);
@ -289,6 +289,8 @@ void Service::AcknowledgeProblem(AcknowledgementType type, double expiry)
SetAcknowledgementExpiry(expiry); SetAcknowledgementExpiry(expiry);
} }
(void) AddComment(CommentAcknowledgement, author, comment, 0);
RequestNotifications(NotificationAcknowledgement, GetLastCheckResult()); RequestNotifications(NotificationAcknowledgement, GetLastCheckResult());
} }

View File

@ -162,7 +162,7 @@ public:
static void UpdateStatistics(const Dictionary::Ptr& cr); 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 ClearAcknowledgement(void);
void ExecuteCheck(void); void ExecuteCheck(void);
@ -217,6 +217,7 @@ public:
const String& text, double expireTime); const String& text, double expireTime);
void RemoveAllComments(void); void RemoveAllComments(void);
void RemoveCommentsByType(int type);
static void RemoveComment(const String& id); static void RemoveComment(const String& id);
static String GetCommentIDFromLegacyID(int id); static String GetCommentIDFromLegacyID(int id);