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

Method RemoveComment

lib/icinga/apiactions.cpp:356–391  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

354}
355
356Dictionary::Ptr ApiActions::RemoveComment(
357 const ConfigObject::Ptr& object,
358 const ApiUser::Ptr&,
359 const Dictionary::Ptr& params
360)
361{
362 ConfigObjectsSharedLock lock (std::try_to_lock);
363
364 if (!lock) {
365 return ApiActions::CreateResult(503, "Icinga is reloading.");
366 }
367
368 auto author (HttpUtility::GetLastParameter(params, "author"));
369 Checkable::Ptr checkable = dynamic_pointer_cast<Checkable>(object);
370
371 if (checkable) {
372 std::set<Comment::Ptr> comments = checkable->GetComments();
373
374 for (const Comment::Ptr& comment : comments) {
375 Comment::RemoveComment(comment->GetName(), true, author);
376 }
377
378 return ApiActions::CreateResult(200, "Successfully removed all comments for object '" + checkable->GetName() + "'.");
379 }
380
381 Comment::Ptr comment = static_pointer_cast<Comment>(object);
382
383 if (!comment)
384 return ApiActions::CreateResult(404, "Cannot remove non-existent comment object.");
385
386 String commentName = comment->GetName();
387
388 Comment::RemoveComment(commentName, true, author);
389
390 return ApiActions::CreateResult(200, "Successfully removed comment '" + commentName + "'.");
391}
392
393Dictionary::Ptr ApiActions::ScheduleDowntime(
394 const ConfigObject::Ptr& object,

Callers

nothing calls this directly

Calls 2

GetCommentsMethod · 0.80
GetNameMethod · 0.45

Tested by

no test coverage detected