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

View File

@ -2026,6 +2026,21 @@ void IcingaDB::SendRemovedComment(const Comment::Ptr& comment)
return; 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()); auto checkable (comment->GetCheckable());
Host::Ptr host; Host::Ptr host;
@ -2064,8 +2079,7 @@ void IcingaDB::SendRemovedComment(const Comment::Ptr& comment)
xAdd.emplace_back(GetObjectIdentifier(endpoint)); xAdd.emplace_back(GetObjectIdentifier(endpoint));
} }
double removeTime = comment->GetRemoveTime(); if (wasRemoved) {
if (removeTime > 0) {
xAdd.emplace_back("remove_time"); xAdd.emplace_back("remove_time");
xAdd.emplace_back(Convert::ToString(TimestampToMilliseconds(removeTime))); xAdd.emplace_back(Convert::ToString(TimestampToMilliseconds(removeTime)));
xAdd.emplace_back("has_been_removed"); xAdd.emplace_back("has_been_removed");
@ -2077,13 +2091,9 @@ void IcingaDB::SendRemovedComment(const Comment::Ptr& comment)
xAdd.emplace_back("0"); xAdd.emplace_back("0");
} }
{ if (hasExpireTime) {
auto expireTime (comment->GetExpireTime()); xAdd.emplace_back("expire_time");
xAdd.emplace_back(Convert::ToString(TimestampToMilliseconds(expireTime)));
if (expireTime > 0) {
xAdd.emplace_back("expire_time");
xAdd.emplace_back(Convert::ToString(TimestampToMilliseconds(expireTime)));
}
} }
m_HistoryBulker.ProduceOne(std::move(xAdd)); m_HistoryBulker.ProduceOne(std::move(xAdd));