function sendDowntime($host_id = -1, $service_id = -1, $author = '', $comment = '', $flexible = '0', $start_time = '0', $end_time = '0', $duration = '3600', $operation = '')
 {
     global $DB;
     if ($host_id == -1 && $service_id == -1) {
         return false;
     }
     $pmTag = new PluginMonitoringTag();
     $pmService = new PluginMonitoringService();
     $pmService->getFromDB($service_id);
     $service_description = $pmService->getName(array('shinken' => '1'));
     $pmHost = new PluginMonitoringHost();
     $pmHost->getFromDB($host_id == -1 ? $pmService->getHostID() : $host_id);
     $hostname = $pmHost->getName(true);
     // Downtime an host ...
     $acknowledgeServiceOnly = true;
     $a_fields = array();
     if ($host_id == -1) {
         $tag = PluginMonitoringEntity::getTagByEntities($pmService->getEntityID());
     } else {
         // ... one service of the host.
         $tag = PluginMonitoringEntity::getTagByEntities($pmHost->getEntityID());
     }
     $ip = $pmTag->getIP($tag);
     $auth = $pmTag->getAuth($tag);
     $port = $pmTag->getPort($tag);
     $url = 'http://' . $ip . ':' . $port . '/';
     $action = 'downtime';
     $a_fields = array('action' => empty($operation) ? 'add' : $operation, 'host_name' => $hostname, 'service_description' => $service_description, 'author' => $author, 'comment' => mb_convert_encoding($comment, "iso-8859-1"), 'flexible' => $flexible, 'start_time' => PluginMonitoringServiceevent::convert_datetime_timestamp($start_time), 'end_time' => PluginMonitoringServiceevent::convert_datetime_timestamp($end_time), 'trigger_id' => '0', 'duration' => $duration);
     // Send downtime command ...
     return $this->sendCommand($url, $action, $a_fields, '', $auth);
 }
 static function showService($items_id, $itemtype, $businessrules_id = 0)
 {
     global $LANG;
     if (!empty($items_id)) {
         $item = new $itemtype();
         $item->getFromDB($items_id);
         echo "\n<table width='100%'><tr>";
         echo "<td>";
         echo "<input type='hidden' name='services_id[]' value='" . $items_id . "' />";
         echo "<strong>" . $item->getName() . "</strong>";
         echo " " . $LANG['networking'][25] . " ";
         $pmHost = new PluginMonitoringHost();
         $pmHost->getFromDB($item->fields['plugin_monitoring_hosts_id']);
         $itemtype2 = $pmHost->fields['itemtype'];
         $item2 = new $itemtype2();
         $item2->getFromDB($pmHost->fields['items_id']);
         echo $item2->getLink(1);
         echo "</td><td width='100'>";
         echo "<input type='hidden' name='businessrules_id' value='" . $businessrules_id . "' />";
         echo " <input type='submit' class='submit' name='delete' value='" . $LANG['buttons'][6] . "'";
         echo "</td></tr></table>\n";
     } else {
         echo "\n<table width='100%'><tr>";
         echo "<td class='left'>";
         self::dropdownService($items_id, array('name' => 'type'));
         echo "</td>\n";
         echo "</tr></table>\n";
     }
 }
