Introduce Checkable#acknowledgement_last_change

refs #7689
This commit is contained in:
Alexander A. Klimov 2019-12-04 15:19:03 +01:00
parent 98ba1c03d0
commit 829d07aefe
11 changed files with 46 additions and 39 deletions

View File

@ -49,7 +49,7 @@ void DbEvents::StaticInitialize()
/* History */
Comment::OnCommentAdded.connect(std::bind(&DbEvents::AddCommentHistory, _1));
Downtime::OnDowntimeAdded.connect(std::bind(&DbEvents::AddDowntimeHistory, _1));
Checkable::OnAcknowledgementSet.connect(std::bind(&DbEvents::AddAcknowledgementHistory, _1, _2, _3, _4, _5, _6));
Checkable::OnAcknowledgementSet.connect(std::bind(&DbEvents::AddAcknowledgementHistory, _1, _2, _3, _4, _5, _7));
Checkable::OnNotificationSentToAllUsers.connect(std::bind(&DbEvents::AddNotificationHistory, _1, _2, _3, _4, _5, _6, _7));

View File

@ -235,7 +235,7 @@ Dictionary::Ptr ApiActions::AcknowledgeProblem(const ConfigObject::Ptr& object,
Comment::AddComment(checkable, CommentAcknowledgement, HttpUtility::GetLastParameter(params, "author"),
HttpUtility::GetLastParameter(params, "comment"), persistent, timestamp);
checkable->AcknowledgeProblem(HttpUtility::GetLastParameter(params, "author"),
HttpUtility::GetLastParameter(params, "comment"), sticky, notify, persistent, timestamp);
HttpUtility::GetLastParameter(params, "comment"), sticky, notify, persistent, Utility::GetTime(), timestamp);
return ApiActions::CreateResult(200, "Successfully acknowledged problem for object '" + checkable->GetName() + "'.");
}

View File

