function prepareInputForAdd($input)
 {
     // Toolbox::logInFile("pm-downtime", "Downtime, prepareInputForAdd\n");
     if ($this->isExpired()) {
         Session::addMessageAfterRedirect(__('Downtime period has already expired!', 'monitoring'), false, ERROR);
         return false;
     }
     // Check user ...
     if ($input["users_id"] == NOT_AVAILABLE) {
         $input["users_id"] = $_SESSION['glpiID'];
     }
     // Compute duration in seconds
     if ($input['duration'] == 0) {
         $input['duration_seconds'] = 0;
     } else {
         $multiple = 1;
         if ($input['duration_type'] == 'seconds') {
             $multiple = 1;
         } else {
             if ($input['duration_type'] == 'minutes') {
                 $multiple = 60;
             } else {
                 if ($input['duration_type'] == 'hours') {
                     $multiple = 3600;
                 } else {
                     if ($input['duration_type'] == 'days') {
                         $multiple = 86400;
                     }
                 }
             }
         }
         $input['duration_seconds'] = $multiple * $input['duration'];
     }
     $user = new User();
     $user->getFromDB($input['users_id']);
     // Downtime is to be created ...
     // ... send information to shinken via webservice
     $pmShinkenwebservice = new PluginMonitoringShinkenwebservice();
     if ($pmShinkenwebservice->sendDowntime($input['plugin_monitoring_hosts_id'], -1, $user->getName(1), $input['comment'], $input['flexible'], $input['start_time'], $input['end_time'], $input['duration_seconds'], 'add')) {
         // ... and then send an acknowledge for the host
         if ($pmShinkenwebservice->sendAcknowledge($input['plugin_monitoring_hosts_id'], -1, $user->getName(1), $input['comment'], '1', '1', '1')) {
             // Set host as acknowledged
             $pmHost = new PluginMonitoringHost();
             $pmHost->getFromDB($input['plugin_monitoring_hosts_id']);
             $pmHost->setAcknowledged($input['comment']);
             $a_services = $pmHost->getServicesID();
             if (is_array($a_services)) {
                 foreach ($a_services as $service_id) {
                     // Send downtime for a service to shinken via webservice
                     $pmShinkenwebservice->sendDowntime(-1, $service_id, $user->getName(1), $input['comment'], $input['flexible'], $input['start_time'], $input['end_time'], $input['duration_seconds'], 'add');
                     /*
                                       // Send acknowledge command for a service to shinken via webservice
                                       if ($pmShinkenwebservice->sendAcknowledge(-1,
                                                                                 $service_id,
                                                                                 $user->getName(1),
                                                                                 $input['comment'],
                                                                                 '1', '1', '1')) {
                                          // Set service as acknowledged
                                          $pmService = new PluginMonitoringService();
                                          $pmService->getFromDB($service_id);
                                          $pmService->setAcknowledged($input['comment']);
                                       }
                     */
                 }
             }
         }
         Session::addMessageAfterRedirect(__('Downtime notified to the monitoring application:', 'monitoring'));
         $input['notified'] = 1;
     } else {
         Session::addMessageAfterRedirect(__('Downtime has not been accepted by the monitoring application:', 'monitoring'), false, ERROR);
         return false;
     }
     return $input;
 }
 /**
  * Actions done before the DELETE of the item in the database /
  * Maybe used to add another check for deletion
  *
  * @return bool : true if item need to be deleted else false
  **/
 function pre_deleteItem()
 {
     PluginMonitoringToolbox::logIfExtradebug('pm-ack', "acknowledge, pre_deleteItem : " . $this->fields['id'] . "\n");
     $user = new User();
     $user->getFromDB($this->fields['users_id']);
     $item = new $this->fields['itemtype']();
     $item->getFromDB($this->fields['items_id']);
     $host_id = -1;
     $service_id = -1;
     if ($this->fields['itemtype'] == 'PluginMonitoringHost') {
         $host_id = $this->fields['items_id'];
     } else {
         $service_id = $this->fields['items_id'];
     }
     if ($host_id != -1) {
         // Acknowledge is to be deleted ...
         // ... send information to shinken via webservice
         $pmShinkenwebservice = new PluginMonitoringShinkenwebservice();
         if ($pmShinkenwebservice->sendAcknowledge($host_id, -1, $user->getName(1), '', '', '', '', 'delete')) {
             // Set host as acknowledged
             // $pmHost = new PluginMonitoringHost();
             // $pmHost->getFromDB($this->fields['plugin_monitoring_hosts_id']);
             // $item->setAcknowledged($this->fields['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), '', '', '', '', 'delete')) {
                         // Set service as acknowledged
                         // $pmService = new PluginMonitoringService();
                         // $pmService->getFromDB($service_id);
                         // $pmService->setAcknowledged($this->fields['comment']);
                     }
                 }
             }
             Session::addMessageAfterRedirect(__('Acknowledge deletion notified to the monitoring application:', 'monitoring'));
             $this->fields['notified'] = 1;
         } else {
             Session::addMessageAfterRedirect(__('Acknowledge deletion has not been accepted by the monitoring application:', '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), '', '', '', '', 'delete')) {
             // Set service as acknowledged
             // $pmService = new PluginMonitoringService();
             // $pmService->getFromDB($service_id);
             // $pmService->setAcknowledged($this->fields['comment']);
             Session::addMessageAfterRedirect(__('Acknowledge deletion notified to the monitoring application:', 'monitoring'));
             $this->fields['notified'] = 1;
         } else {
             Session::addMessageAfterRedirect(__('Acknowledge deletion has not been accepted by the monitoring application:', 'monitoring'), false, ERROR);
             // return false;
         }
     }
     return true;
 }
Example #3
0
  ------------------------------------------------------------------------

  @package   Plugin Monitoring for GLPI
  @author    David Durieux
  @co-author 
  @comment   
  @copyright Copyright (c) 2011-2013 Plugin Monitoring for GLPI team
  @license   AGPL License 3.0 or (at your option) any later version
             http://www.gnu.org/licenses/agpl-3.0-standalone.html
  @link      https://forge.indepnet.net/projects/monitoring/
  @since     2013

  ------------------------------------------------------------------------
*/
include "../../../inc/includes.php";
PluginMonitoringProfile::checkRight("check", "w");
Html::header(__('Monitoring', 'monitoring'), $_SERVER["PHP_SELF"], "plugins", "monitoring", "acknowledge");
$pmService = new PluginMonitoringService();
if (isset($_POST['add'])) {
    $pmService->update($_POST);
    // Send acknowledge command to shinken via webservice
    $pmShinkenwebservice = new PluginMonitoringShinkenwebservice();
    $pmShinkenwebservice->sendAcknowledge($_POST['id']);
    // "[date('U')] ACKNOWLEDGE_SVC_PROBLEM;Computer-11-debian;rrrrr-1;1;1;1;glpi;comment ddurieux\n"
    Html::redirect($_POST['referer']);
}
if (isset($_GET['id'])) {
    $pmService->addAcknowledge($_GET['id']);
}
Html::footer();