Пример #3
0
   /**
    * Form to modify acknowledge of an host
    */
   function showUpdateAcknowledgeForm($id=-1) {
      global $CFG_GLPI;

      Session::checkRight("plugin_monitoring_acknowledge", UPDATE);

      if ($id == -1) {
         $pm_Host = $this;
      } else {
         $pm_Host = new PluginMonitoringHost();
         $pm_Host->getFromDB($id);
      }
      $hostname = $pm_Host->getName();

      echo "<form name='form' method='post'
         action='".$CFG_GLPI['root_doc']."/plugins/monitoring/front/acknowledge.form.php'>";

      echo "<input type='hidden' name='host_id' value='$id' />";
      echo "<input type='hidden' name='hostname' value='$hostname' />";
      echo "<input type='hidden' name='hostAcknowledge' value='$hostname' />";

      echo "<table class='tab_cadre_fixe'>";
      echo "<tr class='tab_bg_1'>";
      echo "<th colspan='2'>";
      echo __('Modify acknowledge for the host', 'monitoring').' : '.$pm_Host->getLink();
      echo "</td>";
      echo "</tr>";

      echo "<tr class='tab_bg_1'>";
      echo "<td>";
      echo __('Acknowledge comment', 'monitoring');
      echo "</td>";
      echo "<td>";
      echo "<textarea cols='80' rows='4' name='acknowledge_comment' >".$pm_Host->fields['acknowledge_comment']."</textarea>";
      echo "</td>";
      echo "</tr>";
      echo "<tr class='tab_bg_1'>";
      echo "<td colspan='2' align='center'>";
      echo "<input type='hidden' name='id' value='".$pm_Host->fields['id']."' />";
      echo "<input type='hidden' name='is_acknowledged' value='1' />";
      echo "<input type='hidden' name='acknowledge_users_id' value='".$_SESSION['glpiID']."' />";
      echo "<input type='hidden' name='referer' value='".$_SERVER['HTTP_REFERER']."' />";

      echo "<tr class='tab_bg_1'>";
      echo "<td>";
      echo __('Acknowledge user', 'monitoring');
      echo "</td>";
      echo "<td>";
      $user = new User();
      $user->getFromDB($pm_Host->fields['acknowledge_users_id']);
      echo $user->getName(1);
      echo "</td>";
      echo "</tr>";

      echo "<tr class='tab_bg_1'>";
      echo "<td colspan='3' align='center'>";
      echo "<input type='submit' name='update' value=\"".__('Update acknowledge comment', 'monitoring')."\" class='submit'>";
      echo "</td>";
      echo "</tr>";

      echo "</table>";
      Html::closeForm();
   }
 static function displayHostLine($data)
 {
     global $DB, $CFG_GLPI;
     $pm_Host = new PluginMonitoringHost();
     $pm_Host->getFromDB($data['id']);
     if ($data[3]['displayname'] == '') {
         $data[3]['displayname'] = 'UNKNOWN';
         $data[4]['displayname'] = 'SOFT';
     }
     $shortstate = $pm_Host->getState($data[3]['displayname'], $data[4]['displayname'], $data[6]['displayname'], $pm_Host->isCurrentlyAcknowledged());
     echo "<td>";
     echo $data[0]['displayname'];
     echo "</td>";
     echo "<td>";
     $item = new $data[1]['displayname']();
     echo $item->getTypeName();
     echo "</td>";
     echo "<td>";
     echo "<span>" . $pm_Host->getLink() . "</span>";
     echo "</td>";
     echo "<td class='center'>";
     echo "<div class='page foldtl resource" . $data[3]['displayname'] . " resource" . $data[4]['displayname'] . "'>";
     echo "<div style='vertical-align:middle;'>";
     echo "<span>";
     echo $data[3]['displayname'];
     echo "</span>";
     echo "</div>";
     echo "</div>";
     echo "</td>";
     if (isset($data['host_command_name'])) {
         $scriptName = $CFG_GLPI['root_doc'] . "/plugins/monitoring/scripts/" . $data['host_command_command'];
         $scriptArgs = $data[2]['displayname'] . " " . $data['ip'];
         echo "<td class='center'>";
         echo "<form name='form' method='post'\n            action='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/" . $data['host_command_command'] . ".php'>";
         echo "<input type='hidden' name='host_id' value='" . $data[9]['displayname'] . "' />";
         echo "<input type='hidden' name='host_name' value='" . $data[2]['displayname'] . "' />";
         echo "<input type='hidden' name='host_ip' value='" . $data['ip'] . "' />";
         echo "<input type='hidden' name='host_state' value='" . $data[3]['displayname'] . "' />";
         echo "<input type='hidden' name='host_statetype' value='" . $data[4]['displayname'] . "' />";
         echo "<input type='hidden' name='host_event' value='" . $data[6]['displayname'] . "' />";
         echo "<input type='hidden' name='host_perfdata' value='" . $data[7]['displayname'] . "' />";
         echo "<input type='hidden' name='host_last_check' value='" . $data[5]['displayname'] . "' />";
         echo "<input type='hidden' name='glpi_users_id' value='" . $_SESSION['glpiID'] . "' />";
         echo "<input type='submit' name='host_command' value=\"" . $data['host_command_name'] . "\" class='submit'>";
         Html::closeForm();
         echo "</td>";
     }
     echo "<td class='center'>";
     echo "<div class='page foldtl resource" . $data['host_services_state'] . "'>";
     echo "<div style='vertical-align:middle;'>";
     echo "<span>";
     if (Session::haveRight("plugin_monitoring_service", READ)) {
         $link = $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/service.php?hidesearch=1" . "&criteria[0][field]=1" . "&criteria[0][searchtype]=equals" . "&criteria[0][value]=" . $data[9]['displayname'] . "&itemtype=PluginMonitoringService" . "&start=0'";
         echo '<a href="' . $link . '">' . $data['host_services_state'] . "</a>";
     } else {
         echo '<span>' . $data['host_services_state'] . "</span>";
     }
     if (!empty($data['host_services_state_list'])) {
         echo "&nbsp;" . Html::showToolTip($data['host_services_state_list'], array('display' => false));
     }
     echo "</span>";
     echo "</div>";
     echo "</div>";
     echo "</td>";
     echo "<td>";
     echo $data['ip'];
     echo "</td>";
     echo "<td>";
     echo Html::convDate($data[5]['displayname']) . ' ' . substr($data[5]['displayname'], 11, 8);
     echo "</td>";
     echo "<td>";
     echo $data[6]['displayname'];
     echo "</td>";
     echo "<td>";
     echo $data[7]['displayname'];
     echo "</td>";
     if (Session::haveRight("plugin_monitoring_acknowledge", READ) || Session::haveRight("plugin_monitoring_downtime", READ)) {
         echo "<td>";
         // Manage downtimes for an host
         if (Session::haveRight("plugin_monitoring_downtime", READ)) {
             if ($pm_Host->isInScheduledDowntime()) {
                 $pmDowntime = new PluginMonitoringDowntime();
                 $pmDowntime->getFromDBByQuery("WHERE `" . $pmDowntime->getTable() . "`.`plugin_monitoring_hosts_id` = '" . $pm_Host->getID() . "' ORDER BY end_time DESC LIMIT 1");
                 $downtime_id = $pmDowntime->getID();
                 // Toolbox::logInFile("pm", "Host ".$pm_Host->getName()." is in downtime period \n");
                 if (Session::haveRight("plugin_monitoring_downtime", CREATE)) {
                     echo "<div style='float: left; margin-right: 10px;'>";
                     echo "<span>";
                     echo "<a href='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/downtime.form.php?host_id=" . $data['id'] . "'>" . "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/downtime_scheduled.png'" . " alt='" . htmlspecialchars(__('Edit the downtime scheduled for the host', 'monitoring'), ENT_QUOTES) . "'" . " title='" . htmlspecialchars(__('Edit the downtime scheduled for the host', 'monitoring'), ENT_QUOTES) . "'/>" . "</a>";
                     echo "&nbsp;&nbsp;</span>";
                     echo "</div>";
                 } else {
                     echo "<div style='float: left; margin-right: 10px;'>";
                     echo "<span>";
                     echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/downtime_scheduled.png'" . " alt='" . htmlspecialchars(__('A downtime is scheduled for the host', 'monitoring'), ENT_QUOTES) . "'" . " title='" . htmlspecialchars(__('A downtime is scheduled for the host', 'monitoring'), ENT_QUOTES) . "'/>";
                     echo "&nbsp;&nbsp;</span>";
                     echo "</div>";
                 }
             } else {
                 if (Session::haveRight("plugin_monitoring_downtime", CREATE)) {
                     echo "<div style='float: left; margin-right: 10px;'>";
                     echo "<span>";
                     echo "<a href='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/downtime.form.php?id=-1&host_id=" . $data['id'] . "'>" . "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/downtime_to_schedule.png'" . " alt='" . htmlspecialchars(__('Schedule a downtime for the host', 'monitoring'), ENT_QUOTES) . "'" . " title='" . htmlspecialchars(__('Schedule a downtime for the host', 'monitoring'), ENT_QUOTES) . "'/>" . "</a>";
                     echo "&nbsp;&nbsp;</span>";
                     echo "</div>";
                 }
             }
         }
         echo "<div style='float: left;'>";
         // Manage acknowledgement for an host
         if ($pm_Host->isCurrentlyAcknowledged()) {
             if (Session::haveRight("plugin_monitoring_acknowledge", CREATE)) {
                 echo "<span>";
                 echo "<a href='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/acknowledge.form.php?itemtype=Host&items_id=" . $data['id'] . "'>" . "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/acknowledge_ok.png'" . " alt='" . htmlspecialchars(__('Modify acknowledge comment for the host', 'monitoring'), ENT_QUOTES) . "'" . " title='" . htmlspecialchars(__('Modify acknowledge comment for the host', 'monitoring'), ENT_QUOTES) . "'" . " width='25' height='20'/>" . "</a>";
                 echo "&nbsp;&nbsp;</span>";
             } else {
                 echo "<span>";
                 echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/acknowledge_ok.png'" . " alt='" . htmlspecialchars(__('Host problem has been acknowledged', 'monitoring'), ENT_QUOTES) . "'" . " title='" . htmlspecialchars(__('Host problem has been acknowledged', 'monitoring'), ENT_QUOTES) . "'" . " width='25' height='20'/>";
                 echo "&nbsp;&nbsp;</span>";
             }
             // Display acknowledge data ...
             $pm_Host->getAcknowledge();
         } else {
             if ($shortstate == 'red' || $shortstate == 'yellow' || $shortstate == 'orange' || !empty($data['host_services_state_list'])) {
                 if (Session::haveRight("plugin_monitoring_acknowledge", CREATE)) {
                     echo "<span>";
                     echo "<a href='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/acknowledge.form.php?itemtype=Host&items_id=" . $data['id'] . "'>" . "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/acknowledge_ko.png'" . " alt='" . htmlspecialchars(__('Add an acknowledge for the host and all faulty services of the host', 'monitoring'), ENT_QUOTES) . "'" . " title='" . htmlspecialchars(__('Add an acknowledge for the host and all faulty services of the host', 'monitoring'), ENT_QUOTES) . "'" . " width='25' height='20'/>" . "</a>";
                     echo "&nbsp;&nbsp;</span>";
                 }
             }
         }
         echo "</div>";
         echo "</td>";
     }
 }
