function prepareInputForAdd($input) { // Toolbox::logInFile("pm-ack", "acknowledge, prepareInputForAdd, item type : ".$input['itemtype']." / ".$input['items_id']."\n"); if ($this->isExpired()) { Session::addMessageAfterRedirect(__('Acknowledge period has already expired!', 'monitoring'), false, ERROR); return false; } // Check user ... if ($input["users_id"] == NOT_AVAILABLE) { $input["users_id"] = $_SESSION['glpiID']; } $user = new User(); $user->getFromDB($input['users_id']); $item = new $input['itemtype'](); $item->getFromDB($input['items_id']); $host_id = -1; $service_id = -1; if ($input['itemtype'] == 'PluginMonitoringHost') { $host_id = $input['items_id']; } else { $service_id = $input['items_id']; } if ($host_id != -1) { // Acknowledge is to be created ... // ... send information to shinken via webservice $pmShinkenwebservice = new PluginMonitoringShinkenwebservice(); if ($pmShinkenwebservice->sendAcknowledge($host_id, -1, $user->getName(1), $input['comment'], $input['sticky'], $input['notify'], $input['persistent'], 'add')) { // Set host as acknowledged $item->setAcknowledged($input['comment']); $a_services = $item->getServicesID(); if (is_array($a_services)) { foreach ($a_services as $service_id) { // Send acknowledge command for a service to shinken via webservice $pmShinkenwebservice = new PluginMonitoringShinkenwebservice(); if ($pmShinkenwebservice->sendAcknowledge(-1, $service_id, $user->getName(1), $input['comment'], $input['sticky'], $input['notify'], $input['persistent'], 'add')) { // Set service as acknowledged $pmService = new PluginMonitoringService(); $pmService->getFromDB($service_id); // Will force to create a new acknowledgement for a service ... beware of infinite loop in this function ! $pmService->setAcknowledged($input['comment'], true); } } } Session::addMessageAfterRedirect(__('Acknowledge notified to the monitoring application for the host', 'monitoring')); $input['notified'] = 1; } else { Session::addMessageAfterRedirect(__('Acknowledge has not been accepted by the monitoring application for the host', 'monitoring'), false, ERROR); return false; } } else { // Send acknowledge command for a service to shinken via webservice $pmShinkenwebservice = new PluginMonitoringShinkenwebservice(); if ($pmShinkenwebservice->sendAcknowledge(-1, $service_id, $user->getName(1), $input['comment'], $input['sticky'], $input['notify'], $input['persistent'], 'add')) { // Set service as acknowledged $pmService = new PluginMonitoringService(); $pmService->getFromDB($service_id); // Do not create a new acknowledgement for a service ... false will simply update PMService table ! $pmService->setAcknowledged($input['comment'], false); Session::addMessageAfterRedirect(__('Acknowledge notified to the monitoring application:', 'monitoring')); $input['notified'] = 1; } else { Session::addMessageAfterRedirect(__('Acknowledge has not been accepted by the monitoring application:', 'monitoring'), false, ERROR); return false; } } return $input; }