MCPcopy Create free account
hub / github.com/Icinga/icinga2 / SendRemovedComment

Method SendRemovedComment

lib/icingadb/icingadb-objects.cpp:2300–2380  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2298}
2299
2300void IcingaDB::SendRemovedComment(const Comment::Ptr& comment)
2301{
2302 if (comment->GetEntryType() != CommentUser || !GetActive()) {
2303 return;
2304 }
2305
2306 double removeTime = comment->GetRemoveTime();
2307 bool wasRemoved = removeTime > 0;
2308
2309 double expireTime = comment->GetExpireTime();
2310 bool hasExpireTime = expireTime > 0;
2311 bool isExpired = hasExpireTime && expireTime <= Utility::GetTime();
2312
2313 if (!wasRemoved && !isExpired) {
2314 /* The comment object disappeared for no apparent reason, most likely because it simply was deleted instead
2315 * of using the proper remove-comment API action. In this case, information that should normally be set is
2316 * missing and a proper history event cannot be generated.
2317 */
2318 return;
2319 }
2320
2321 auto checkable (comment->GetCheckable());
2322
2323 Host::Ptr host;
2324 Service::Ptr service;
2325 tie(host, service) = GetHostService(checkable);
2326
2327 // Update the checkable state to so that the "last_comment_id" is correctly reflected.
2328 EnqueueConfigObject(checkable, icingadb::task_queue::FullState);
2329
2330 RedisConnection::Query xAdd ({
2331 "XADD", "icinga:history:stream:comment", "*",
2332 "comment_id", GetObjectIdentifier(comment),
2333 "environment_id", m_EnvironmentId,
2334 "host_id", GetObjectIdentifier(host),
2335 "entry_time", Convert::ToString(TimestampToMilliseconds(comment->GetEntryTime())),
2336 "author", Utility::ValidateUTF8(comment->GetAuthor()),
2337 "comment", Utility::ValidateUTF8(comment->GetText()),
2338 "entry_type", IcingaDB::CommentTypeToString(comment->GetEntryType()),
2339 "is_persistent", Convert::ToString((unsigned short)comment->GetPersistent()),
2340 "is_sticky", Convert::ToString((unsigned short)comment->GetSticky()),
2341 "event_id", CalcEventID("comment_remove", comment),
2342 "event_type", "comment_remove"
2343 });
2344
2345 if (service) {
2346 xAdd.emplace_back("object_type");
2347 xAdd.emplace_back("service");
2348 xAdd.emplace_back("service_id");
2349 xAdd.emplace_back(GetObjectIdentifier(checkable));
2350 } else {
2351 xAdd.emplace_back("object_type");
2352 xAdd.emplace_back("host");
2353 }
2354
2355 auto endpoint (Endpoint::GetLocalEndpoint());
2356
2357 if (endpoint) {

Callers 1

CommentRemovedHandlerMethod · 0.80

Calls 2

ProduceOneMethod · 0.80
GetCheckableMethod · 0.45

Tested by

no test coverage detected