@ -182,7 +182,7 @@ void ApiEvents::FlappingChangedHandler(const Checkable::Ptr& checkable, const Me
void ApiEvents::AcknowledgementSetHandler(const Checkable::Ptr& checkable,
const String& author, const String& comment, AcknowledgementType type,
bool notify, bool persistent, double expiry, const MessageOrigin::Ptr& origin)
bool notify, bool persistent, double, double expiry, const MessageOrigin::Ptr& origin)
{
std::vector<EventQueue::Ptr> queues = EventQueue::GetQueuesForType("AcknowledgementSet");
auto inboxes (EventsRouter::GetInstance().GetInboxes(EventType::AcknowledgementSet));
@ -221,7 +221,7 @@ void ApiEvents::AcknowledgementSetHandler(const Checkable::Ptr& checkable,
inboxes.Push(std::move(result));
}
void ApiEvents::AcknowledgementClearedHandler(const Checkable::Ptr& checkable, const String& removedBy, const MessageOrigin::Ptr& origin)
void ApiEvents::AcknowledgementClearedHandler(const Checkable::Ptr& checkable, const String& removedBy, double, const MessageOrigin::Ptr& origin)
{
std::vector<EventQueue::Ptr> queues = EventQueue::GetQueuesForType("AcknowledgementCleared");
auto inboxes (EventsRouter::GetInstance().GetInboxes(EventType::AcknowledgementCleared));

View File

@ -29,8 +29,8 @@ public:
static void AcknowledgementSetHandler(const Checkable::Ptr& checkable,
const String& author, const String& comment, AcknowledgementType type,
bool notify, bool persistent, double expiry, const MessageOrigin::Ptr& origin);
static void AcknowledgementClearedHandler(const Checkable::Ptr& checkable, const String& removedBy, const MessageOrigin::Ptr& origin);
bool notify, bool persistent, double, double expiry, const MessageOrigin::Ptr& origin);
static void AcknowledgementClearedHandler(const Checkable::Ptr& checkable, const String& removedBy, double, const MessageOrigin::Ptr& origin);
static void CommentAddedHandler(const Comment::Ptr& comment);
static void CommentRemovedHandler(const Comment::Ptr& comment);

View File

@ -15,8 +15,8 @@ using namespace icinga;
REGISTER_TYPE_WITH_PROTOTYPE(Checkable, Checkable::GetPrototype());
INITIALIZE_ONCE(&Checkable::StaticInitialize);
boost::signals2::signal<void (const Checkable::Ptr&, const String&, const String&, AcknowledgementType, bool, bool, double, const MessageOrigin::Ptr&)> Checkable::OnAcknowledgementSet;
boost::signals2::signal<void (const Checkable::Ptr&, const String&, const MessageOrigin::Ptr&)> Checkable::OnAcknowledgementCleared;
boost::signals2::signal<void (const Checkable::Ptr&, const String&, const String&, AcknowledgementType, bool, bool, double, double, const MessageOrigin::Ptr&)> Checkable::OnAcknowledgementSet;
boost::signals2::signal<void (const Checkable::Ptr&, const String&, double, const MessageOrigin::Ptr&)> Checkable::OnAcknowledgementCleared;
static Timer::Ptr l_CheckablesFireSuppressedNotifications;
@ -122,7 +122,7 @@ bool Checkable::IsAcknowledged() const
return const_cast<Checkable *>(this)->GetAcknowledgement() != AcknowledgementNone;
}
void Checkable::AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, bool notify, bool persistent, double expiry, const MessageOrigin::Ptr& origin)
void Checkable::AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, bool notify, bool persistent, double changeTime, double expiry, const MessageOrigin::Ptr& origin)
{
SetAcknowledgementRaw(type);
SetAcknowledgementExpiry(expiry);
@ -133,10 +133,12 @@ void Checkable::AcknowledgeProblem(const String& author, const String& comment,
Log(LogInformation, "Checkable")
<< "Acknowledgement set for checkable '" << GetName() << "'.";
OnAcknowledgementSet(this, author, comment, type, notify, persistent, expiry, origin);
OnAcknowledgementSet(this, author, comment, type, notify, persistent, changeTime, expiry, origin);
SetAcknowledgementLastChange(changeTime);
}
void Checkable::ClearAcknowledgement(const String& removedBy, const MessageOrigin::Ptr& origin)
void Checkable::ClearAcknowledgement(const String& removedBy, double changeTime, const MessageOrigin::Ptr& origin)
{
ObjectLock oLock (this);
@ -157,7 +159,9 @@ void Checkable::ClearAcknowledgement(const String& removedBy, const MessageOrigi
<< "Acknowledgement cleared for checkable '" << GetName() << "'.";
if (wasAcked) {
OnAcknowledgementCleared(this, removedBy, origin);
OnAcknowledgementCleared(this, removedBy, changeTime, origin);
SetAcknowledgementLastChange(changeTime);
}
}

View File

@ -68,8 +68,8 @@ public:
AcknowledgementType GetAcknowledgement();
void AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, bool notify = true, bool persistent = false, double expiry = 0, const MessageOrigin::Ptr& origin = nullptr);
void ClearAcknowledgement(const String& removedBy, const MessageOrigin::Ptr& origin = nullptr);
void AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, bool notify = true, bool persistent = false, double changeTime = Utility::GetTime(), double expiry = 0, const MessageOrigin::Ptr& origin = nullptr);
void ClearAcknowledgement(const String& removedBy, double changeTime = Utility::GetTime(), const MessageOrigin::Ptr& origin = nullptr);
int GetSeverity() const override;
bool GetProblem() const override;
@ -112,8 +112,8 @@ public:
const NotificationType&, const CheckResult::Ptr&, const String&,
const String&, const MessageOrigin::Ptr&)> OnNotificationSentToAllUsers;
static boost::signals2::signal<void (const Checkable::Ptr&, const String&, const String&, AcknowledgementType,
bool, bool, double, const MessageOrigin::Ptr&)> OnAcknowledgementSet;
static boost::signals2::signal<void (const Checkable::Ptr&, const String&, const MessageOrigin::Ptr&)> OnAcknowledgementCleared;
bool, bool, double, double, const MessageOrigin::Ptr&)> OnAcknowledgementSet;
static boost::signals2::signal<void (const Checkable::Ptr&, const String&, double, const MessageOrigin::Ptr&)> OnAcknowledgementCleared;
static boost::signals2::signal<void (const Checkable::Ptr&)> OnNextCheckUpdated;
static boost::signals2::signal<void (const Checkable::Ptr&)> OnEventCommandExecuted;

