Merge pull request #9298 from Icinga/bugfix/icingadb-remove-comment-history

Icinga DB: discard comment removals with missing information
This commit is contained in:
Alexander Aleksandrovič Klimov 2022-03-29 11:25:01 +02:00 committed by GitHub
commit d171301b9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 9 deletions

View File

@ -2026,6 +2026,21 @@ void IcingaDB::SendRemovedComment(const Comment::Ptr& comment)
return;
}
double removeTime = comment->GetRemoveTime();
bool wasRemoved = removeTime > 0;
double expireTime = comment->GetExpireTime();
bool hasExpireTime = expireTime > 0;
bool isExpired = hasExpireTime && expireTime <= Utility::GetTime();
if (!wasRemoved && !isExpired) {
/* The comment object disappeared for no apparent reason, most likely because it simply was deleted instead
* of using the proper remove-comment API action. In this case, information that should normally be set is
* missing and a proper history event cannot be generated.
*/
return;
}
auto checkable (comment->GetCheckable());
Host::Ptr host;
@ -2064,8 +2079,7 @@ void IcingaDB::SendRemovedComment(const Comment::Ptr& comment)
xAdd.emplace_back(GetObjectIdentifier(endpoint));
}
double removeTime = comment->GetRemoveTime();
if (removeTime > 0) {
if (wasRemoved) {
xAdd.emplace_back("remove_time");
xAdd.emplace_back(Convert::ToString(TimestampToMilliseconds(removeTime)));
xAdd.emplace_back("has_been_removed");
@ -2077,14 +2091,10 @@ void IcingaDB::SendRemovedComment(const Comment::Ptr& comment)
xAdd.emplace_back("0");
}
{
auto expireTime (comment->GetExpireTime());
if (expireTime > 0) {
if (hasExpireTime) {
xAdd.emplace_back("expire_time");
xAdd.emplace_back(Convert::ToString(TimestampToMilliseconds(expireTime)));
}
}
m_HistoryBulker.ProduceOne(std::move(xAdd));
UpdateState(checkable, StateUpdate::Full);