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

Method AcknowledgeProblem

lib/icinga/apiactions.cpp:222–285  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

220}
221
222Dictionary::Ptr ApiActions::AcknowledgeProblem(
223 const ConfigObject::Ptr& object,
224 const ApiUser::Ptr&,
225 const Dictionary::Ptr& params
226)
227{
228 Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
229
230 if (!checkable)
231 return ApiActions::CreateResult(404, "Cannot acknowledge problem for non-existent object.");
232
233 if (!params->Contains("author") || !params->Contains("comment"))
234 return ApiActions::CreateResult(400, "Acknowledgements require author and comment.");
235
236 AcknowledgementType sticky = AcknowledgementNormal;
237 bool notify = false;
238 bool persistent = false;
239 double timestamp = 0.0;
240
241 if (params->Contains("sticky") && HttpUtility::GetLastParameter(params, "sticky"))
242 sticky = AcknowledgementSticky;
243 if (params->Contains("notify"))
244 notify = HttpUtility::GetLastParameter(params, "notify");
245 if (params->Contains("persistent"))
246 persistent = HttpUtility::GetLastParameter(params, "persistent");
247 if (params->Contains("expiry")) {
248 timestamp = HttpUtility::GetLastParameter(params, "expiry");
249
250 if (timestamp <= Utility::GetTime())
251 return ApiActions::CreateResult(409, "Acknowledgement 'expiry' timestamp must be in the future for object " + checkable->GetName());
252 } else
253 timestamp = 0;
254
255 ObjectLock oLock (checkable);
256
257 Host::Ptr host;
258 Service::Ptr service;
259 tie(host, service) = GetHostService(checkable);
260
261 if (!service) {
262 if (host->GetState() == HostUp)
263 return ApiActions::CreateResult(409, "Host " + checkable->GetName() + " is UP.");
264 } else {
265 if (service->GetState() == ServiceOK)
266 return ApiActions::CreateResult(409, "Service " + checkable->GetName() + " is OK.");
267 }
268
269 if (checkable->IsAcknowledged()) {
270 return ApiActions::CreateResult(409, (service ? "Service " : "Host ") + checkable->GetName() + " is already acknowledged.");
271 }
272
273 ConfigObjectsSharedLock lock (std::try_to_lock);
274
275 if (!lock) {
276 return ApiActions::CreateResult(503, "Icinga is reloading.");
277 }
278
279 Comment::AddComment(checkable, CommentAcknowledgement, HttpUtility::GetLastParameter(params, "author"),

Callers

nothing calls this directly

Calls 4

IsAcknowledgedMethod · 0.80
ContainsMethod · 0.45
GetNameMethod · 0.45
GetStateMethod · 0.45

Tested by

no test coverage detected