View File

@ -147,6 +147,7 @@ abstract class Checkable : CustomVarObject
default {{{ return AcknowledgementNone; }}}
};
[state] Timestamp acknowledgement_expiry;
[state] Timestamp acknowledgement_last_change;
[state] bool force_next_notification;
[no_storage] Timestamp last_check {
get;

View File

@ -473,7 +473,7 @@ Value ClusterEvents::ForceNextNotificationChangedAPIHandler(const MessageOrigin:
void ClusterEvents::AcknowledgementSetHandler(const Checkable::Ptr& checkable,
const String& author, const String& comment, AcknowledgementType type,
bool notify, bool persistent, double expiry, const MessageOrigin::Ptr& origin)
bool notify, bool persistent, double changeTime, double expiry, const MessageOrigin::Ptr& origin)
{
ApiListener::Ptr listener = ApiListener::GetInstance();
@ -494,6 +494,7 @@ void ClusterEvents::AcknowledgementSetHandler(const Checkable::Ptr& checkable,
params->Set("notify", notify);
params->Set("persistent", persistent);
params->Set("expiry", expiry);
params->Set("change_time", changeTime);
Dictionary::Ptr message = new Dictionary();
message->Set("jsonrpc", "2.0");
@ -546,12 +547,12 @@ Value ClusterEvents::AcknowledgementSetAPIHandler(const MessageOrigin::Ptr& orig
checkable->AcknowledgeProblem(params->Get("author"), params->Get("comment"),
static_cast<AcknowledgementType>(static_cast<int>(params->Get("acktype"))),
params->Get("notify"), params->Get("persistent"), params->Get("expiry"), origin);
params->Get("notify"), params->Get("persistent"), params->Get("change_time"), params->Get("expiry"), origin);
return Empty;
}
void ClusterEvents::AcknowledgementClearedHandler(const Checkable::Ptr& checkable, const String& removedBy, const MessageOrigin::Ptr& origin)
void ClusterEvents::AcknowledgementClearedHandler(const Checkable::Ptr& checkable, const String& removedBy, double changeTime, const MessageOrigin::Ptr& origin)
{
ApiListener::Ptr listener = ApiListener::GetInstance();
@ -567,6 +568,7 @@ void ClusterEvents::AcknowledgementClearedHandler(const Checkable::Ptr& checkabl
if (service)
params->Set("service", service->GetShortName());
params->Set("author", removedBy);
params->Set("change_time", changeTime);
Dictionary::Ptr message = new Dictionary();
message->Set("jsonrpc", "2.0");
@ -608,7 +610,7 @@ Value ClusterEvents::AcknowledgementClearedAPIHandler(const MessageOrigin::Ptr&
return Empty;
}
checkable->ClearAcknowledgement(params->Get("author"), origin);
checkable->ClearAcknowledgement(params->Get("author"), params->Get("change_time"), origin);
return Empty;
}

View File

@ -39,10 +39,10 @@ public:
static Value ForceNextNotificationChangedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params);
static void AcknowledgementSetHandler(const Checkable::Ptr& checkable, const String& author, const String& comment, AcknowledgementType type,
bool notify, bool persistent, double expiry, const MessageOrigin::Ptr& origin);
bool notify, bool persistent, double changeTime, double expiry, const MessageOrigin::Ptr& origin);
static Value AcknowledgementSetAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params);
static void AcknowledgementClearedHandler(const Checkable::Ptr& checkable, const String& removedBy, const MessageOrigin::Ptr& origin);
static void AcknowledgementClearedHandler(const Checkable::Ptr& checkable, const String& removedBy, double changeTime, const MessageOrigin::Ptr& origin);
static Value AcknowledgementClearedAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params);
static Value ExecuteCommandAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params);