Пример #5
0
  @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     2011

  ------------------------------------------------------------------------
*/
include "../../../inc/includes.php";
Session::checkCentralAccess();
Html::header(__('Monitoring', 'monitoring'), $_SERVER["PHP_SELF"], "plugins", "monitoring", "host");
$pmHost = new PluginMonitoringHost();
if (isset($_POST["add"])) {
    if (isset($_POST['items_id']) and $_POST['items_id'] != "0" and $_POST['items_id'] != "" or isset($_POST['is_template']) and $_POST['is_template'] == "1") {
        if (isset($_POST['template_id']) and $_POST['template_id'] > 0) {
            $pmHost->getFromDB($_POST['template_id']);
            $_POST['parenttype'] = $pmHost->fields['parenttype'];
            $_POST['plugin_monitoring_commands_id'] = $pmHost->fields['plugin_monitoring_commands_id'];
            $_POST['plugin_monitoring_checks_id'] = $pmHost->fields['plugin_monitoring_checks_id'];
            $_POST['active_checks_enabled'] = $pmHost->fields['active_checks_enabled'];
            $_POST['passive_checks_enabled'] = $pmHost->fields['passive_checks_enabled'];
            $_POST['calendars_id'] = $pmHost->fields['calendars_id'];
        }
        $hosts_id = $pmHost->add($_POST);
        if (isset($_POST['template_id']) and $_POST['template_id'] > 0) {
            // Add parents
            $pmHost_Host = new PluginMonitoringHost_Host();
            $a_list = $pmHost_Host->find("`plugin_monitoring_hosts_id_1`='" . $_POST['template_id'] . "'");
            foreach ($a_list as $data) {
                $input = array();
                $input['plugin_monitoring_hosts_id_1'] = $hosts_id;
   function showWidgetFrame($id, $reduced_interface=false, $is_minemap=FALSE) {
      global $DB, $CFG_GLPI;

      $this->getFromDB($id);
      $data = $this->fields;

      $ret = $this->getInfoOfCatalog($id);
      $nb_ressources = $ret[0];
      if ($nb_ressources == 0) {
         echo '<div class="ch-item">
            <div>
            <h1>'.__('Nothing to display ...', 'monitoring').'</h1>
            </div>
         </div>';

         return;
      }

      $stateg = $ret[1];
      $hosts_ids = $ret[2];
      $services_ids = $ret[3];
      $hosts_ressources = $ret[4];
      $hosts_states = $ret[5];

      $colorclass = 'ok';
      $count = 0;

      $link = '';
      // Toolbox::logInFile("pm", "stateg $id - ".serialize($stateg)."\n");
      if ($stateg['CRITICAL'] > 0) {
         $count = $stateg['CRITICAL'];
         $colorclass = 'crit';
         $link = $CFG_GLPI['root_doc'].
         "/plugins/monitoring/front/service.php?hidesearch=1"
//                 . "&reset=reset&"
                 . "criteria[0][field]=3"
                 . "&criteria[0][searchtype]=equals"
                 . "&criteria[0][value]=CRITICAL"

                 . "&criteria[1][link]=AND"
                 . "&criteria[1][field]=9"
                 . "&criteris[1][searchtype]=equals"
                 . "&criteria[1][value]=".$id

                 . "&itemtype=PluginMonitoringService"
                 . "&start=0";
      } else if ($stateg['WARNING'] > 0) {
         $count = $stateg['WARNING'];
         $colorclass = 'warn';
         $link = $CFG_GLPI['root_doc'].
         "/plugins/monitoring/front/service.php?hidesearch=1"
//                 . "&reset=reset"
                 . "&criteria[0][field]=3"
                 . "&criteria[0][searchtype]=equals"
                 . "&criteria[0][value]=WARNING"

                 . "&criteria[1][link]=AND"
                 . "&criteria[1][field]=9"
                 . "&criteria[1][searchtype]=equals"
                 . "&criteria[1][value]=".$id

                 . "&criteria[2][link]=OR"
                 . "&criteria[2][field]=3"
                 . "&criteria[2][searchtype]=equals"
                 . "&criteria[2][value]=UNKNOWN"

                 . "&criteria[3][link]=AND"
                 . "&criteria[3][field]=9"
                 . "&criteria[3][searchtype]=equals"
                 . "&criteria[3][value]=".$id

                 . "&criteria[4][link]=OR"
                 . "&criteria[4][field]=3"
                 . "&criteria[4][searchtype]=equals"
                 . "&criteria[4][value]=RECOVERY"

                 . "&criteria[5][link]=AND"
                 . "&criteria[5][field]=9"
                 . "&criteria[5][searchtype]=equals"
                 . "&criteria[5][value]=".$id

                 . "&criteria[6][link]=OR"
                 . "&criteria[6][field]=3"
                 . "&criteria[6][searchtype]=equals"
                 . "&criteria[6][value]=FLAPPING"

                 . "&criteria[7][link]=AND"
                 . "&criteria[7][field]=9"
                 . "&criteria[7][searchtype]=equals"
                 . "&criteria[7][value]=".$id

                 . "&itemtype=PluginMonitoringService"
                 . "&start=0";
      } else {
         $count = $stateg['OK'];
         $count += $stateg['ACKNOWLEDGE'];
         $count += $stateg['UNKNOWN'];
         $link = $CFG_GLPI['root_doc'].
         "/plugins/monitoring/front/service.php?hidesearch=1"
//                 . "&reset=reset"
                 . "&criteria[0][field]=3"
                 . "&criteria[0][searchtype]=equals"
                 . "&criteria[0][value]=OK"

                 . "&criteria[1][link]=AND"
                 . "&criteria[1][field]=9"
                 . "&criteria[1][searchtype]=equals"
                 . "&criteria[1][value]=".$id

                 . "&criteria[2][link]=OR"
                 . "&criteria[2][field]=3"
                 . "&criteria[2][searchtype]=equals"
                 . "&criteria[2][value]=UP"

                 . "&itemtype=PluginMonitoringService"
                 . "&start=0";
      }

      if (Session::haveRight("plugin_monitoring_service", READ)) {
         $link_catalog = $CFG_GLPI['root_doc'].
            "/plugins/monitoring/front/service.php?hidesearch=1"
//                 . "&reset=reset"
                 . "&criteria[0][field]=9"
                 . "&criteria[0][searchtype]=equals"
                 . "&criteria[0][value]=".$id

                 . "&itemtype=PluginMonitoringService"
                 . "&start=0";

         echo '<div class="ch-item">
            <div class="ch-info-'.$colorclass.'">
            <h1><a href="'.$link_catalog.'">'.ucfirst($data['name']);
            if ($data['comment'] != '') {
               echo ' '.$this->getComments();
            }
            echo '</a></h1>
               <p><a href="'.$link.'">'.$count.'</a><font style="font-size: 14px;">/ '.
               ($stateg['CRITICAL'] + $stateg['WARNING'] + $stateg['OK'] + $stateg['ACKNOWLEDGE'] + $stateg['UNKNOWN']).'</font></p>
            </div>
         </div>';
      } else {
         echo '<div class="ch-item">
            <div class="ch-info-'.$colorclass.'">
            <h1>'.ucfirst($data['name']);
            if ($data['comment'] != '') {
               echo ' '.$this->getComments();
            }
            echo '</h1>
               <p>'.$count.'<font style="font-size: 14px;">/ '.
               ($stateg['CRITICAL'] + $stateg['WARNING'] + $stateg['OK'] + $stateg['ACKNOWLEDGE'] + $stateg['UNKNOWN']).'</font></p>
            </div>
         </div>';
      }

      // Get services list ...
      $services = array();
      $i = 0;
      foreach ($hosts_ressources as $resources) {
         foreach ($resources as $resource=>$status) {
            $services[$i++] = $resource;
         }
         break;
      }
      sort($services);

      echo "<div class='minemapdiv' align='center'>"
            ."<a onclick='$(\"#minemapCC-".$id."\").toggle();'>"
            .__('Minemap', 'monitoring')."</a></div>";
      if (!$is_minemap) {
         echo '<div class="minemapdiv" id="minemapCC-'.$id.'" style="display: none; z-index: 1500">';
      } else {
         echo '<div class="minemapdiv" id="minemapCC-'.$id.'">';
      }

      echo '<table class="tab_cadrehov" >';

      // Header with services name and link to services list ...
      echo "<tr>";
      echo "<th colspan='2'>";
      echo __('Hosts', 'monitoring');
      echo "</th>";
      for ($i = 0; $i < count($services); $i++) {
         // Do not display fake host service ...
         if ($services[$i] == '_fake_') continue;

         if (Session::haveRight("plugin_monitoring_service", READ)) {
            $link = $CFG_GLPI['root_doc'].
               "/plugins/monitoring/front/service.php?hidesearch=1"
//                    . "&reset=reset"
                    . "&criteria[0][field]=2"
                    . "&criteria[0][searchtype]=equals"
                    . "&criteria[0][value]=".$services_ids[$services[$i]]

                    . "&itemtype=PluginMonitoringService"
                    . "&start=0'";
            echo '<th class="vertical">';
            echo '<a href="'.$link.'"><div class="rotated-text"><span class="rotated-text__inner">'.$services[$i].'</span></div></a>';
            echo '</th>';
         } else {
            echo '<th class="vertical">';
            echo '<div class="rotated-text"><span class="rotated-text__inner">'.$services[$i].'</span></div>';
            echo '</th>';
         }
      }
      echo '</tr>';

      $pmHost = new PluginMonitoringHost();
      $entityId = -1;
      $overallServicesState = 'OK';
      foreach ($hosts_ressources as $hosts_id=>$resources) {
         // Reduced array or not ?
         if ($reduced_interface and $hosts_states[$hosts_id]) continue;

         $pmHost->getFromDB($hosts_ids[$hosts_id]['id']);
         if ($entityId != $pmHost->fields['entities_id']) {
            if ($entityId != -1) {
               echo "</table>";
               if ($overallServicesState != 'OK') {
                  echo "<script>
                     Ext.onReady(function(){
                        toggleEntity('entity-$id-$entityId');
                     });</script>";
                  $overallServicesState = 'OK';
               }
            }
            // A new sub-table for each entity ...
            $entityId = $pmHost->fields['entities_id'];
            $pmEntity = new Entity();
            $pmEntity->getFromDB($entityId);
            echo "<tr class='tab_bg_1'>";
            echo "<table class='tab_cadrehov' style='height: auto;' id='entity-$id-$entityId' onClick='javascript: toggleEntity(\"entity-$id-$entityId\");'>";
            $overallServicesState = 'OK';
            echo "<tr class='header'><th class='left' style='height:50px;' colspan='".(count($services))."'>".$pmEntity->fields['name']."</th></tr>";
         }
         $field_id = 20;
         if ($hosts_ids[$hosts_id]['itemtype'] == 'Printer') {
            $field_id = 21;
         } else if ($hosts_ids[$hosts_id]['itemtype'] == 'NetworkEquipment') {
            $field_id = 22;
         }

         $link = $CFG_GLPI['root_doc'].
            "/plugins/monitoring/front/service.php?hidesearch=1"
//                 . "&reset=reset"
                 . "&criteria[0][field]=".$field_id.""
                 . "&criteria[0][searchtype]=equals"
                 . "&criteria[0][value]=".$hosts_ids[$hosts_id]['items_id']

                 . "&itemtype=PluginMonitoringService"
                 . "&start=0'";

         if ($hosts_states[$hosts_id]) {
            echo  "<tr class='services tab_bg_2' style='display:none;'>";
         } else {
            echo  "<tr class='services tab_bg_3' style='display:none;'>";
         }
         // echo "<td><div style='width: 5px !important;'>&nbsp;</div></td>";
         if (Session::haveRight("plugin_monitoring_service", READ)) {
            $item = new $hosts_ids[$hosts_id]['itemtype'];
            $item->getFromDB($hosts_ids[$hosts_id]['items_id']);
            echo  "<td class='left'><a href='".$link."'>".$hosts_ids[$hosts_id]['name']."</a> ".$item->getComments()."</td>";
         } else {
            echo  "<td class='left'>".$hosts_ids[$hosts_id]['name']."</td>";
         }
         for ($i = 0; $i < count($services); $i++) {
            if ($services[$i] == '_fake_') continue;

            if ($resources[$services[$i]]['state'] != 'OK') {
               $overallServicesState = $resources[$services[$i]]['state'];
            }
            echo '<td class="serviceState">';
            if (Session::haveRight("plugin_monitoring_service", READ)) {
               $link_service = $link;
               $link_service .= "&link[1]=AND&field[1]=2&searchtype[1]=equals&contains[1]=".
                       $resources[$services[$i]]['plugin_monitoring_components_id'];
               echo '<a href="'.$link_service.'">'.
                        '<div title="'.$resources[$services[$i]]['state'].
                        " - ".$resources[$services[$i]]['last_check']." - ".
                        $resources[$services[$i]]['event'].
                        '" class="service service'.$resources[$services[$i]]['state_type'].' service'.$resources[$services[$i]]['state'].'"></div>'.
                        '</a>';
            } else {
               echo '<div title="'.$resources[$services[$i]]['state'].
                       " - ".$resources[$services[$i]]['last_check']." - ".
                       $resources[$services[$i]]['event'].
                       '" class="service service'.$resources[$services[$i]]['state_type'].' service'.$resources[$services[$i]]['state'].'"></div>';
            }
            echo '</td>';
         }
         echo  '</tr>';
      }
      echo  '</table>';
      echo '</div>';
      if ($overallServicesState != 'OK') {
         echo "<script>
            Ext.onReady(function(){
               toggleEntity('entity-$id-$entityId');
            });</script>";
      }
   }
 /**
  *
  *
  * @param $items_id integer ID
  *
  * @param $host_id integer associated host ID
  * @param $options array
  *
  *@return bool true if form is ok
  *
  **/
 function showForm($items_id = -1, $options = array())
 {
     global $DB, $CFG_GLPI;
     $host_id = -1;
     if (isset($_GET['host_id'])) {
         $host_id = $_GET['host_id'];
     }
     if ($host_id == -1 && $items_id == -1) {
         return false;
     }
     $createDowntime = false;
     $pmHost = new PluginMonitoringHost();
     if ($host_id != -1) {
         $pmHost->getFromDB($host_id);
         if ($pmHost->isInScheduledDowntime()) {
             // If host already in scheduled downtime, show current downtime ...
             $pmDowntime = new PluginMonitoringDowntime();
             $pmDowntime->getFromDBByQuery("WHERE `" . $pmDowntime->getTable() . "`.`plugin_monitoring_hosts_id` = '" . $host_id . "' LIMIT 1");
             $items_id = $pmDowntime->getID();
             $this->getFromDB($items_id);
         } else {
             // .. else create new downtime
             $createDowntime = true;
             $this->getEmpty();
             $this->setDefaultContent($host_id);
         }
     } else {
         $this->getFromDB($items_id);
     }
     // Now ...
     $nowDate = date('Y-m-d');
     $nowTime = date('H:i:s');
     $this->showFormHeader(array('colspan' => '4'));
     $this->isExpired();
     $pmHost = new PluginMonitoringHost();
     $pmHost->getFromDB($this->fields["plugin_monitoring_hosts_id"]);
     $itemtype = $pmHost->getField("itemtype");
     $item = new $itemtype();
     $item->getFromDB($pmHost->getField("items_id"));
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . $item->getTypeName() . "</td>";
     echo "<td>";
     echo "<input type='hidden' name='plugin_monitoring_hosts_id' value='" . $this->fields['plugin_monitoring_hosts_id'] . "' />";
     echo $item->getLink() . "&nbsp;" . $pmHost->getComments();
     echo "</td>";
     echo "<td></td>";
     echo "<td></td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Start time', 'monitoring') . "</td>";
     echo "<td>";
     $date = $this->fields["start_time"];
     Html::showDateTimeField("start_time", array('value' => $date, 'timestep' => 10, 'maybeempty' => false, 'canedit' => $createDowntime, 'mindate' => $nowDate, 'mintime' => $nowTime));
     echo "</td>";
     echo "<td>" . __('Flexible ?', 'monitoring') . "</td>";
     echo "<td>";
     if ($createDowntime) {
         Dropdown::showYesNo('flexible', $this->fields['flexible']);
     } else {
         echo Dropdown::getYesNo($this->fields['flexible']);
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('End time', 'monitoring') . "</td>";
     echo "<td>";
     $date = $this->fields["end_time"];
     Html::showDateTimeField("end_time", array('value' => $date, 'timestep' => 10, 'maybeempty' => false, 'canedit' => $createDowntime, 'mindate' => $nowDate, 'mintime' => $nowTime));
     echo "</td>";
     echo "<td>" . __('Duration', 'monitoring') . "</td>";
     echo "<td>";
     if ($createDowntime) {
         Dropdown::showNumber("duration", array('value' => $this->fields['duration'], 'min' => 1, 'max' => 300));
     } else {
         echo $this->fields['duration'];
     }
     $a_duration_type = array();
     $a_duration_type['seconds'] = __('Second(s)', 'monitoring');
     $a_duration_type['minutes'] = __('Minute(s)', 'monitoring');
     $a_duration_type['hours'] = __('Hour(s)', 'monitoring');
     $a_duration_type['days'] = __('Day(s)', 'monitoring');
     if ($createDowntime) {
         Dropdown::showFromArray("duration_type", $a_duration_type, array('value' => $this->fields['duration_type']));
     } else {
         echo "&nbsp;" . $this->fields['duration_type'];
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Comment', 'monitoring') . "</td>";
     echo "<td >";
     if ($createDowntime) {
         echo "<textarea cols='80' rows='4' name='comment' >" . $this->fields['comment'] . "</textarea>";
     } else {
         echo "<textarea cols='80' rows='4' name='comment' readonly='1' disabled='1' >" . $this->fields['comment'] . "</textarea>";
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('User', 'monitoring') . "</td>";
     echo "<td>";
     echo "<input type='hidden' name='users_id' value='" . $this->fields['users_id'] . "' />";
     echo $this->getUsername();
     echo "</td>";
     echo "<td>" . __('Expired ?', 'monitoring') . "</td>";
     echo "<td>";
     echo Dropdown::getYesNo($this->fields['expired']);
     echo "</td>";
     echo "</tr>";
     if (Ticket::canView()) {
         echo "<tr class='tab_bg_1'>";
         echo "<td colspan='4'>&nbsp;</td>";
         echo "</tr>";
         if ($this->isAssociatedTicket()) {
             echo "<tr class='tab_bg_3'>";
             echo "<td colspan='4'>" . __('Downtime associated ticket', 'monitoring') . "</td>";
             echo "</tr>";
             // Find ticket in DB ...
             $track = new Ticket();
             $track->getFromDB($this->getField("tickets_id"));
             // Display ticket id, name and tracking ...
             $bgcolor = $_SESSION["glpipriority_" . $track->fields["priority"]];
             echo "<tr class='tab_bg_2'>";
             echo "<td class='center' bgcolor='{$bgcolor}'>" . sprintf(__('%1$s: %2$s'), __('ID'), $track->fields["id"]) . "</td>";
             echo "<td class='center'>";
             $showprivate = Session::haveRight("show_full_ticket", 1);
             $link = "<a id='ticket" . $track->fields["id"] . "' href='" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php?id=" . $track->fields["id"];
             $link .= "'>";
             $link .= "<span class='b'>" . $track->getNameID() . "</span></a>";
             $link = sprintf(__('%1$s (%2$s)'), $link, sprintf(__('%1$s - %2$s'), $track->numberOfFollowups($showprivate), $track->numberOfTasks($showprivate)));
             $link = printf(__('%1$s %2$s'), $link, Html::showToolTip($track->fields['content'], array('applyto' => 'ticket' . $track->fields["id"], 'display' => false)));
             echo "</td>";
             echo "</tr>";
         } else {
             if ($createDowntime && Ticket::canCreate()) {
                 echo "<tr class='tab_bg_3'>";
                 echo "<td colspan='4'>" . __('Associated ticket (no declared category implies no ticket created):', 'monitoring') . "</td>";
                 echo "</tr>";
                 echo "<input type='hidden' name='redirect' value='" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php' />";
                 echo "<input type='hidden' name='itemtype' value='" . $pmHost->getField("itemtype") . "' />";
                 echo "<input type='hidden' name='items_id' value='" . $pmHost->getField("items_id") . "' />";
                 echo '<input type="hidden" name="entities_id" value="' . $item->fields['entities_id'] . '" />';
                 $item = new $itemtype();
                 $item->getFromDB($pmHost->getField("items_id"));
                 echo "<input type='hidden' name='locations_id' value='" . $item->getField("locations_id") . "' />";
                 /*
                             // Find SLA ...
                             $sla = new Sla();
                             $slas = current($sla->find("`name` LIKE '%proactive%' LIMIT 1"));
                             $sla_id = isset($slas['id']) ? $slas['id'] : 0;
                 
                             echo "<tr class='tab_bg_3'>";
                             echo "<td>".__('Ticket SLA:', 'monitoring')."</td>";
                             echo "<td colspan='3'>";
                             Sla::dropdown(array('value'  => $sla_id));
                             echo "</td>";
                             echo "</tr>";
                 */
                 // Ticket type ...
                 echo "<tr class='tab_bg_3'>";
                 echo "<td>" . __('Ticket type:', 'monitoring') . "</td>";
                 echo "<td colspan='3'>";
                 Ticket::dropdownType("type", array('value' => Ticket::INCIDENT_TYPE));
                 echo "</td>";
                 echo "</tr>";
                 // Find category ...
                 $category = new ITILCategory();
                 $categories = current($category->find("`name` LIKE '%incident%' LIMIT 1"));
                 $category_id = isset($categories['id']) ? $categories['id'] : 0;
                 /*
                             echo "
                             <script>
                             function changeCategory() {
                                alert(document.getElementById('dropdown_itilcategories_idcategory'));
                                alert($('#dropdown_itilcategories_idcategory').val());
                             }
                             </script>
                             ";
                 */
                 echo "<tr class='tab_bg_3'>";
                 echo "<td>" . __('Ticket category:', 'monitoring') . "</td>";
                 echo "<td colspan='3'>";
                 ITILCategory::dropdown(array('value' => $category_id));
                 /*
                             ITILCategory::dropdown(array(
                                'value'     => $category_id,
                                'rand'      => 'category',
                                'on_change' => 'changeCategory();'
                             ));
                 */
                 echo "</td>";
                 echo "</tr>";
             } else {
                 echo "<tr class='tab_bg_3'>";
                 echo "<td colspan='4'>" . __('No associated ticket for this downtime', 'monitoring') . "</td>";
                 echo "</tr>";
             }
         }
     }
     $this->showFormButtons(array('canedit' => $createDowntime));
     return true;
 }