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

Method AddComment

lib/icinga/apiactions.cpp:314–354  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

312}
313
314Dictionary::Ptr ApiActions::AddComment(
315 const ConfigObject::Ptr& object,
316 const ApiUser::Ptr&,
317 const Dictionary::Ptr& params
318)
319{
320 Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
321
322 if (!checkable)
323 return ApiActions::CreateResult(404, "Cannot add comment for non-existent object");
324
325 if (!params->Contains("author") || !params->Contains("comment"))
326 return ApiActions::CreateResult(400, "Comments require author and comment.");
327
328 double timestamp = 0.0;
329
330 if (params->Contains("expiry")) {
331 timestamp = HttpUtility::GetLastParameter(params, "expiry");
332 }
333
334 ConfigObjectsSharedLock lock (std::try_to_lock);
335
336 if (!lock) {
337 return ApiActions::CreateResult(503, "Icinga is reloading.");
338 }
339
340 Comment::Ptr comment = Comment::AddComment(checkable, CommentUser,
341 HttpUtility::GetLastParameter(params, "author"),
342 HttpUtility::GetLastParameter(params, "comment"), false, timestamp);
343
344 String commentName = comment->GetName();
345
346 Dictionary::Ptr additional = new Dictionary({
347 { "name", commentName },
348 { "legacy_id", comment->GetLegacyId() }
349 });
350
351 return ApiActions::CreateResult(200, "Successfully added comment '"
352 + commentName + "' for object '" + checkable->GetName()
353 + "'.", additional);
354}
355
356Dictionary::Ptr ApiActions::RemoveComment(
357 const ConfigObject::Ptr& object,

Callers

nothing calls this directly

Calls 2

ContainsMethod · 0.45
GetNameMethod · 0.45

Tested by

no test coverage detected