| 220 | } |
| 221 | |
| 222 | Dictionary::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"), |
nothing calls this directly
no test coverage detected