View File

@ -60,15 +60,15 @@ void IcingaDB::ConfigStaticInitialize()
IcingaDB::StateChangeHandler(checkable, cr, type);
});
Checkable::OnAcknowledgementSet.connect([](const Checkable::Ptr& checkable, const String& author, const String& comment, AcknowledgementType type, bool, bool persistent, double expiry, const MessageOrigin::Ptr&) {
AcknowledgementSetHandler(checkable, author, comment, type, persistent, expiry);
Checkable::OnAcknowledgementSet.connect([](const Checkable::Ptr& checkable, const String& author, const String& comment, AcknowledgementType type, bool, bool persistent, double changeTime, double expiry, const MessageOrigin::Ptr&) {
AcknowledgementSetHandler(checkable, author, comment, type, persistent, changeTime, expiry);
});
Checkable::OnAcknowledgementCleared.connect([](const Checkable::Ptr& checkable, const String& removedBy, const MessageOrigin::Ptr&) {
AcknowledgementClearedHandler(checkable, removedBy);
Checkable::OnAcknowledgementCleared.connect([](const Checkable::Ptr& checkable, const String& removedBy, double changeTime, const MessageOrigin::Ptr&) {
AcknowledgementClearedHandler(checkable, removedBy, changeTime);
});
/* triggered when acknowledged host/service goes back to ok and when the acknowledgement gets deleted */
Checkable::OnAcknowledgementCleared.connect([](const Checkable::Ptr& checkable, const String&, const MessageOrigin::Ptr&) {
Checkable::OnAcknowledgementCleared.connect([](const Checkable::Ptr& checkable, const String&, double, const MessageOrigin::Ptr&) {
IcingaDB::StateChangeHandler(checkable);
});
@ -1669,7 +1669,7 @@ void IcingaDB::SendNextUpdate(const Checkable::Ptr& checkable)
);
}
void IcingaDB::SendAcknowledgementSet(const Checkable::Ptr& checkable, const String& author, const String& comment, AcknowledgementType type, bool persistent, double expiry)
void IcingaDB::SendAcknowledgementSet(const Checkable::Ptr& checkable, const String& author, const String& comment, AcknowledgementType type, bool persistent, double changeTime, double expiry)
{
if (!m_Rcon || !m_Rcon->IsConnected())
return;
@ -1683,7 +1683,7 @@ void IcingaDB::SendAcknowledgementSet(const Checkable::Ptr& checkable, const Str
"id", Utility::NewUniqueID(),
"environment_id", SHA1(GetEnvironment()),
"host_id", GetObjectIdentifier(host),
"event_time", Convert::ToString(TimestampToMilliseconds(Utility::GetTime())),
"event_time", Convert::ToString(TimestampToMilliseconds(changeTime)),
"event_type", "ack_set",
"author", author,
"comment", comment,
@ -1716,7 +1716,7 @@ void IcingaDB::SendAcknowledgementSet(const Checkable::Ptr& checkable, const Str
m_Rcon->FireAndForgetQuery(std::move(xAdd), Prio::History);
}
void IcingaDB::SendAcknowledgementCleared(const Checkable::Ptr& checkable, const String& removedBy)
void IcingaDB::SendAcknowledgementCleared(const Checkable::Ptr& checkable, const String& removedBy, double changeTime)
{
if (!m_Rcon || !m_Rcon->IsConnected())
return;
@ -1730,7 +1730,7 @@ void IcingaDB::SendAcknowledgementCleared(const Checkable::Ptr& checkable, const
"id", Utility::NewUniqueID(),
"environment_id", SHA1(GetEnvironment()),
"host_id", GetObjectIdentifier(host),
"event_time", Convert::ToString(TimestampToMilliseconds(Utility::GetTime())),
"event_time", Convert::ToString(TimestampToMilliseconds(changeTime)),
"event_type", "ack_clear",
"author", removedBy
});
@ -2007,7 +2007,7 @@ struct AuthorComment
String Comment;
};
void IcingaDB::AcknowledgementSetHandler(const Checkable::Ptr& checkable, const String& author, const String& comment, AcknowledgementType type, bool persistent, double expiry)
void IcingaDB::AcknowledgementSetHandler(const Checkable::Ptr& checkable, const String& author, const String& comment, AcknowledgementType type, bool persistent, double changeTime, double expiry)
{
auto rws (ConfigType::GetObjectsByType<IcingaDB>());
@ -2015,12 +2015,12 @@ void IcingaDB::AcknowledgementSetHandler(const Checkable::Ptr& checkable, const
auto ac (Shared<AuthorComment>::Make(AuthorComment{author, comment}));
for (auto& rw : rws) {
rw->m_WorkQueue.Enqueue([rw, checkable, ac, type, persistent, expiry]() { rw->SendAcknowledgementSet(checkable, ac->Author, ac->Comment, type, persistent, expiry); });
rw->m_WorkQueue.Enqueue([rw, checkable, ac, type, persistent, changeTime, expiry]() { rw->SendAcknowledgementSet(checkable, ac->Author, ac->Comment, type, persistent, changeTime, expiry); });
}
}
}
void IcingaDB::AcknowledgementClearedHandler(const Checkable::Ptr& checkable, const String& removedBy)
void IcingaDB::AcknowledgementClearedHandler(const Checkable::Ptr& checkable, const String& removedBy, double changeTime)
{
auto rws (ConfigType::GetObjectsByType<IcingaDB>());
@ -2028,7 +2028,7 @@ void IcingaDB::AcknowledgementClearedHandler(const Checkable::Ptr& checkable, co
auto rb (Shared<String>::Make(removedBy));
for (auto& rw : rws) {
rw->m_WorkQueue.Enqueue([rw, checkable, rb]() { rw->SendAcknowledgementCleared(checkable, *rb); });
rw->m_WorkQueue.Enqueue([rw, checkable, rb, changeTime]() { rw->SendAcknowledgementCleared(checkable, *rb, changeTime); });
}
}
}

View File

@ -67,8 +67,8 @@ private:
void SendRemovedComment(const Comment::Ptr& comment);
void SendFlappingChanged(const Checkable::Ptr& checkable, const Value& value);
void SendNextUpdate(const Checkable::Ptr& checkable);
void SendAcknowledgementSet(const Checkable::Ptr& checkable, const String& author, const String& comment, AcknowledgementType type, bool persistent, double expiry);
void SendAcknowledgementCleared(const Checkable::Ptr& checkable, const String& removedBy);
void SendAcknowledgementSet(const Checkable::Ptr& checkable, const String& author, const String& comment, AcknowledgementType type, bool persistent, double changeTime, double expiry);
void SendAcknowledgementCleared(const Checkable::Ptr& checkable, const String& removedBy, double changeTime);
std::vector<String> UpdateObjectAttrs(const ConfigObject::Ptr& object, int fieldType, const String& typeNameOverride);
Dictionary::Ptr SerializeState(const Checkable::Ptr& checkable);
@ -106,8 +106,8 @@ private:
static void CommentRemovedHandler(const Comment::Ptr& comment);
static void FlappingChangedHandler(const Checkable::Ptr& checkable, const Value& value);
static void NewCheckResultHandler(const Checkable::Ptr& checkable);
static void AcknowledgementSetHandler(const Checkable::Ptr& checkable, const String& author, const String& comment, AcknowledgementType type, bool persistent, double expiry);
static void AcknowledgementClearedHandler(const Checkable::Ptr& checkable, const String& removedBy);
static void AcknowledgementSetHandler(const Checkable::Ptr& checkable, const String& author, const String& comment, AcknowledgementType type, bool persistent, double changeTime, double expiry);
static void AcknowledgementClearedHandler(const Checkable::Ptr& checkable, const String& removedBy, double changeTime);
void AssertOnWorkQueue();