static function isThisItemCheckRuleNetworkport($parm)
 {
     global $DB;
     $pmComponentscatalog_rule = new self();
     $pmService = new PluginMonitoringService();
     $pmSearch = new PluginMonitoringSearch();
     $a_networkports_id = array();
     if (get_class($parm) == 'PluginMonitoringNetworkport') {
         $a_networkports_id[$parm->fields['networkports_id']] = $parm->fields['items_id'];
     } else {
         if (get_class($parm) == 'NetworkEquipment') {
             $query = "SELECT * FROM `glpi_plugin_monitoring_networkports`\n            WHERE `items_id`='" . $parm->fields['id'] . "'";
             $result = $DB->query($query);
             while ($data = $DB->fetch_array($result)) {
                 $a_networkports_id[$data['networkports_id']] = $parm->fields['id'];
             }
         }
     }
     foreach ($a_networkports_id as $networkports_id => $networkequipments_id) {
         $a_find = array();
         $query = "SELECT * FROM `" . $pmComponentscatalog_rule->getTable() . "`\n            WHERE `itemtype`='PluginMonitoringNetworkport'";
         $result = $DB->query($query);
         $get_tmp = array();
         if (isset($_GET)) {
             $get_tmp = $_GET;
         }
         while ($data = $DB->fetch_array($result)) {
             if (isset($_SESSION["glpisearchcount"][$data['itemtype']])) {
                 unset($_SESSION["glpisearchcount"][$data['itemtype']]);
             }
             if (isset($_SESSION["glpisearchcount2"][$data['itemtype']])) {
                 unset($_SESSION["glpisearchcount2"][$data['itemtype']]);
             }
             $_GET = importArrayFromDB($data['condition']);
             $_GET["glpisearchcount"] = count($_GET['field']);
             if (isset($_GET['field2'])) {
                 $_GET["glpisearchcount2"] = count($_GET['field2']);
             }
             if (!isset($_SESSION['glpiactiveentities_string'])) {
                 $_SESSION['glpiactiveentities_string'] = $parm->fields['entities_id'];
             }
             Search::manageGetValues($data['itemtype']);
             $resultr = $pmSearch->constructSQL("PluginMonitoringNetworkport", $_GET, $networkports_id);
             if ($DB->numrows($resultr) > 0) {
                 $a_find[$data['plugin_monitoring_componentscalalog_id']][$networkports_id] = 1;
             } else {
                 if (!isset($a_find[$data['plugin_monitoring_componentscalalog_id']][$networkports_id])) {
                     $a_find[$data['plugin_monitoring_componentscalalog_id']][$networkports_id] = 0;
                 }
             }
         }
         if (count($get_tmp) > 0) {
             $_GET = $get_tmp;
         }
         $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host();
         foreach ($a_find as $componentscalalog_id => $datan) {
             foreach ($datan as $networkports_id => $is_present) {
                 // Get all networports in this rule
                 if ($is_present == '0') {
                     // * Remove from dynamic if present
                     $query = "SELECT `glpi_plugin_monitoring_services`.`id`,\n                        `glpi_plugin_monitoring_componentscatalogs_hosts`.`id` as hid\n                        FROM `glpi_plugin_monitoring_services`\n                     LEFT JOIN `glpi_plugin_monitoring_componentscatalogs_hosts` ON\n                        `plugin_monitoring_componentscatalogs_hosts_id` = `glpi_plugin_monitoring_componentscatalogs_hosts`.`id`\n                     WHERE `plugin_monitoring_componentscalalog_id`='" . $componentscalalog_id . "'\n                        AND `itemtype`='NetworkEquipment'\n                        AND `items_id`='" . $networkequipments_id . "'\n                        AND `is_static`='0'\n                        AND `networkports_id`='" . $networkports_id . "'";
                     $result = $DB->query($query);
                     while ($data = $DB->fetch_array($result)) {
                         $pmComponentscatalog_Host->getFromDB($data['hid']);
                         $_SESSION['plugin_monitoring_hosts'] = $pmComponentscatalog_Host->fields;
                         $pmService->delete(array('id' => $data['id']));
                     }
                 } else {
                     //  add if not present
                     // * Add componentscatalogs_hosts if not exist
                     $componentscatalogs_hosts_id = 0;
                     $query = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts`\n                     WHERE `plugin_monitoring_componentscalalog_id`='" . $componentscalalog_id . "'\n                        AND `itemtype`='NetworkEquipment'\n                        AND `items_id`='" . $networkequipments_id . "'\n                           LIMIT 1";
                     $result = $DB->query($query);
                     if ($DB->numrows($result) == '0') {
                         $input = array();
                         $input['plugin_monitoring_componentscalalog_id'] = $componentscalalog_id;
                         $input['is_static'] = '0';
                         $input['itemtype'] = "NetworkEquipment";
                         $input['items_id'] = $networkequipments_id;
                         $componentscatalogs_hosts_id = $pmComponentscatalog_Host->add($input);
                     } else {
                         $a_componentscatalogs_hosts = $DB->fetch_assoc($result);
                         $componentscatalogs_hosts_id = $a_componentscatalogs_hosts['id'];
                     }
                     // * Add service if not exist
                     $pmComponentscatalog_Host->linkComponentsToItem($componentscalalog_id, $componentscatalogs_hosts_id, $networkports_id);
                 }
             }
         }
     }
 }
   static function getServicesList($statetype, $view) {
      global $DB;

      $services = array();

      if ($view == 'Ressources') {

         switch ($statetype) {

            case "ok":
               $query = "SELECT * FROM `glpi_plugin_monitoring_services`
                  LEFT JOIN `glpi_plugin_monitoring_componentscatalogs_hosts`
                     ON `plugin_monitoring_componentscatalogs_hosts_id`=
                        `glpi_plugin_monitoring_componentscatalogs_hosts`.`id`
                  WHERE (`state`='OK' OR `state`='UP') AND `state_type`='HARD'";
               $result = $DB->query($query);
               while ($data=$DB->fetch_array($result)) {
                  $itemtype = $data['itemtype'];
                  $item = new $itemtype();
                  $item->getFromDB($data['items_id']);

                  $services[] = "(".$itemtype.") ".$item->getName()."\n=> ".$data['name'];
               }
               break;

            case "warning":
               $query = "SELECT * FROM `glpi_plugin_monitoring_services`
                  LEFT JOIN `glpi_plugin_monitoring_componentscatalogs_hosts`
                     ON `plugin_monitoring_componentscatalogs_hosts_id`=
                        `glpi_plugin_monitoring_componentscatalogs_hosts`.`id`
                  WHERE (`state`='WARNING' OR `state`='UNKNOWN' OR `state`='RECOVERY' OR `state`='FLAPPING' OR `state` IS NULL)
                    AND `state_type`='HARD'";
               $result = $DB->query($query);
               while ($data=$DB->fetch_array($result)) {
                  $itemtype = $data['itemtype'];
                  $item = new $itemtype();
                  $item->getFromDB($data['items_id']);

                  $services[] = "(".$itemtype.") ".$item->getName()."\n=> ".$data['name'];
               }
               break;

            case "critical":
               $query = "SELECT * FROM `glpi_plugin_monitoring_services`
                  LEFT JOIN `glpi_plugin_monitoring_componentscatalogs_hosts`
                     ON `plugin_monitoring_componentscatalogs_hosts_id`=
                        `glpi_plugin_monitoring_componentscatalogs_hosts`.`id`
                  WHERE (`state`='DOWN' OR `state`='UNREACHABLE' OR `state`='CRITICAL' OR `state`='DOWNTIME')
                    AND `state_type`='HARD'";
               $result = $DB->query($query);
               while ($data=$DB->fetch_array($result)) {
                  $itemtype = $data['itemtype'];
                  $item = new $itemtype();
                  $item->getFromDB($data['items_id']);

                  $services[] = "(".$itemtype.") ".$item->getName()."\n=> ".$data['name'];
               }
               break;
         }

      } else if ($view == 'Componentscatalog') {
         $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host();
         $queryCat = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs`";
         $resultCat = $DB->query($queryCat);
         while ($data=$DB->fetch_array($resultCat)) {

            $query = "SELECT * FROM `".$pmComponentscatalog_Host->getTable()."`
               WHERE `plugin_monitoring_componentscalalog_id`='".$data['id']."'";
            $result = $DB->query($query);
            $state = array();
            $state['ok'] = 0;
            $state['warning'] = 0;
            $state['critical'] = 0;
            while ($dataComponentscatalog_Host=$DB->fetch_array($result)) {

               $state['ok'] += countElementsInTable("glpi_plugin_monitoring_services",
                       "(`state`='OK' OR `state`='UP') AND `state_type`='HARD'
                          AND `plugin_monitoring_componentscatalogs_hosts_id`='".$dataComponentscatalog_Host['id']."'");


               $state['warning'] += countElementsInTable("glpi_plugin_monitoring_services",
                       "(`state`='WARNING' OR `state`='UNKNOWN' OR `state`='RECOVERY' OR `state`='FLAPPING' OR `state` IS NULL)
                          AND `state_type`='HARD'
                          AND `plugin_monitoring_componentscatalogs_hosts_id`='".$dataComponentscatalog_Host['id']."'");

               $state['critical'] += countElementsInTable("glpi_plugin_monitoring_services",
                       "(`state`='DOWN' OR `state`='UNREACHABLE' OR `state`='CRITICAL' OR `state`='DOWNTIME')
                          AND `state_type`='HARD'
                          AND `plugin_monitoring_componentscatalogs_hosts_id`='".$dataComponentscatalog_Host['id']."'");

            }
            if ($state['critical'] > 0) {
               if ($statetype == 'critical') {
                  $services[] = "(Catalog) ".$data['name'];
               }
            } else if ($state['warning'] > 0) {
               if ($statetype == 'warning') {
                  $services[] = "(Catalog) ".$data['name'];
               }
            } else if ($state['ok'] > 0) {
               if ($statetype == 'ok') {
                  $services[] = "(Catalog) ".$data['name'];
               }
            }
         }
      } else if ($view == 'Businessrules') {

      }
      return $services;
   }
 function showWidget($id)
 {
     global $LANG, $DB, $CFG_GLPI;
     $pmService = new PluginMonitoringService();
     $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host();
     $input = '';
     $this->getFromDB($id);
     $data = $this->fields;
     $input .= '<table  class="tab_cadre_fixe" style="width:158px;">';
     $input .= '<tr class="tab_bg_1">';
     $input .= '<th colspan="2" style="font-size:18px;" height="60">';
     $input .= $data['name'] . "&nbsp;";
     $input .= '</th>';
     $input .= '</tr>';
     $stateg = array();
     $stateg['OK'] = 0;
     $stateg['WARNING'] = 0;
     $stateg['CRITICAL'] = 0;
     $a_gstate = array();
     $nb_ressources = 0;
     $query = "SELECT * FROM `" . $pmComponentscatalog_Host->getTable() . "`\n         WHERE `plugin_monitoring_componentscalalog_id`='" . $data['id'] . "'";
     $result = $DB->query($query);
     while ($dataComponentscatalog_Host = $DB->fetch_array($result)) {
         $queryService = "SELECT * FROM `" . $pmService->getTable() . "`\n            WHERE `plugin_monitoring_componentscatalogs_hosts_id`='" . $dataComponentscatalog_Host['id'] . "'\n               AND `entities_id` IN (" . $_SESSION['glpiactiveentities_string'] . ")";
         $resultService = $DB->query($queryService);
         while ($dataService = $DB->fetch_array($resultService)) {
             $nb_ressources++;
             $state = array();
             $state['OK'] = 0;
             $state['WARNING'] = 0;
             $state['CRITICAL'] = 0;
             if ($dataService['state_type'] != "HARD") {
                 $a_gstate[$dataService['id']] = "OK";
             } else {
                 switch ($dataService['state']) {
                     case 'UP':
                     case 'OK':
                         $state['OK']++;
                         break;
                     case 'DOWN':
                     case 'UNREACHABLE':
                     case 'CRITICAL':
                     case 'DOWNTIME':
                         $state['CRITICAL']++;
                         break;
                     case 'WARNING':
                     case 'UNKNOWN':
                     case 'RECOVERY':
                     case 'FLAPPING':
                         $state['WARNING']++;
                         break;
                 }
                 if ($state['CRITICAL'] >= 1) {
                     $a_gstate[$dataService['id']] = "CRITICAL";
                 } else {
                     if ($state['WARNING'] >= 1) {
                         $a_gstate[$dataService['id']] = "WARNING";
                     } else {
                         $a_gstate[$dataService['id']] = "OK";
                     }
                 }
             }
         }
     }
     foreach ($a_gstate as $value) {
         $stateg[$value]++;
     }
     $input .= '<tr class="tab_bg_1">';
     $input .= '<td>';
     $input .= $LANG['plugin_monitoring']['service'][0] . "&nbsp;:";
     $input .= '</td>';
     $input .= '<th align="center" height="40" width="50%">';
     $link = $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/service.php?reset=reset&field[0]=8&searchtype[0]=equals&contains[0]=" . $id . "&itemtype=PluginMonitoringService&start=0&glpi_tab=3";
     $input .= '<a href="' . $link . '">' . $nb_ressources . '</a>';
     $input .= '</th>';
     $input .= '</tr>';
     $background = '';
     $count = 0;
     $link = '';
     if ($stateg['CRITICAL'] > 0) {
         $count = $stateg['CRITICAL'];
         $background = 'background="' . $CFG_GLPI['root_doc'] . '/plugins/monitoring/pics/bg_critical.png"';
         $link = $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/service.php?reset=reset&field[0]=3&searchtype[0]=equals&contains[0]=CRITICAL" . "&link[1]=AND&field[1]=8&searchtype[1]=equals&contains[1]=" . $id . "&link[2]=OR&field[2]=3&searchtype[2]=equals&contains[2]=DOWN" . "&link[3]=AND&field[3]=8&searchtype[3]=equals&contains[3]=" . $id . "&link[4]=OR&field[4]=3&searchtype[4]=equals&contains[4]=UNREACHABLE" . "&link[5]=AND&field[5]=8&searchtype[5]=equals&contains[5]=" . $id . "&itemtype=PluginMonitoringService&start=0&glpi_tab=3";
     } else {
         if ($stateg['WARNING'] > 0) {
             $count = $stateg['WARNING'];
             $background = 'background="' . $CFG_GLPI['root_doc'] . '/plugins/monitoring/pics/bg_warning.png"';
             $link = $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/service.php?reset=reset&field[0]=3&searchtype[0]=equals&contains[0]=WARNING" . "&link[1]=AND&field[1]=8&searchtype[1]=equals&contains[1]=" . $id . "&link[2]=OR&field[2]=3&searchtype[2]=equals&contains[2]=UNKNOWN" . "&link[3]=AND&field[3]=8&searchtype[3]=equals&contains[3]=" . $id . "&link[4]=OR&field[4]=3&searchtype[4]=equals&contains[4]=RECOVERY" . "&link[5]=AND&field[5]=8&searchtype[5]=equals&contains[5]=" . $id . "&link[6]=OR&field[6]=3&searchtype[6]=equals&contains[6]=FLAPPING" . "&link[7]=AND&field[7]=8&searchtype[7]=equals&contains[7]=" . $id . "&itemtype=PluginMonitoringService&start=0&glpi_tab=3";
         } else {
             if ($stateg['OK'] > 0) {
                 $count = $stateg['OK'];
                 $background = 'background="' . $CFG_GLPI['root_doc'] . '/plugins/monitoring/pics/bg_ok.png"';
                 $link = $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/service.php?reset=reset&field[0]=3&searchtype[0]=equals&contains[0]=OK" . "&link[1]=AND&field[1]=8&searchtype[1]=equals&contains[1]=" . $id . "&link[2]=OR&field[2]=3&searchtype[2]=equals&contains[2]=UP" . "&itemtype=PluginMonitoringService&start=0&glpi_tab=3";
             }
         }
     }
     $input .= "<tr " . $background . ">";
     $input .= '<th style="background-color:transparent;" ' . $background . ' colspan="2" height="100">';
     $input .= '<a href="' . $link . '"><font style="font-size: 52px; color:black">' . $count . '</font></a>';
     $input .= '</th>';
     $input .= '</tr>';
     $input .= '</table>';
     return $input;
 }
Example #4
0
   function post_purgeItem() {

      $pmLog = new PluginMonitoringLog();

      $input = array();
      $input['itemtype'] = "PluginMonitoringService";
      $input['items_id'] = $this->fields['id'];
      $input['action'] = "delete";

      if (isset($_SESSION['plugin_monitoring_hosts'])
              && isset($_SESSION['plugin_monitoring_hosts']['itemtype'])) {
         $itemtype = $_SESSION['plugin_monitoring_hosts']['itemtype'];
         $item = new $itemtype();
         $item->getFromDB($_SESSION['plugin_monitoring_hosts']['items_id']);

         if (isset($_SESSION['plugin_monitoring_hosts']['id'])) {
            $input['value'] = "Service ".$this->fields['name']." of ".$item->getTypeName()." ".$item->getName();
         } else {
            $input['value'] = "Service ".$this->fields['name']." of port of ";
         }
         $pmLog->add($input);
      }
      unset($_SESSION['plugin_monitoring_hosts']);

      if ($this->fields['networkports_id'] > 0) {
         // Delete componentscatalog_host if no networkports in services
         if (countElementsInTable(
                 'glpi_plugin_monitoring_services',
                 "`plugin_monitoring_components_id`='".$this->fields['plugin_monitoring_components_id']."'
                  AND `networkports_id`>0
                  AND `plugin_monitoring_componentscatalogs_hosts_id`='".$this->fields['plugin_monitoring_componentscatalogs_hosts_id']."'") == 0) {
            $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host();
            $pmComponentscatalog_Host->getFromDB($this->fields['plugin_monitoring_componentscatalogs_hosts_id']);
            if ($pmComponentscatalog_Host->fields['is_static'] == 0) {
               $pmComponentscatalog_Host->delete($pmComponentscatalog_Host->fields);
            }
         }
      }
   }
    switch ($_POST['glpi_tab']) {
        case -1:
            break;
        case 1:
            $pmComponentscatalog_Component = new PluginMonitoringComponentscatalog_Component();
            $pmComponentscatalog_Component->showComponents($_POST['id']);
            break;
        case 2:
            $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host();
            $pmComponentscatalog_Host->showHosts($_POST['id'], 1);
            break;
        case 3:
            $pmComponentscatalog_rule = new PluginMonitoringComponentscatalog_rule();
            $pmComponentscatalog_rule->showRules($_POST['id']);
            break;
        case 4:
            $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host();
            $pmComponentscatalog_Host->showHosts($_POST['id'], 0);
            break;
        case 5:
            $pmContact_Item = new PluginMonitoringContact_Item();
            $pmContact_Item->showContacts("PluginMonitoringComponentscatalog", $_POST['id']);
            break;
        case 6:
            $pmUnavaibility = new PluginMonitoringUnavaibility();
            $pmUnavaibility->displayComponentscatalog($_POST['id']);
            break;
        default:
    }
}
ajaxFooter();
 function post_addItem()
 {
     global $DB;
     $pmLog = new PluginMonitoringLog();
     $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host();
     $input = array();
     $input['itemtype'] = "PluginMonitoringService";
     $input['items_id'] = $this->fields['id'];
     $input['action'] = "add";
     $pmComponentscatalog_Host->getFromDB($this->fields['plugin_monitoring_componentscatalogs_hosts_id']);
     $itemtype = $pmComponentscatalog_Host->fields['itemtype'];
     $item = new $itemtype();
     $item->getFromDB($pmComponentscatalog_Host->fields['items_id']);
     $input['value'] = "New service " . $this->fields['name'] . " for " . $item->getTypeName() . " " . $item->getName();
     $pmLog->add($input);
 }
 function displayItem($data, $config)
 {
     global $CFG_GLPI, $LANG;
     $itemtype = $data['itemtype'];
     $item = new $itemtype();
     $content = '';
     $title = $item->getTypeName();
     $event = '';
     $width = '';
     if ($itemtype == "PluginMonitoringService") {
         $content = $item->showWidget($data['items_id'], $data['extra_infos']);
         $title .= " : " . Dropdown::getDropdownName(getTableForItemType('PluginMonitoringComponent'), $item->fields['plugin_monitoring_components_id']);
         $title .= ' ' . $LANG['networking'][25] . ' ';
         $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host();
         $pmComponentscatalog_Host->getFromDB($item->fields["plugin_monitoring_componentscatalogs_hosts_id"]);
         if (isset($pmComponentscatalog_Host->fields['itemtype']) and $pmComponentscatalog_Host->fields['itemtype'] != '') {
             $itemtype2 = $pmComponentscatalog_Host->fields['itemtype'];
             $item2 = new $itemtype2();
             $item2->getFromDB($pmComponentscatalog_Host->fields['items_id']);
             $title .= $item2->getName() . " (" . $item2->getTypeName() . ")";
         }
         $width = "width: 702,";
     } else {
         if ($itemtype == "PluginMonitoringWeathermap") {
             $content = $item->showWidget($data['items_id'], $data['extra_infos']);
             $event = ", " . $item->widgetEvent($data['items_id']);
             $title .= " : " . Dropdown::getDropdownName(getTableForItemType('PluginMonitoringWeathermap'), $data['items_id']);
             $item->getFromDB($data['items_id']);
             $width = "width:" . $item->fields['width'] * $data['extra_infos'] / 100 . ",";
         } else {
             $content = $item->showWidget($data['items_id']);
             if ($data['itemtype'] == 'PluginMonitoringServicescatalog') {
                 $width = "width: 202,";
             } else {
                 $width = "width: 160,";
             }
         }
     }
     echo "<script>\n         var left = 0;\n         var top = 0;\n         var obj = document.getElementById('panel');\n         if (obj.offsetParent) {\n           do {\n             left += obj.offsetLeft;\n             top += obj.offsetTop;\n           } while (obj = obj.offsetParent);\n         }\n\n        var item" . $data['id'] . " = new Ext.Panel({\n             closable: true,           \n             title: '" . $title . "',\n             x: " . $data['x'] . ",\n             y: " . $data['y'] . ",\n             html       : '" . $content . "',\n             baseCls : 'x-panel',\n             layout : 'fit',\n             renderTo: Ext.getBody(),\n             floating: false,\n             frame: false,\n             " . $width . "\n             autoHeight  : true,\n             layout: 'fit',\n             draggable: {\n                 //Config option of Ext.Panel.DD class.\n                 //It's a floating Panel, so do not show a placeholder proxy in the original position.\n                 insertProxy: false,\n\n                 //Called for each mousemove event while dragging the DD object.\n                 onDrag : function(e){\n                     //Record the x,y position of the drag proxy so that we can\n                     //position the Panel at end of drag.\n                     var el = this.proxy.getEl();\n                     this.x = el.getLeft(true) - left - 5;\n                     this.y = el.getTop(true) - top - 5;\n\n\n                     //Keep the Shadow aligned if there is one.\n                     var s = this.panel.getEl().shadow;\n                     if (s) {\n                         s.realign(this.x, this.y, pel.getWidth(), pel.getHeight());\n                     }\n                 },\n\n                 //Called on the mouseup event.\n                 endDrag : function(e){\n                     this.panel.setPosition(this.x, this.y);\n";
     if ($config == '1') {
         echo "      Ext.get('updatecoordonates').load({\n                        url: '" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/ajax/displayview_itemcoordinates.php',\n                        scripts: true,\n                        params:'id=" . $data['id'] . "&x=' + (this.x)  + '&y=' + (this.y)\n                     });\n";
         echo "      if (this.x < 1) {\n                        this.panel.destroy();\n                     }\n                     if (this.y < 0) {\n                        this.panel.destroy();\n                     }\n            \n            ";
     }
     echo "      }\n             }\n             " . $event . "\n         });\n     </script>";
     //.show()
 }
Example #8
0
 function displayCounters($type, $display = 1)
 {
     global $DB, $CFG_GLPI;
     $ok = 0;
     $warningdata = 0;
     $warningconnection = 0;
     $critical = 0;
     $ok_soft = 0;
     $warningdata_soft = 0;
     $warningconnection_soft = 0;
     $critical_soft = 0;
     $acknowledge = 0;
     $play_sound = 0;
     if ($type == 'Ressources') {
         $ok = countElementsInTable("glpi_plugin_monitoring_services", "(`state`='OK' OR `state`='UP') AND `state_type`='HARD'\n                    AND `entities_id` IN (" . $_SESSION['glpiactiveentities_string'] . ")\n                    AND `is_acknowledged`='0'");
         $warningdata = countElementsInTable("glpi_plugin_monitoring_services", "((`state`='WARNING' AND `event` IS NOT NULL) \n                        OR `state`='RECOVERY' OR `state`='FLAPPING')\n                    AND `event` IS NOT NULL\n                    AND `state_type`='HARD'\n                    AND `entities_id` IN (" . $_SESSION['glpiactiveentities_string'] . ")\n                    AND `is_acknowledged`='0'");
         $warningconnection = countElementsInTable("glpi_plugin_monitoring_services", "(`state`='UNKNOWN' OR `state` IS NULL\n                    OR (`state`='WARNING' AND `event` IS NULL))\n                    AND `state_type`='HARD'\n                    AND `entities_id` IN (" . $_SESSION['glpiactiveentities_string'] . ")\n                    AND `is_acknowledged`='0'");
         $critical = countElementsInTable("glpi_plugin_monitoring_services", "(`state`='DOWN' OR `state`='UNREACHABLE' OR `state`='CRITICAL' OR `state`='DOWNTIME')\n                    AND `state_type`='HARD'\n                    AND `entities_id` IN (" . $_SESSION['glpiactiveentities_string'] . ")\n                    AND `is_acknowledged`='0'");
         $warningdata_soft = countElementsInTable("glpi_plugin_monitoring_services", "((`state`='WARNING' AND `event` IS NOT NULL) \n                        OR `state`='RECOVERY' OR `state`='FLAPPING')\n                    AND `state_type`='SOFT'\n                    AND `entities_id` IN (" . $_SESSION['glpiactiveentities_string'] . ")\n                    AND `is_acknowledged`='0'");
         $warningconnection_soft = countElementsInTable("glpi_plugin_monitoring_services", "(`state`='UNKNOWN' OR `state` IS NULL\n                    OR (`state`='WARNING' AND `event` IS NULL))\n                    AND `state_type`='SOFT'\n                    AND `entities_id` IN (" . $_SESSION['glpiactiveentities_string'] . ")\n                    AND `is_acknowledged`='0'");
         $critical_soft = countElementsInTable("glpi_plugin_monitoring_services", "(`state`='DOWN' OR `state`='UNREACHABLE' OR `state`='CRITICAL' OR `state`='DOWNTIME')\n                    AND `state_type`='SOFT'\n                    AND `entities_id` IN (" . $_SESSION['glpiactiveentities_string'] . ")\n                    AND `is_acknowledged`='0'");
         $ok_soft = countElementsInTable("glpi_plugin_monitoring_services", "(`state`='OK' OR `state`='UP') AND `state_type`='SOFT'\n                    AND `entities_id` IN (" . $_SESSION['glpiactiveentities_string'] . ")\n                    AND `is_acknowledged`='0'");
         $acknowledge = countElementsInTable("glpi_plugin_monitoring_services", "`state_type`='HARD'\n                    AND `entities_id` IN (" . $_SESSION['glpiactiveentities_string'] . ")\n                    AND `is_acknowledged`='1'");
         // ** Manage play sound if critical increase since last refresh
         if (isset($_SESSION['plugin_monitoring_dashboard_Ressources'])) {
             if ($critical > $_SESSION['plugin_monitoring_dashboard_Ressources']) {
                 $play_sound = 1;
             }
         }
         $_SESSION['plugin_monitoring_dashboard_Ressources'] = $critical;
     } else {
         if ($type == 'Componentscatalog') {
             $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host();
             $queryCat = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs`";
             $resultCat = $DB->query($queryCat);
             while ($data = $DB->fetch_array($resultCat)) {
                 $query = "SELECT COUNT(*) AS cpt FROM `" . $pmComponentscatalog_Host->getTable() . "`\n               LEFT JOIN `glpi_plugin_monitoring_services` \n                  ON `plugin_monitoring_componentscatalogs_hosts_id`=`" . $pmComponentscatalog_Host->getTable() . "`.`id`\n               WHERE `plugin_monitoring_componentscalalog_id`='" . $data['id'] . "'\n                  AND (`state`='DOWN' OR `state`='UNREACHABLE' OR `state`='CRITICAL' OR `state`='DOWNTIME')\n                  AND `state_type`='HARD'\n                  AND `entities_id` IN (" . $_SESSION['glpiactiveentities_string'] . ")\n                  AND `is_acknowledged`='0'";
                 $result = $DB->query($query);
                 $data2 = $DB->fetch_assoc($result);
                 if ($data2['cpt'] > 0) {
                     $critical++;
                 } else {
                     $query = "SELECT COUNT(*) AS cpt, `glpi_plugin_monitoring_services`.`state` \n                     FROM `" . $pmComponentscatalog_Host->getTable() . "`\n                  LEFT JOIN `glpi_plugin_monitoring_services` \n                     ON `plugin_monitoring_componentscatalogs_hosts_id`=`" . $pmComponentscatalog_Host->getTable() . "`.`id`\n                  WHERE `plugin_monitoring_componentscalalog_id`='" . $data['id'] . "'\n                     AND (`state`='WARNING' OR `state`='UNKNOWN' OR `state`='RECOVERY' OR `state`='FLAPPING' OR `state` IS NULL)\n                     AND `state_type`='HARD'\n                     AND `entities_id` IN (" . $_SESSION['glpiactiveentities_string'] . ")\n                     AND `is_acknowledged`='0'";
                     $result = $DB->query($query);
                     $data2 = $DB->fetch_assoc($result);
                     if ($data2['cpt'] > 0) {
                         $warningdata++;
                     } else {
                         $query = "SELECT COUNT(*) AS cpt FROM `" . $pmComponentscatalog_Host->getTable() . "`\n                     LEFT JOIN `glpi_plugin_monitoring_services` \n                        ON `plugin_monitoring_componentscatalogs_hosts_id`=`" . $pmComponentscatalog_Host->getTable() . "`.`id`\n                     WHERE `plugin_monitoring_componentscalalog_id`='" . $data['id'] . "'\n                     AND (`state`='OK' OR `state`='UP') AND `state_type`='HARD'\n                     AND `entities_id` IN (" . $_SESSION['glpiactiveentities_string'] . ")\n                     AND `is_acknowledged`='0'";
                         $result = $DB->query($query);
                         $data2 = $DB->fetch_assoc($result);
                         if ($data2['cpt'] > 0) {
                             $ok++;
                         }
                     }
                 }
                 $query = "SELECT COUNT(*) AS cpt FROM `" . $pmComponentscatalog_Host->getTable() . "`\n               LEFT JOIN `glpi_plugin_monitoring_services` \n                  ON `plugin_monitoring_componentscatalogs_hosts_id`=`" . $pmComponentscatalog_Host->getTable() . "`.`id`\n               WHERE `plugin_monitoring_componentscalalog_id`='" . $data['id'] . "'\n                  AND (`state`='DOWN' OR `state`='UNREACHABLE' OR `state`='CRITICAL' OR `state`='DOWNTIME')\n                  AND `state_type`='SOFT'\n                  AND `entities_id` IN (" . $_SESSION['glpiactiveentities_string'] . ")\n                  AND `is_acknowledged`='0'";
                 $result = $DB->query($query);
                 $data2 = $DB->fetch_assoc($result);
                 if ($data2['cpt'] > 0) {
                     $critical_soft++;
                 } else {
                     $query = "SELECT COUNT(*) AS cpt FROM `" . $pmComponentscatalog_Host->getTable() . "`\n                  LEFT JOIN `glpi_plugin_monitoring_services` \n                     ON `plugin_monitoring_componentscatalogs_hosts_id`=`" . $pmComponentscatalog_Host->getTable() . "`.`id`\n                  WHERE `plugin_monitoring_componentscalalog_id`='" . $data['id'] . "'\n                     AND (`state`='WARNING' OR `state`='UNKNOWN' OR `state`='RECOVERY' OR `state`='FLAPPING' OR `state` IS NULL)\n                     AND `state_type`='SOFT'\n                     AND `entities_id` IN (" . $_SESSION['glpiactiveentities_string'] . ")\n                     AND `is_acknowledged`='0'";
                     $result = $DB->query($query);
                     $data2 = $DB->fetch_assoc($result);
                     if ($data2['cpt'] > 0) {
                         $warningdata_soft++;
                     } else {
                         $query = "SELECT COUNT(*) AS cpt FROM `" . $pmComponentscatalog_Host->getTable() . "`\n                     LEFT JOIN `glpi_plugin_monitoring_services` \n                        ON `plugin_monitoring_componentscatalogs_hosts_id`=`" . $pmComponentscatalog_Host->getTable() . "`.`id`\n                     WHERE `plugin_monitoring_componentscalalog_id`='" . $data['id'] . "'\n                        AND (`state`='OK' OR `state`='UP') AND `state_type`='SOFT'\n                        AND `entities_id` IN (" . $_SESSION['glpiactiveentities_string'] . ")\n                        AND `is_acknowledged`='0'";
                         $result = $DB->query($query);
                         $data2 = $DB->fetch_assoc($result);
                         if ($data2['cpt'] > 0) {
                             $ok_soft++;
                         }
                     }
                 }
             }
             // ** Manage play sound if critical increase since last refresh
             if (isset($_SESSION['plugin_monitoring_dashboard_Componentscatalog'])) {
                 if ($critical > $_SESSION['plugin_monitoring_dashboard_Componentscatalog']) {
                     $play_sound = 1;
                 }
             }
             $_SESSION['plugin_monitoring_dashboard_Componentscatalog'] = $critical;
         } else {
             if ($type == 'Businessrules') {
                 $ok = countElementsInTable("glpi_plugin_monitoring_servicescatalogs", "(`state`='OK' OR `state`='UP') AND `state_type`='HARD'\n                 AND `entities_id` IN (" . $_SESSION['glpiactiveentities_string'] . ")\n                 AND `is_acknowledged`='0'");
                 $warningdata = countElementsInTable("glpi_plugin_monitoring_servicescatalogs", "(`state`='WARNING' OR `state`='UNKNOWN'\n                        OR `state`='RECOVERY' OR `state`='FLAPPING')\n                    AND `state_type`='HARD'\n                    AND `entities_id` IN (" . $_SESSION['glpiactiveentities_string'] . ")\n                    AND `is_acknowledged`='0'");
                 $critical = countElementsInTable("glpi_plugin_monitoring_servicescatalogs", "(`state`='DOWN' OR `state`='UNREACHABLE' OR `state`='CRITICAL' OR `state`='DOWNTIME')\n                    AND `state_type`='HARD'\n                    AND `entities_id` IN (" . $_SESSION['glpiactiveentities_string'] . ")\n                    AND `is_acknowledged`='0'");
                 $warningdata_soft = countElementsInTable("glpi_plugin_monitoring_servicescatalogs", "(`state`='WARNING' OR `state`='UNKNOWN' \n                        OR `state`='RECOVERY' OR `state`='FLAPPING')\n                    AND `state_type`='SOFT'\n                    AND `entities_id` IN (" . $_SESSION['glpiactiveentities_string'] . ")\n                    AND `is_acknowledged`='0'");
                 $critical_soft = countElementsInTable("glpi_plugin_monitoring_servicescatalogs", "(`state`='DOWN' OR `state`='UNREACHABLE' OR `state`='CRITICAL' OR `state`='DOWNTIME')\n                    AND `state_type`='SOFT'\n                    AND `entities_id` IN (" . $_SESSION['glpiactiveentities_string'] . ")\n                    AND `is_acknowledged`='0'");
                 $ok_soft = countElementsInTable("glpi_plugin_monitoring_servicescatalogs", "(`state`='OK' OR `state`='UP') AND `state_type`='SOFT'\n                  AND `entities_id` IN (" . $_SESSION['glpiactiveentities_string'] . ")\n                    AND `is_acknowledged`='0'");
                 // ** Manage play sound if critical increase since last refresh
                 if (isset($_SESSION['plugin_monitoring_dashboard_Businessrules'])) {
                     if ($critical > $_SESSION['plugin_monitoring_dashboard_Businessrules']) {
                         $play_sound = 1;
                     }
                 }
                 $_SESSION['plugin_monitoring_dashboard_Businessrules'] = $critical;
             }
         }
     }
     if ($display == '0') {
         $a_return = array();
         $a_return['ok'] = strval($ok);
         $a_return['ok_soft'] = strval($ok_soft);
         $a_return['warningdata'] = strval($warningdata);
         $a_return['warningconnection'] = strval($warningconnection);
         $a_return['warningdata_soft'] = strval($warningdata_soft);
         $a_return['warningconnection_soft'] = strval($warningconnection_soft);
         $a_return['critical'] = strval($critical);
         $a_return['critical_soft'] = strval($critical_soft);
         $a_return['acknowledge'] = strval($acknowledge);
         return $a_return;
     }
     $critical_link = $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/service.php?hidesearch=1&reset=reset" . "&field[0]=3&searchtype[0]=contains&contains[0]=CRITICAL&link[1]=AND" . "&field[1]=23&searchtype[1]=equals&contains[1]=0&link[2]=OR" . "&field[2]=3&searchtype[2]=contains&contains[2]=DOWN&link[3]=AND" . "&field[3]=23&searchtype[3]=equals&contains[3]=0&link[4]=OR" . "&field[4]=3&searchtype[4]=contains&contains[4]=UNREACHABLE&link[5]=AND" . "&field[5]=23&searchtype[5]=equals&contains[5]=0" . "&itemtype=PluginMonitoringService&start=0&glpi_tab=3'";
     $warning_link = $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/service.php?hidesearch=1&reset=reset" . "&field[0]=3&searchtype[0]=contains&contains[0]=FLAPPING&link[1]=OR" . "&field[1]=3&searchtype[1]=contains&contains[1]=RECOVERY&link[2]=OR" . "&field[2]=3&searchtype[2]=contains&contains[2]=WARNING&link[3]=OR" . "&field[3]=3&searchtype[3]=contains&contains[3]=UNKNOWN" . "&itemtype=PluginMonitoringService&start=0&glpi_tab=3'";
     $warningdata_link = $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/service.php?hidesearch=1&reset=reset" . "&field[0]=3&searchtype[0]=contains&contains[0]=FLAPPING&link[1]=OR" . "&field[1]=3&searchtype[1]=contains&contains[1]=RECOVERY&link[2]=OR" . "&field[2]=3&searchtype[2]=contains&contains[2]=WARNING&link[3]=AND" . "&field[3]=9&searchtype[3]=contains&contains[3]=^" . "&itemtype=PluginMonitoringService&start=0&glpi_tab=3'";
     $warningconnection_link = $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/service.php?hidesearch=1&reset=reset" . "&field[0]=3&searchtype[0]=contains&contains[0]=UNKNOWN&link[1]=OR" . "&field[1]=3&searchtype[1]=contains&contains[1]=NULL&link[2]=OR" . "&field[2]=3&searchtype[2]=contains&contains[2]=WARNING&link[3]=AND" . "&field[3]=9&searchtype[3]=contains&contains[3]=^\$" . "&itemtype=PluginMonitoringService&start=0&glpi_tab=3'";
     $ok_link = $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/service.php?hidesearch=1&reset=reset&" . "field[0]=3&searchtype[0]=contains&contains[0]=OK&link[1]=OR" . "&field[1]=3&searchtype[1]=contains&contains[1]=UP" . "&itemtype=PluginMonitoringService&start=0&glpi_tab=3'";
     $acknowledge_link = $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/service.php?hidesearch=1&reset=reset&" . "field[0]=23&searchtype[0]=equals&contains[0]=1" . "&itemtype=PluginMonitoringService&start=0&glpi_tab=3'";
     echo "<table align='center'>";
     echo "<tr>";
     echo "<td>";
     $background = '';
     if ($critical > 0) {
         $background = 'background="' . $CFG_GLPI['root_doc'] . '/plugins/monitoring/pics/bg_critical.png"';
     }
     echo "<table class='tab_cadre' width='414' height='130' " . $background . " >";
     echo "<tr>";
     echo "<th style='background-color:transparent;'>";
     if ($type == 'Ressources' or $type == 'Componentscatalog') {
         echo "<a href='" . $critical_link . ">" . "<font color='black' style='font-size: 12px;font-weight: bold;'>" . __('Critical', 'monitoring') . "</font></a>";
     } else {
         echo __('Critical', 'monitoring');
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr>";
     echo "<th style='background-color:transparent;'>";
     if ($type == 'Ressources' or $type == 'Componentscatalog') {
         echo "<a href='" . $critical_link . ">" . "<font color='black' style='font-size: 52px;font-weight: bold;'>" . $critical . "</font></a>";
     } else {
         echo "<font style='font-size: 52px;'>" . $critical . "</font>";
     }
     echo "</th>";
     echo "</tr>";
     echo "<tr>";
     echo "<th style='background-color:transparent;'>";
     echo "<font style='font-size: 11px;'>Soft : " . $critical_soft . "</font>";
     echo "</th>";
     echo "</tr>";
     echo "</table>";
     echo "</td>";
     echo "<td>";
     $background = '';
     if ($warningdata > 0) {
         $background = 'background="' . $CFG_GLPI['root_doc'] . '/plugins/monitoring/pics/bg_warning.png"';
     }
     if ($type == 'Ressources') {
         echo "<table class='tab_cadre' width='188' height='130' " . $background . " >";
     } else {
         echo "<table class='tab_cadre' width='316' height='130' " . $background . " >";
     }
     echo "<tr>";
     echo "<th style='background-color:transparent;'>";
     if ($type == 'Ressources') {
         echo "<a href='" . $warningdata_link . ">" . "<font color='black' style='font-size: 12px;font-weight: bold;'>" . __('Warning', 'monitoring') . "</font></a>";
     } else {
         if ($type == 'Componentscatalog') {
             echo "<a href='" . $warning_link . ">" . "<font color='black' style='font-size: 12px;font-weight: bold;'>" . __('Warning', 'monitoring') . "</font></a>";
         } else {
             echo __('Warning', 'monitoring');
         }
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr>";
     echo "<th style='background-color:transparent;'>";
     if ($type == 'Ressources') {
         echo "<a href='" . $warningdata_link . ">" . "<font color='black' style='font-size: 52px;'>" . $warningdata . "</font></a>";
     } else {
         if ($type == 'Componentscatalog') {
             echo "<a href='" . $warning_link . ">" . "<font color='black' style='font-size: 52px;'>" . $warningdata . "</font></a>";
         } else {
             echo "<font style='font-size: 52px;'>" . $warningdata . "</font>";
         }
     }
     echo "</th>";
     echo "</tr>";
     echo "<tr>";
     echo "<th style='background-color:transparent;'>";
     echo "<font style='font-size: 11px;'>Soft : " . $warningdata_soft . "</font>";
     echo "</th>";
     echo "</tr>";
     echo "</table>";
     echo "</td>";
     if ($type == 'Ressources') {
         echo "<td>";
         $background = '';
         if ($warningconnection > 0) {
             $background = 'background="' . $CFG_GLPI['root_doc'] . '/plugins/monitoring/pics/bg_warning_yellow.png"';
         }
         echo "<table class='tab_cadre' width='188' height='130' " . $background . " >";
         echo "<tr>";
         echo "<th style='background-color:transparent;'>";
         if ($type == 'Ressources' or $type == 'Componentscatalog') {
             echo "<a href='" . $warningconnection_link . ">" . "<font color='black' style='font-size: 12px;font-weight: bold;'>" . __('Warning (connection)', 'monitoring') . "</font></a>";
         } else {
             echo __('Warning (connection)', 'monitoring');
         }
         echo "</td>";
         echo "</tr>";
         echo "<tr>";
         echo "<th style='background-color:transparent;'>";
         if ($type == 'Ressources' or $type == 'Componentscatalog') {
             echo "<a href='" . $warningconnection_link . ">" . "<font color='black' style='font-size: 52px;'>" . $warningconnection . "</font></a>";
         } else {
             echo "<font style='font-size: 52px;'>" . $warningconnection . "</font>";
         }
         echo "</th>";
         echo "</tr>";
         echo "<tr>";
         echo "<th style='background-color:transparent;'>";
         echo "<font style='font-size: 11px;'>Soft : " . $warningconnection_soft . "</font>";
         echo "</th>";
         echo "</tr>";
         echo "</table>";
         echo "</td>";
     }
     echo "<td>";
     $background = '';
     if ($ok > 0) {
         $background = 'background="' . $CFG_GLPI['root_doc'] . '/plugins/monitoring/pics/bg_ok.png"';
     }
     echo "<table class='tab_cadre' width='158' height='130' " . $background . " >";
     echo "<tr>";
     echo "<th style='background-color:transparent;'>";
     if ($type == 'Ressources' or $type == 'Componentscatalog') {
         echo "<a href='" . $ok_link . ">" . "<font color='black' style='font-size: 12px;font-weight: bold;'>" . __('OK', 'monitoring') . "</font></a>";
     } else {
         echo __('OK', 'monitoring');
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr>";
     echo "<th style='background-color:transparent;'>";
     if ($type == 'Ressources' or $type == 'Componentscatalog') {
         echo "<a href='" . $ok_link . ">" . "<font color='black' style='font-size: 52px;font-weight: bold;'>" . $ok . "</font></a>";
     } else {
         echo "<font style='font-size: 52px;'>" . $ok . "</font>";
     }
     echo "</th>";
     echo "</tr>";
     echo "<tr>";
     echo "<th style='background-color:transparent;'>";
     echo "<font style='font-size: 11px;'>Soft : " . $ok_soft . "</font>";
     echo "</th>";
     echo "</tr>";
     echo "</table>";
     echo "</td>";
     echo "<td>";
     $background = '';
     if ($acknowledge > 0) {
         $background = 'background="' . $CFG_GLPI['root_doc'] . '/plugins/monitoring/pics/bg_acknowledge.png"';
     }
     echo "<table class='tab_cadre' width='120' height='130' " . $background . " >";
     echo "<tr>";
     echo "<th style='background-color:transparent;'>";
     if ($type == 'Ressources' or $type == 'Componentscatalog') {
         echo "<a href='" . $acknowledge_link . "'>" . "<font color='black' style='font-size: 12px;font-weight: bold;'>" . __('Acknowledge', 'monitoring') . "</font></a>";
     } else {
         echo __('Acknowledge', 'monitoring');
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr>";
     echo "<th style='background-color:transparent;'>";
     if ($type == 'Ressources' or $type == 'Componentscatalog') {
         echo "<a href='" . $acknowledge_link . "'>" . "<font color='black' style='font-size: 52px;font-weight: bold;'>" . $acknowledge . "</font></a>";
     } else {
         echo "<font style='font-size: 52px;'>" . $acknowledge . "</font>";
     }
     echo "</th>";
     echo "</tr>";
     echo "<tr>";
     echo "<th style='background-color:transparent;'>&nbsp;";
     echo "</th>";
     echo "</tr>";
     echo "</table>";
     echo "</td>";
     echo "</tr>";
     echo "</table><br/>";
     // ** play sound
     if ($play_sound == '1') {
         echo '<audio autoplay="autoplay">
              <source src="../audio/star-trek.ogg" type="audio/ogg" />
              Your browser does not support the audio element.
            </audio>';
     }
 }
 function getRessources($componentscatalogs_id, $state, $state_type = 'HARD')
 {
     global $DB;
     $a_services = array();
     $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host();
     $query = "SELECT * FROM `glpi_plugin_monitoring_services`         \n         LEFT JOIN `" . $pmComponentscatalog_Host->getTable() . "`\n            ON `plugin_monitoring_componentscatalogs_hosts_id`=\n               `" . $pmComponentscatalog_Host->getTable() . "`.`id`\n         WHERE `plugin_monitoring_componentscalalog_id`='" . $componentscatalogs_id . "'\n            AND `state_type` LIKE '" . $state_type . "'\n         ORDER BY `name`";
     $result = $DB->query($query);
     while ($data = $DB->fetch_array($result)) {
         if (PluginMonitoringDisplay::getState($data['state'], $data['state_type'], '', $data['is_acknowledged']) == $state) {
             $a_services[] = $data;
         }
     }
     return $a_services;
 }
 function showForm($items_id, $servicescatalogs_id, $options = array())
 {
     global $CFG_GLPI;
     if ($items_id != '') {
         $this->getFromDB($items_id);
     } else {
         $this->getEmpty();
     }
     $this->showFormHeader($options);
     $pmBusinessrule_component = new PluginMonitoringBusinessrule_component();
     $pmBusinessrule_component->replayDynamicServices($items_id);
     $pmSC = new PluginMonitoringServicescatalog();
     $pmSC->getFromDB($servicescatalogs_id);
     $rand = mt_rand();
     echo "<tr class='tab_bg_1'>";
     echo "<td>";
     echo "<input type='hidden' name='plugin_monitoring_servicescatalogs_id' value='" . $servicescatalogs_id . "'/>";
     echo __('Name') . "&nbsp;:";
     echo "</td>";
     echo "<td>";
     echo "<input type='text' name='name' value='" . $this->fields["name"] . "' size='30'/>";
     echo "</td>";
     if ($items_id != '') {
         if (Session::haveRight("plugin_monitoring_servicescatalog", CREATE)) {
             echo "<th colspan='2' width='60%'>";
             echo __('Resources', 'monitoring');
             echo "&nbsp;";
             echo "<img onClick=\"Ext.get('ressources" . $rand . "').setDisplayed('block')\"\n                       title=\"" . __('add') . "\" alt=\"" . __('add') . "\"\n                       class='pointer'  src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png'>";
             echo "</th>";
         }
     }
     echo "</tr>";
     echo "<tr>";
     echo "<td valign='top'>";
     echo __('Logical operator') . "&nbsp;:";
     echo "</td>";
     echo "<td valign='top'>";
     $first_operator = array();
     $first_operator['and'] = "and";
     $first_operator['or'] = "or";
     $first_operator['2 of:'] = __('2 of', 'monitoring');
     $first_operator['3 of:'] = __('3 of', 'monitoring');
     $first_operator['4 of:'] = __('4 of', 'monitoring');
     $first_operator['5 of:'] = __('5 of', 'monitoring');
     $first_operator['6 of:'] = __('6 of', 'monitoring');
     $first_operator['7 of:'] = __('7 of', 'monitoring');
     $first_operator['8 of:'] = __('8 of', 'monitoring');
     $first_operator['9 of:'] = __('9 of', 'monitoring');
     $first_operator['10 of:'] = __('10 of', 'monitoring');
     Dropdown::showFromArray('operator', $first_operator, array("value" => $this->fields['operator']));
     echo "</td>";
     if ($items_id != '') {
         echo "<td colspan='2'>";
         if (Session::haveRight("plugin_monitoring_servicescatalog", CREATE)) {
             // ** Dropdown to display
             echo "<div style='display:none' id='ressources" . $rand . "' >";
             // Static (a service for an host)
             echo "<table>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>";
             echo "<form name='form' method='post' action='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/businessrule.form.php'>";
             echo "<input type='hidden' name='plugin_monitoring_businessrulegroups_id' value='" . $items_id . "' />";
             echo "<input type='hidden' name='is_generic' value='" . $pmSC->getField('is_generic') . "' />";
             PluginMonitoringBusinessrule::dropdownService(0, array('name' => 'type'));
             echo "<input type='submit' name='add' value=\"" . __('Add') . "\" class='submit'>";
             Html::closeForm();
             echo "</td>";
             echo "</tr>";
             echo "</table>";
             echo "<hr>";
             // Dynamique (all service of component of component catalog)
             echo "<table>";
             echo "<tr class='tab_bg_1'>";
             echo "<td><strong>";
             echo __('Components catalog', 'monitoring');
             echo ' + ';
             echo __('Component', 'monitoring');
             echo " (" . __('Dynamic', 'monitoring') . ")";
             echo " :</strong></td>";
             echo "</tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>";
             echo "<form name='form' method='post' action='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/businessrule_component.form.php'>";
             echo "<input type='hidden' name='plugin_monitoring_businessrulegroups_id' value='" . $items_id . "' />";
             $options = array('toupdate' => array('value_fieldname' => 'plugin_monitoring_componentscalalog_id', 'to_update' => "componentdropdown" . $rand, 'url' => $CFG_GLPI["root_doc"] . "/plugins/monitoring/ajax/dropdownComponent.php", 'moreparams' => array()));
             Dropdown::show('PluginMonitoringComponentscatalog', $options);
             echo '<div id="componentdropdown' . $rand . '"></div>';
             //PluginMonitoringBusinessrule::dropdownService(0, array('name' => 'type'));
             echo "<input type='submit' name='add' value=\"" . __('Add') . "\" class='submit'>";
             Html::closeForm();
             echo "</td>";
             echo "</tr>";
             echo "</table>";
             echo "<hr>";
             echo "</div>";
         }
         $pmBusinessrule = new PluginMonitoringBusinessrule();
         $pmService = new PluginMonitoringService();
         $a_services = $pmBusinessrule->find("`plugin_monitoring_businessrulegroups_id`='" . $items_id . "'" . " AND `is_dynamic`='0'");
         if (count($a_services) > 0) {
             echo "<strong>" . __('Static hosts', 'monitoring') . " :</strong>";
             echo "<table width='100%'>";
             foreach ($a_services as $gdata) {
                 if ($pmService->getFromDB($gdata['plugin_monitoring_services_id'])) {
                     $shortstate = $pmService->getShortState();
                     echo "<tr class='tab_bg_1'>";
                     echo "<td>";
                     echo "<img src='" . $pmService->getShortState(array('image' => '32')) . "'/>";
                     echo "</td>";
                     echo "<td>";
                     echo $pmService->getLink();
                     echo "</td>";
                     echo "<td>";
                     echo "<input type='submit' name='deletebusinessrules-" . $gdata['id'] . "' value=\"" . _sx('button', 'Delete permanently') . "\" class='submit'>";
                     echo "</td>";
                     echo "</tr>";
                 } else {
                     // resource deleted
                     echo "<tr class='tab_bg_1'>";
                     echo "<td colspan='2' bgcolor='#ff0000'>";
                     echo __('Resource deleted', 'monitoring');
                     echo "</td>";
                     echo "<td>";
                     echo "<input type='submit' name='deletebusinessrules-" . $gdata['id'] . "' value=\"" . __('Clean') . "\" class='submit'>";
                     echo "</td>";
                     echo "</tr>";
                 }
             }
             echo "</table>";
             echo "<hr/>";
         }
         $a_br_components = $pmBusinessrule_component->find("`plugin_monitoring_businessrulegroups_id`='" . $items_id . "'");
         $pmComponentscatalog_Component = new PluginMonitoringComponentscatalog_Component();
         $pmComponentscatalog = new PluginMonitoringComponentscatalog();
         $pmComponent = new PluginMonitoringComponent();
         if (count($a_br_components) > 0) {
             echo "<strong>" . __('Dynamic hosts', 'monitoring') . " :</strong>";
             echo "<table width='100%'>";
             foreach ($a_br_components as $a_br_component) {
                 echo "<tr class='tab_bg_1'>";
                 echo "<td>";
                 $pmComponentscatalog_Component->getFromDB($a_br_component['plugin_monitoring_componentscatalogs_components_id']);
                 $pmComponentscatalog->getFromDB($pmComponentscatalog_Component->fields['plugin_monitoring_componentscalalog_id']);
                 echo $pmComponentscatalog->getLink();
                 echo ' > ';
                 $pmComponent->getFromDB($pmComponentscatalog_Component->fields['plugin_monitoring_components_id']);
                 echo $pmComponent->getLink();
                 echo "</td>";
                 echo "<td>";
                 echo "<input type='submit' name='deletebrcomponents-" . $a_br_component['id'] . "' value=\"" . _sx('button', 'Delete permanently') . "\" class='submit'>";
                 echo "</td>";
                 echo "</tr>";
             }
             echo "</table>";
         }
         if (!($pmSC->fields['is_generic'] && $pmSC->fields['is_recursive'])) {
             echo "<table width='100%'>";
             $a_services = $pmBusinessrule->find("`plugin_monitoring_businessrulegroups_id`='" . $items_id . "'" . " AND `is_dynamic`='1'");
             foreach ($a_services as $gdata) {
                 $pmService->getFromDB($gdata["plugin_monitoring_services_id"]);
                 $shortstate = $pmService->getShortState();
                 echo "<tr class='tab_bg_1'>";
                 echo "<td width='130'>&nbsp;";
                 echo "</td>";
                 echo "<td>";
                 echo "<img src='" . $pmService->getShortState(array('image' => '32')) . "'/>";
                 echo "</td>";
                 echo "<td>";
                 $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host();
                 $pmComponentscatalog_Host->getFromDB($pmService->fields['plugin_monitoring_componentscatalogs_hosts_id']);
                 echo $pmService->getLink();
                 echo "</td>";
                 echo "</tr>";
             }
             echo "</table>";
         } else {
             echo "<strong>" . __('Dynamic hosts list will be defined during Shinken configuration build.', 'monitoring') . "</strong>";
         }
     }
     echo "</td>";
     echo "</tr>";
     $this->showFormButtons($options);
     return true;
 }
 function showForm($items_id, $servicescatalogs_id, $options = array())
 {
     global $LANG, $CFG_GLPI;
     if ($items_id != '') {
         $this->getFromDB($items_id);
     } else {
         $this->getEmpty();
     }
     $this->showFormHeader($options);
     $rand = mt_rand();
     echo "<tr class='tab_bg_1'>";
     echo "<td>";
     echo "<input type='hidden' name='plugin_monitoring_servicescatalogs_id' value='" . $servicescatalogs_id . "'/>";
     echo $LANG['common'][16] . "&nbsp;:";
     echo "</td>";
     echo "<td>";
     echo "<input type='text' name='name' value='" . $this->fields["name"] . "' size='30'/>";
     echo "</td>";
     if ($items_id != '') {
         echo "<th colspan='2' width='60%'>";
         echo $LANG['plugin_monitoring']['service'][0];
         echo "&nbsp;";
         echo "<img onClick=\"Ext.get('ressources" . $rand . "').setDisplayed('block')\"\n                    title=\"" . $LANG['buttons'][8] . "\" alt=\"" . $LANG['buttons'][8] . "\"\n                    class='pointer'  src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png'>";
         echo "</th>";
         echo "</tr>";
         echo "<tr>";
     }
     echo "<td valign='top'>";
     echo $LANG['rulesengine'][9] . "&nbsp;:";
     echo "</td>";
     echo "<td valign='top'>";
     $first_operator = array();
     $first_operator['or'] = "or";
     $first_operator['2 of:'] = $LANG['plugin_monitoring']['businessrule'][2];
     $first_operator['3 of:'] = $LANG['plugin_monitoring']['businessrule'][3];
     $first_operator['4 of:'] = $LANG['plugin_monitoring']['businessrule'][4];
     $first_operator['5 of:'] = $LANG['plugin_monitoring']['businessrule'][5];
     $first_operator['6 of:'] = $LANG['plugin_monitoring']['businessrule'][6];
     $first_operator['7 of:'] = $LANG['plugin_monitoring']['businessrule'][7];
     $first_operator['8 of:'] = $LANG['plugin_monitoring']['businessrule'][8];
     $first_operator['9 of:'] = $LANG['plugin_monitoring']['businessrule'][9];
     $first_operator['10 of:'] = $LANG['plugin_monitoring']['businessrule'][10];
     Dropdown::showFromArray('operator', $first_operator, array("value" => $this->fields['operator']));
     echo "</td>";
     if ($items_id != '') {
         echo "<td colspan='2'>";
         // ** Dropdown to display
         echo "<div style='display:none' id='ressources" . $rand . "' >";
         echo "<table>";
         echo "<tr class='tab_bg_1'>";
         echo "<td>";
         echo "<form name='form' method='post' action='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/businessrule.form.php'>";
         echo "<input type='hidden' name='plugin_monitoring_businessrulegroups_id' value='" . $items_id . "' />";
         PluginMonitoringBusinessrule::dropdownService(0, array('name' => 'type'));
         echo "<input type='submit' name='add' value=\"" . $LANG['buttons'][8] . "\" class='submit'>";
         echo "</form>";
         echo "</td>";
         echo "</tr>";
         echo "</table>";
         echo "<hr>";
         echo "</div>";
         echo "<table width='100%'>";
         $pmBusinessrule = new PluginMonitoringBusinessrule();
         $pmService = new PluginMonitoringService();
         $a_services = $pmBusinessrule->find("`plugin_monitoring_businessrulegroups_id`='" . $servicescatalogs_id . "'");
         foreach ($a_services as $gdata) {
             if ($pmService->getFromDB($gdata['plugin_monitoring_services_id'])) {
                 $shortstate = PluginMonitoringDisplay::getState($pmService->fields['state'], $pmService->fields['state_type']);
                 echo "<tr class='tab_bg_1'>";
                 echo "<td>";
                 echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/box_" . $shortstate . "_32.png'/>";
                 echo "</td>";
                 echo "<td>";
                 $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host();
                 $pmService->getFromDB($gdata["plugin_monitoring_services_id"]);
                 $pmComponentscatalog_Host->getFromDB($pmService->fields['plugin_monitoring_componentscatalogs_hosts_id']);
                 echo $pmService->getLink(1);
                 echo " " . $LANG['networking'][25] . " ";
                 $itemtype2 = $pmComponentscatalog_Host->fields['itemtype'];
                 $item2 = new $itemtype2();
                 $item2->getFromDB($pmComponentscatalog_Host->fields['items_id']);
                 echo $item2->getLink(1);
                 echo "</td>";
                 echo "<td>";
                 echo "<input type='submit' name='deletebusinessrules-" . $gdata['id'] . "' value=\"" . $LANG['buttons'][6] . "\" class='submit'>";
                 echo "</td>";
             } else {
                 // resource deleted
                 echo "<tr class='tab_bg_1'>";
                 echo "<td colspan='2' bgcolor='#ff0000'>";
                 echo $LANG['plugin_monitoring']['service'][23];
                 echo "</td>";
                 echo "<td>";
                 echo "<input type='submit' name='deletebusinessrules-" . $gdata['id'] . "' value=\"" . $LANG['buttons'][53] . "\" class='submit'>";
                 echo "</td>";
             }
         }
         echo "</tr>";
     }
     echo "</table>";
     echo "</td>";
     echo "</tr>";
     $this->showFormButtons($options);
     return true;
 }
 function generateServicesCfg($file = 0, $tag = '')
 {
     global $DB;
     $pMonitoringCommand = new PluginMonitoringCommand();
     $pMonitoringCheck = new PluginMonitoringCheck();
     $pmComponent = new PluginMonitoringComponent();
     $pmEntity = new PluginMonitoringEntity();
     $pmContact_Item = new PluginMonitoringContact_Item();
     $pmService = new PluginMonitoringService();
     $pmComponentscatalog = new PluginMonitoringComponentscatalog();
     $calendar = new Calendar();
     $user = new User();
     $pmLog = new PluginMonitoringLog();
     $profile_User = new Profile_User();
     if (isset($_SERVER['HTTP_USER_AGENT']) and strstr($_SERVER['HTTP_USER_AGENT'], 'xmlrpclib.py')) {
         if (!isset($_SESSION['glpi_currenttime'])) {
             $_SESSION['glpi_currenttime'] = date("Y-m-d H:i:s");
         }
         $input = array();
         $input['user_name'] = "Shinken";
         $input['action'] = "restart";
         $input['date_mod'] = date("Y-m-d H:i:s");
         $pmLog->add($input);
     }
     $hostnamebp = '';
     $a_services = array();
     $i = 0;
     // * Prepare contacts
     $a_contacts_entities = array();
     $a_list_contact = $pmContact_Item->find("`itemtype`='PluginMonitoringComponentscatalog'\n         AND `users_id`>0");
     foreach ($a_list_contact as $data) {
         $contactentities = getSonsOf('glpi_entities', $data['entities_id']);
         if (isset($a_contacts_entities[$data['items_id']][$data['users_id']])) {
             $contactentities = array_merge($contactentities, $a_contacts_entities[$data['items_id']][$data['users_id']]);
         }
         $a_contacts_entities[$data['items_id']][$data['users_id']] = $contactentities;
     }
     $a_entities_allowed = $pmEntity->getEntitiesByTag($tag);
     $query = "SELECT * FROM `glpi_plugin_monitoring_services`";
     $result = $DB->query($query);
     while ($data = $DB->fetch_array($result)) {
         $notadd = 0;
         $notadddescription = '';
         $a_component = current($pmComponent->find("`id`='" . $data['plugin_monitoring_components_id'] . "'", "", 1));
         $a_hostname = array();
         $queryh = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts` \n            WHERE `id` = '" . $data['plugin_monitoring_componentscatalogs_hosts_id'] . "'\n            LIMIT 1";
         $resulth = $DB->query($queryh);
         $hostname = '';
         $plugin_monitoring_componentscatalogs_id = 0;
         while ($datah = $DB->fetch_array($resulth)) {
             $itemtype = $datah['itemtype'];
             $item = new $itemtype();
             if ($item->getFromDB($datah['items_id'])) {
                 if (isset($a_entities_allowed['-1']) or isset($a_entities_allowed[$item->fields['entities_id']])) {
                     $a_hostname[] = $itemtype . "-" . $datah['items_id'] . "-" . preg_replace("/[^A-Za-z0-9]/", "", $item->fields['name']);
                     $hostname = $item->fields['name'];
                     $plugin_monitoring_componentscatalogs_id = $datah['plugin_monitoring_componentscalalog_id'];
                 }
             }
         }
         if (count($a_hostname) > 0) {
             if (isset($_SESSION['plugin_monitoring']['servicetemplates'][$a_component['id']])) {
                 $a_services[$i]['use'] = $_SESSION['plugin_monitoring']['servicetemplates'][$a_component['id']];
             }
             $a_services[$i]['host_name'] = implode(",", array_unique($a_hostname));
             $hostnamebp = $a_services[$i]['host_name'];
             // For business rules
             $a_services[$i]['service_description'] = preg_replace("/[^A-Za-z0-9]/", "", $a_component['name']) . "-" . $data['id'];
             $pMonitoringCommand->getFromDB($a_component['plugin_monitoring_commands_id']);
             // Manage arguments
             $array = array();
             preg_match_all("/\\\$(ARG\\d+)\\\$/", $pMonitoringCommand->fields['command_line'], $array);
             sort($array[0]);
             $a_arguments = importArrayFromDB($a_component['arguments']);
             $a_argumentscustom = importArrayFromDB($data['arguments']);
             foreach ($a_argumentscustom as $key => $value) {
                 $a_arguments[$key] = $value;
             }
             $args = '';
             foreach ($array[0] as $arg) {
                 if ($arg != '$PLUGINSDIR$' and $arg != '$HOSTADDRESS$' and $arg != '$MYSQLUSER$' and $arg != '$MYSQLPASSWORD$') {
                     $arg = str_replace('$', '', $arg);
                     if (!isset($a_arguments[$arg])) {
                         $args .= '!';
                     } else {
                         if (strstr($a_arguments[$arg], "[[HOSTNAME]]")) {
                             $a_arguments[$arg] = str_replace("[[HOSTNAME]]", $hostname, $a_arguments[$arg]);
                         } elseif (strstr($a_arguments[$arg], "[[NETWORKPORTDESCR]]")) {
                             if (class_exists("PluginFusinvsnmpNetworkPort")) {
                                 $pfNetworkPort = new PluginFusinvsnmpNetworkPort();
                                 $pfNetworkPort->loadNetworkport($data['networkports_id']);
                                 $descr = '';
                                 $descr = $pfNetworkPort->getValue("ifdescr");
                                 $a_arguments[$arg] = str_replace("[[NETWORKPORTDESCR]]", $descr, $a_arguments[$arg]);
                             }
                         } elseif (strstr($a_arguments[$arg], "[[NETWORKPORTNUM]]")) {
                             $networkPort = new NetworkPort();
                             $networkPort->getFromDB($data['networkports_id']);
                             $logicalnum = $pfNetworkPort->fields['logical_number'];
                             $a_arguments[$arg] = str_replace("[[NETWORKPORTNUM]]", $logicalnum, $a_arguments[$arg]);
                         } elseif (strstr($a_arguments[$arg], "[[NETWORKPORTNAME]]")) {
                             $networkPort = new NetworkPort();
                             $networkPort->getFromDB($data['networkports_id']);
                             $portname = $pfNetworkPort->fields['name'];
                             $a_arguments[$arg] = str_replace("[[NETWORKPORTNAME]]", $portname, $a_arguments[$arg]);
                         } else {
                             if (strstr($a_arguments[$arg], "[")) {
                                 $a_arguments[$arg] = PluginMonitoringService::convertArgument($data['id'], $a_arguments[$arg]);
                             }
                         }
                         if ($a_arguments == '') {
                             $notadd = 1;
                             if ($notadddescription != '') {
                                 $notadddescription .= ", ";
                             }
                             $notadddescription .= "Argument " . $a_arguments[$arg] . " Not have value";
                         }
                         $args .= '!' . $a_arguments[$arg];
                         if ($a_arguments[$arg] == '' and $a_component['alias_command'] != '') {
                             $args .= $a_component['alias_command'];
                         }
                     }
                 }
             }
             // End manage arguments
             if ($a_component['remotesystem'] == 'nrpe') {
                 if ($a_component['alias_command'] != '') {
                     $a_services[$i]['check_command'] = "check_nrpe!" . $a_component['alias_command'];
                 } else {
                     $a_services[$i]['check_command'] = "check_nrpe!" . $pMonitoringCommand->fields['command_name'];
                 }
             } else {
                 $a_services[$i]['check_command'] = $pMonitoringCommand->fields['command_name'] . $args;
             }
             // * Contacts
             $a_contacts = array();
             $a_list_contact = $pmContact_Item->find("`itemtype`='PluginMonitoringComponentscatalog'\n                  AND `items_id`='" . $plugin_monitoring_componentscatalogs_id . "'");
             foreach ($a_list_contact as $data_contact) {
                 if (isset($a_contacts_entities[$plugin_monitoring_componentscatalogs_id][$data_contact['users_id']])) {
                     if (in_array($data['entities_id'], $a_contacts_entities[$plugin_monitoring_componentscatalogs_id][$data_contact['users_id']])) {
                         //                  $pmContact->getFromDB($data_contact['plugin_monitoring_contacts_id']);
                         $user->getFromDB($data_contact['users_id']);
                         $a_contacts[] = $user->fields['name'];
                     }
                 }
             }
             $a_contacts_unique = array_unique($a_contacts);
             $a_services[$i]['contacts'] = implode(',', $a_contacts_unique);
             // ** If shinken not use templates or template not defined :
             if (!isset($_SESSION['plugin_monitoring']['servicetemplates'][$a_component['id']])) {
                 $pMonitoringCheck->getFromDB($a_component['plugin_monitoring_checks_id']);
                 $a_services[$i]['check_interval'] = $pMonitoringCheck->fields['check_interval'];
                 $a_services[$i]['retry_interval'] = $pMonitoringCheck->fields['retry_interval'];
                 $a_services[$i]['max_check_attempts'] = $pMonitoringCheck->fields['max_check_attempts'];
                 if ($calendar->getFromDB($a_component['calendars_id'])) {
                     $a_services[$i]['check_period'] = $calendar->fields['name'];
                 }
                 $a_services[$i]['notification_interval'] = '30';
                 if ($calendar->getFromDB($a_component['calendars_id'])) {
                     $a_services[$i]['notification_period'] = $calendar->fields['name'];
                 } else {
                     $a_services[$i]['notification_period'] = "24x7";
                 }
                 $a_services[$i]['notification_options'] = 'w,c,r';
                 $a_services[$i]['active_checks_enabled'] = '1';
                 $a_services[$i]['process_perf_data'] = '1';
                 $a_services[$i]['active_checks_enabled'] = '1';
                 $a_services[$i]['passive_checks_enabled'] = '1';
                 $a_services[$i]['parallelize_check'] = '1';
                 $a_services[$i]['obsess_over_service'] = '1';
                 $a_services[$i]['check_freshness'] = '1';
                 $a_services[$i]['freshness_threshold'] = '1';
                 $a_services[$i]['notifications_enabled'] = '1';
                 $a_services[$i]['event_handler_enabled'] = '0';
                 //$a_services[$i]['event_handler'] = 'super_event_kill_everyone!DIE';
                 $a_services[$i]['flap_detection_enabled'] = '1';
                 $a_services[$i]['failure_prediction_enabled'] = '1';
                 $a_services[$i]['retain_status_information'] = '1';
                 $a_services[$i]['retain_nonstatus_information'] = '1';
                 $a_services[$i]['is_volatile'] = '0';
                 $a_services[$i]['_httpstink'] = 'NO';
             }
             $pmComponentscatalog->getFromDB($plugin_monitoring_componentscatalogs_id);
             if ($pmComponentscatalog->fields['notification_interval'] != '30') {
                 $a_services[$i]['notification_interval'] = $pmComponentscatalog->fields['notification_interval'];
             }
             if ($notadd == '1') {
                 unset($a_services[$i]);
                 $input = array();
                 $input['id'] = $data['id'];
                 $input['event'] = $notadddescription;
                 $input['state'] = "CRITICAL";
                 $input['state_type'] = "HARD";
                 $pmService->update($input);
             } else {
                 $i++;
             }
         }
     }
     //      // Business rules....
     $pmService = new PluginMonitoringService();
     $pmServicescatalog = new PluginMonitoringServicescatalog();
     $pMonitoringBusinessrulegroup = new PluginMonitoringBusinessrulegroup();
     $pmBusinessrule = new PluginMonitoringBusinessrule();
     $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host();
     $a_listBA = $pmServicescatalog->find();
     foreach ($a_listBA as $dataBA) {
         if (isset($a_entities_allowed['-1']) or isset($a_entities_allowed[$dataBA['entities_id']])) {
             $a_grouplist = $pMonitoringBusinessrulegroup->find("`plugin_monitoring_servicescatalogs_id`='" . $dataBA['id'] . "'");
             $a_group = array();
             foreach ($a_grouplist as $gdata) {
                 $a_listBR = $pmBusinessrule->find("`plugin_monitoring_businessrulegroups_id`='" . $gdata['id'] . "'");
                 foreach ($a_listBR as $dataBR) {
                     if ($pmService->getFromDB($dataBR['plugin_monitoring_services_id'])) {
                         $pmComponentscatalog_Host->getFromDB($pmService->fields['plugin_monitoring_componentscatalogs_hosts_id']);
                         $itemtype = $pmComponentscatalog_Host->fields['itemtype'];
                         $item = new $itemtype();
                         if ($item->getFromDB($pmComponentscatalog_Host->fields['items_id'])) {
                             $hostname = $itemtype . "-" . $pmComponentscatalog_Host->fields['items_id'] . "-" . preg_replace("/[^A-Za-z0-9]/", "", $item->fields['name']);
                             if ($gdata['operator'] == 'and' or $gdata['operator'] == 'or' or strstr($gdata['operator'], ' of:')) {
                                 $operator = '|';
                                 if ($gdata['operator'] == 'and') {
                                     $operator = '&';
                                 }
                                 if (!isset($a_group[$gdata['id']])) {
                                     $a_group[$gdata['id']] = '';
                                     if (strstr($gdata['operator'], ' of:')) {
                                         $a_group[$gdata['id']] = $gdata['operator'];
                                     }
                                     $a_group[$gdata['id']] .= $hostname . "," . preg_replace("/[^A-Za-z0-9]/", "", $pmService->fields['name']) . "-" . $pmService->fields['id'];
                                 } else {
                                     $a_group[$gdata['id']] .= $operator . $hostname . "," . preg_replace("/[^A-Za-z0-9]/", "", $pmService->fields['name']) . "-" . $pmService->fields['id'];
                                 }
                             } else {
                                 $a_group[$gdata['id']] = $gdata['operator'] . " " . $hostname . "," . preg_replace("/[^A-Za-z0-9]/", "", $item->getName()) . "-" . $item->fields['id'];
                             }
                         }
                     }
                 }
             }
             if (count($a_group) > 0) {
                 $pMonitoringCheck->getFromDB($dataBA['plugin_monitoring_checks_id']);
                 $a_services[$i]['check_interval'] = $pMonitoringCheck->fields['check_interval'];
                 $a_services[$i]['retry_interval'] = $pMonitoringCheck->fields['retry_interval'];
                 $a_services[$i]['max_check_attempts'] = $pMonitoringCheck->fields['max_check_attempts'];
                 if ($calendar->getFromDB($dataBA['calendars_id'])) {
                     $a_services[$i]['check_period'] = $calendar->fields['name'];
                 }
                 $a_services[$i]['host_name'] = $hostnamebp;
                 $a_services[$i]['service_description'] = preg_replace("/[^A-Za-z0-9]/", "", $dataBA['name']) . "-" . $dataBA['id'] . "-businessrules";
                 $command = "bp_rule!";
                 foreach ($a_group as $key => $value) {
                     if (!strstr($value, "&") and !strstr($value, "|")) {
                         $a_group[$key] = trim($value);
                     } else {
                         $a_group[$key] = "(" . trim($value) . ")";
                     }
                 }
                 $a_services[$i]['check_command'] = $command . implode("&", $a_group);
                 $a_services[$i]['notification_interval'] = '30';
                 if ($calendar->getFromDB($dataBA['calendars_id'])) {
                     $a_services[$i]['notification_period'] = $calendar->fields['name'];
                 } else {
                     $a_services[$i]['notification_period'] = "24x7";
                 }
                 $a_services[$i]['notification_options'] = 'w,c,r';
                 $a_services[$i]['active_checks_enabled'] = '1';
                 $a_services[$i]['process_perf_data'] = '1';
                 $a_services[$i]['active_checks_enabled'] = '1';
                 $a_services[$i]['passive_checks_enabled'] = '1';
                 $a_services[$i]['parallelize_check'] = '1';
                 $a_services[$i]['obsess_over_service'] = '1';
                 $a_services[$i]['check_freshness'] = '1';
                 $a_services[$i]['freshness_threshold'] = '1';
                 $a_services[$i]['notifications_enabled'] = '1';
                 $a_services[$i]['event_handler_enabled'] = '0';
                 //$a_services[$i]['event_handler'] = 'super_event_kill_everyone!DIE';
                 $a_services[$i]['flap_detection_enabled'] = '1';
                 $a_services[$i]['failure_prediction_enabled'] = '1';
                 $a_services[$i]['retain_status_information'] = '1';
                 $a_services[$i]['retain_nonstatus_information'] = '1';
                 $a_services[$i]['is_volatile'] = '0';
                 $a_services[$i]['_httpstink'] = 'NO';
                 $a_services[$i]['contacts'] = '';
                 $i++;
             }
         }
     }
     if ($file == "1") {
         $config = "# Generated by plugin monitoring for GLPI\n# on " . date("Y-m-d H:i:s") . "\n\n";
         foreach ($a_services as $data) {
             $config .= $this->constructFile("service", $data);
         }
         return array('services.cfg', $config);
     } else {
         return $a_services;
     }
 }
  @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     2011

  ------------------------------------------------------------------------
*/
include "../../../inc/includes.php";
PluginMonitoringProfile::checkRight("componentscatalog", "w");
$pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host();
if (isset($_POST["add"])) {
    if (isset($_POST['items_id']) and $_POST['items_id'] != '0') {
        $componentscatalogs_hosts_id = $pmComponentscatalog_Host->add($_POST);
        $pmComponentscatalog_Host->linkComponentsToItem($_POST['plugin_monitoring_componentscalalog_id'], $componentscatalogs_hosts_id);
    }
    Html::back();
} else {
    if (isset($_POST["deleteitem"])) {
        foreach ($_POST["item"] as $id => $num) {
            $pmComponentscatalog_Host->delete(array('id' => $id));
        }
        Html::back();
    }
}
Html::footer();
  ------------------------------------------------------------------------

  @package   Plugin Monitoring for GLPI
  @author    David Durieux
  @co-author
  @comment
  @copyright Copyright (c) 2011-2014 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::checkRight("plugin_monitoring_componentscatalog", UPDATE);
$pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host();
if (isset($_POST["add"])) {
    if (isset($_POST['items_id']) and $_POST['items_id'] != '0') {
        $pmComponentscatalog_Host->add($_POST);
    }
    Html::back();
} else {
    if (isset($_POST["deleteitem"])) {
        foreach ($_POST["item"] as $id => $num) {
            $pmComponentscatalog_Host->delete(array('id' => $id));
        }
        Html::back();
    }
}
Html::footer();
 function linkComponentsToItem($componentscatalogs_id, $componentscatalogs_hosts_id, $networkports_id = 0)
 {
     global $DB;
     $pmService = new PluginMonitoringService();
     $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host();
     $pmComponentscatalog_Host->getFromDB($componentscatalogs_hosts_id);
     $query = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_components`\n         WHERE `plugin_monitoring_componentscalalog_id`='" . $componentscatalogs_id . "'";
     $result = $DB->query($query);
     while ($data = $DB->fetch_array($result)) {
         $input = array();
         $itemtype = $pmComponentscatalog_Host->fields['itemtype'];
         $item = new $itemtype();
         $item->getFromDB($pmComponentscatalog_Host->fields['items_id']);
         if ($networkports_id == 0) {
             $input['entities_id'] = $item->fields['entities_id'];
             $input['plugin_monitoring_componentscatalogs_hosts_id'] = $componentscatalogs_hosts_id;
             $input['plugin_monitoring_components_id'] = $data['plugin_monitoring_components_id'];
             $input['name'] = Dropdown::getDropdownName("glpi_plugin_monitoring_components", $data['plugin_monitoring_components_id']);
             $input['state'] = 'WARNING';
             $input['state_type'] = 'HARD';
             $pmService->add($input);
         } else {
             if ($networkports_id > 0) {
                 $a_services = $pmService->find("`plugin_monitoring_components_id`='" . $data['plugin_monitoring_components_id'] . "'\n               AND `plugin_monitoring_componentscatalogs_hosts_id`='" . $componentscatalogs_hosts_id . "'\n               AND `networkports_id`='" . $networkports_id . "'", "", 1);
                 $item = new NetworkPort();
                 $item->getFromDB($networkports_id);
                 if (count($a_services) == 0) {
                     $input = array();
                     $input['networkports_id'] = $networkports_id;
                     $input['entities_id'] = $item->fields['entities_id'];
                     $input['plugin_monitoring_componentscatalogs_hosts_id'] = $componentscatalogs_hosts_id;
                     $input['plugin_monitoring_components_id'] = $data['plugin_monitoring_components_id'];
                     $input['name'] = Dropdown::getDropdownName("glpi_plugin_monitoring_components", $data['plugin_monitoring_components_id']);
                     $input['state'] = 'WARNING';
                     $input['state_type'] = 'HARD';
                     $pmService->add($input);
                 } else {
                     $a_service = current($a_services);
                     $queryu = "UPDATE `glpi_plugin_monitoring_services`\n                  SET `entities_id`='" . $item->fields['entities_id'] . "'\n                     WHERE `id`='" . $a_service['id'] . "'";
                     $DB->query($queryu);
                 }
             }
         }
     }
 }
 function displayItem($data, $config)
 {
     global $CFG_GLPI;
     $itemtype = $data['itemtype'];
     $itemtype2 = '';
     if ($itemtype == 'host' || $itemtype == 'service') {
         $itemtype2 = $itemtype;
         $itemtype = 'PluginMonitoringDisplayview';
     }
     $item = new $itemtype();
     $content = '';
     $title = $item->getTypeName();
     $event = '';
     $width = '';
     if ($itemtype == "PluginMonitoringService") {
         $content = $item->showWidget($data['items_id'], $data['extra_infos']);
         if (!isset($item->fields['plugin_monitoring_components_id'])) {
             return false;
         }
         $title .= " : <a href=\"" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/display.form.php?itemtype=PluginMonitoringService&items_id=" . $data['items_id'] . "\">" . Dropdown::getDropdownName(getTableForItemType('PluginMonitoringComponent'), $item->fields['plugin_monitoring_components_id']);
         $title .= '</a> ' . __('on', 'monitoring') . ' ';
         $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host();
         $pmComponentscatalog_Host->getFromDB($item->fields["plugin_monitoring_componentscatalogs_hosts_id"]);
         if (isset($pmComponentscatalog_Host->fields['itemtype']) and $pmComponentscatalog_Host->fields['itemtype'] != '') {
             $itemtype2 = $pmComponentscatalog_Host->fields['itemtype'];
             $item2 = new $itemtype2();
             $item2->getFromDB($pmComponentscatalog_Host->fields['items_id']);
             $title .= str_replace("'", "\"", $item2->getLink() . " (" . $item2->getTypeName() . " / " . $data['extra_infos'] . ")");
         }
         $width = "width: 475,";
     } else {
         if ($itemtype == "PluginMonitoringWeathermap") {
             $content = $item->showWidget($data['items_id'], $data['extra_infos']);
             $content = '<div id="weathermap-' . $data['items_id'] . '">' . $content . "</div>";
             $event = ", " . $item->widgetEvent($data['items_id']);
             $title .= " : " . Dropdown::getDropdownName(getTableForItemType('PluginMonitoringWeathermap'), $data['items_id']);
             $item->getFromDB($data['items_id']);
             $width = "width:" . $item->fields['width'] * $data['extra_infos'] / 100 . ",";
         } else {
             if ($itemtype2 != '') {
                 $content = $item->showWidget2($data['id']);
             } else {
                 $content = $item->showWidget($data['items_id']);
             }
             if ($data['itemtype'] == 'PluginMonitoringServicescatalog') {
                 $width = "width: 202,";
             } else {
                 $width = "width: 180,";
             }
         }
     }
     if ($config == 0 && $itemtype != "PluginMonitoringService") {
         $title = '';
     }
     echo "<script>\n         var left = 0;\n         var topd = 0;\n         var obj = document.getElementById('panel');\n         if (obj.offsetParent) {\n           do {\n             left += obj.offsetLeft;\n             topd += obj.offsetTop;\n           } while (obj = obj.offsetParent);\n         }\n\n        var item" . $data['id'] . " = new Ext.Panel({\n             closable: true,           \n             title: '" . $title . "',\n             x: " . $data['x'] . ",\n             y: " . $data['y'] . ",\n             html       : '" . $content . "',\n             baseCls : 'x-panel',\n             layout : 'fit',\n             bodyStyle: 'background:transparent',\n             ";
     if ($config == 0 && $itemtype != "PluginMonitoringService") {
         echo "border: false,";
     }
     echo "renderTo: Ext.getBody(),\n             floating: false,\n             frame: false,\n             " . $width . "\n             autoHeight  : true,\n             layout: 'fit',\n             draggable: {\n                 //Config option of Ext.Panel.DD class.\n                 //It's a floating Panel, so do not show a placeholder proxy in the original position.\n                 insertProxy: false,\n\n                 //Called for each mousemove event while dragging the DD object.\n                 onDrag : function(e){\n                     //Record the x,y position of the drag proxy so that we can\n                     //position the Panel at end of drag.\n                     var el = this.proxy.getEl();\n                     this.x = el.getLeft(true) - left - 5;\n                     this.y = el.getTop(true) - topd - 5;\n\n\n                     //Keep the Shadow aligned if there is one.\n                     var s = this.panel.getEl().shadow;\n                     if (s) {\n                         s.realign(this.x, this.y, pel.getWidth(), pel.getHeight());\n                     }\n                 },\n\n                 //Called on the mouseup event.\n                 endDrag : function(e){\n                     this.panel.setPosition(this.x, this.y);\n";
     if ($config == '1') {
         echo "      Ext.get('updatecoordonates').load({\n                        url: '" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/ajax/displayview_itemcoordinates.php',\n                        scripts: true,\n                        params:'id=" . $data['id'] . "&x=' + (this.x)  + '&y=' + (this.y)\n                     });\n";
         echo "      if (this.x < 1) {\n                        this.panel.destroy();\n                     }\n                     if (this.y < 0) {\n                        this.panel.destroy();\n                     }\n            \n            ";
     }
     echo "      }\n             }\n             " . $event . "\n         });\n     </script>";
     //.show()
     if ($itemtype == "PluginMonitoringService") {
         $pmComponent = new PluginMonitoringComponent();
         $item = new $itemtype();
         $item->getFromDB($data['items_id']);
         $pmComponent->getFromDB($item->fields['plugin_monitoring_components_id']);
         $pmServicegraph = new PluginMonitoringServicegraph();
         $pmServicegraph->displayGraph($pmComponent->fields['graph_template'], "PluginMonitoringService", $data['items_id'], "0", $data['extra_infos'], "js");
     } else {
         if ($itemtype == "PluginMonitoringComponentscatalog") {
             $pmComponentscatalog = new PluginMonitoringComponentscatalog();
             $pmComponentscatalog->ajaxLoad($data['items_id']);
         } else {
             if ($itemtype == "PluginMonitoringServicescatalog") {
                 $pmServicescatalog = new PluginMonitoringServicescatalog();
                 $pmServicescatalog->ajaxLoad($data['items_id']);
             } else {
                 if ($itemtype2 != '') {
                     $pmDisplayview = new PluginMonitoringDisplayview();
                     $pmDisplayview->ajaxLoad2($data['id']);
                 } else {
                     if ($itemtype == "PluginMonitoringDisplayview") {
                         $pmDisplayview = new PluginMonitoringDisplayview();
                         $pmDisplayview->ajaxLoad($data['items_id']);
                     }
                 }
             }
         }
     }
     if ($itemtype == "PluginMonitoringWeathermap") {
         //         echo "<script type='text/javascript'>
         //            function updateimagew".$data['items_id']."() {
         //               var demain=new Date();
         //               document.getElementById('weathermap-".$data['items_id']."').innerHTML = demain.getTime() + '".$content."';
         //            }
         //            setInterval(updateimagew".$data['items_id'].", 50000);
         //         </script>";
         //      }
         echo "<script type='text/javascript'>\n         var mgr = new Ext.UpdateManager('weathermap-" . $data['items_id'] . "');\n         mgr.startAutoRefresh(50, \"" . $CFG_GLPI["root_doc"] . "/plugins/monitoring/ajax/widgetWeathermap.php\", \"id=" . $data['items_id'] . "&extra_infos=" . $data['extra_infos'] . "\", \"\", true);\n         </script>";
     }
     return true;
 }
   function getRessources($componentscatalogs_id, $state, $state_type='HARD') {
      global $DB;

      $a_services = array();

      $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host();
      $pmService = new PluginMonitoringService();

      $query = "SELECT * FROM `glpi_plugin_monitoring_services`
         LEFT JOIN `".$pmComponentscatalog_Host->getTable()."`
            ON `plugin_monitoring_componentscatalogs_hosts_id`=
               `".$pmComponentscatalog_Host->getTable()."`.`id`
         WHERE `plugin_monitoring_componentscalalog_id`='".$componentscatalogs_id."'
            AND `state_type` LIKE '".$state_type."'
         ORDER BY `name`";
      $result = $DB->query($query);
      while ($data=$DB->fetch_array($result)) {
         $pmService->getFromDB($dataService["id"]);
         if ($pmService->getShortState()) {
         // if (PluginMonitoringHost::getState($data['state'],
                                               // $data['state_type'],
                                               // '',
                                               // $data['is_acknowledged']) == $state) {
            $a_services[] = $data;
         }
      }
      return $a_services;
   }
Example #18
0
 public function testPHPlogs()
 {
     global $CFG_GLPI, $PLUGIN_HOOKS;
     $_SESSION['glpi_use_mode'] = 2;
     $_SESSION["glpiID"] = 2;
     $_SESSION["glpiactiveentities_string"] = 0;
     $PLUGIN_HOOKS = plugin_init_monitoring();
     plugin::load("monitoring");
     $CFG_GLPI['root_doc'] = "http://127.0.0.1/fusion0.80/";
     loadLanguage("en_GB");
     $pmComponent = new PluginMonitoringComponent();
     $pmComponentscatalog = new PluginMonitoringComponentscatalog();
     $pmComponentscatalog_Component = new PluginMonitoringComponentscatalog_Component();
     $pmComponentscatalog_rule = new PluginMonitoringComponentscatalog_rule();
     $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host();
     $pmService = new PluginMonitoringService();
     $computer = new Computer();
     // Add components
     $input = array();
     $input['name'] = 'Host alive';
     $input['plugin_monitoring_commands_id '] = '21';
     $input['plugin_monitoring_checks_id'] = '1';
     $input['calendars_id'] = '1';
     $components_id = $pmComponent->add($input);
     // Add components catalog
     $input = array();
     $input['name'] = 'linux servers';
     $catalogs_id = $pmComponentscatalog->add($input);
     $input = array();
     $input['plugin_monitoring_componentscalalog_id'] = $catalogs_id;
     $input['plugin_monitoring_components_id'] = $components_id;
     $pmComponentscatalog_Component->add($input);
     // Add Computer
     $input = array();
     $input['name'] = 'pc1';
     $input['entities_id'] = 0;
     $pc1 = $computer->add($input);
     // Check computer pc1 not added in ressources
     $a_hosts = $pmComponentscatalog_Host->find("`plugin_monitoring_componentscalalog_id`='" . $catalogs_id . "'");
     $this->assertEquals(count($a_hosts), '0', '[f1] Computer in component cataglog and may not be');
     $input = array();
     $input['plugin_monitoring_componentscalalog_id'] = $catalogs_id;
     $input['name'] = 'all have name';
     $input['itemtype'] = 'Computer';
     $input['condition'] = '{"field":["1"],"searchtype":["contains"],"contains":["pc"],"itemtype":"Computer","start":"0"}';
     $rules_id = $pmComponentscatalog_rule->add($input);
     // Check computer pc1 not added in ressources
     $a_hosts = $pmComponentscatalog_Host->find("`plugin_monitoring_componentscalalog_id`='" . $catalogs_id . "'");
     $this->assertEquals(count($a_hosts), '1', '[f2] Computer may be in component catalog');
     // Check service of this computer created
     $a_services = $pmService->find();
     $this->assertEquals(count($a_services), '1', '[s2] One service may be created');
     // Add Computer
     $input = array();
     $input['name'] = 'pc2';
     $input['entities_id'] = 0;
     $pc2 = $computer->add($input);
     // Check computer pc1 not added in ressources
     $a_hosts = $pmComponentscatalog_Host->find("`plugin_monitoring_componentscalalog_id`='" . $catalogs_id . "'");
     $this->assertEquals(count($a_hosts), '2', '[f3] 2 computers may be in component catalog');
     // Check service of this computer created
     $a_services = $pmService->find();
     $this->assertEquals(count($a_services), '2', '[s3] 2 services may be created');
     // Remove pc2
     $computer->delete(array('id' => $pc2), 1);
     // Check computer pc1 added in ressources
     $a_hosts = $pmComponentscatalog_Host->find("`plugin_monitoring_componentscalalog_id`='" . $catalogs_id . "'");
     $this->assertEquals(count($a_hosts), '1', '[f4] Computer may be unique in component catalog');
     // Check service of this computer created
     $a_services = $pmService->find();
     $this->assertEquals(count($a_services), '1', '[s4] One service may be created');
     // Modify rule
     $input['id'] = $rules_id;
     $input['condition'] = '{"field":["1"],"searchtype":["contains"],"contains":["tc"],"itemtype":"Computer","start":"0"}';
     $pmComponentscatalog_rule->update($input);
     // Check no computer in ressources
     $a_hosts = $pmComponentscatalog_Host->find("`plugin_monitoring_componentscalalog_id`='" . $catalogs_id . "'");
     $this->assertEquals(count($a_hosts), '0', '[f5] Computer may be deleted on rule update');
     // Check service
     $a_services = $pmService->find();
     $this->assertEquals(count($a_services), '0', '[s5] No service may be created');
     // Modify rule
     $input['id'] = $rules_id;
     $input['condition'] = '{"field":["1"],"searchtype":["contains"],"contains":["pc"],"itemtype":"Computer","start":"0"}';
     $pmComponentscatalog_rule->update($input);
     // Check computer pc1 added in ressources
     $a_hosts = $pmComponentscatalog_Host->find("`plugin_monitoring_componentscalalog_id`='" . $catalogs_id . "'");
     $this->assertEquals(count($a_hosts), '1', '[f6] Computer may be unique in component catalog');
     // Delete rule
     $pmComponentscatalog_rule->delete(array('id' => $rules_id), 1);
     // Check not have computer in ressources
     $a_hosts = $pmComponentscatalog_Host->find("`plugin_monitoring_componentscalalog_id`='" . $catalogs_id . "'");
     $this->assertEquals(count($a_hosts), '0', '[f7] must have no computer in component catalog');
     // Check service
     $a_services = $pmService->find();
     $this->assertEquals(count($a_services), '0', '[s7] No service may be created');
 }
Example #19
0
   function displayCounters($type, $display=1) {
      global $DB,$CFG_GLPI;

      $ok = 0;
      $warningdata = 0;
      $warningconnection = 0;
      $critical = 0;
      $ok_soft = 0;
      $warningdata_soft = 0;
      $warningconnection_soft = 0;
      $critical_soft = 0;
      $acknowledge = 0;

      $play_sound = 0;

      if ($type == 'Ressources') {
         $ok = $this->countServicesQuery("
            `glpi_plugin_monitoring_services`.`state_type`='HARD'
            AND `glpi_plugin_monitoring_services`.`state`='OK'
            AND `glpi_plugin_monitoring_hosts`.`is_acknowledged`='0'
            AND `glpi_plugin_monitoring_services`.`is_acknowledged`='0'");

         $warningdata = $this->countServicesQuery("
            `glpi_plugin_monitoring_services`.`state_type`='HARD'
            AND (
                  (`glpi_plugin_monitoring_services`.`state`='WARNING' AND `glpi_plugin_monitoring_services`.`event` IS NOT NULL AND `glpi_plugin_monitoring_services`.`event` <> '') OR
                  (`glpi_plugin_monitoring_services`.`state`='RECOVERY') OR
                  (`glpi_plugin_monitoring_services`.`state`='FLAPPING')
            )
            AND `glpi_plugin_monitoring_hosts`.`is_acknowledged`='0'
            AND `glpi_plugin_monitoring_services`.`is_acknowledged`='0'");

         $warningconnection = $this->countServicesQuery("
            `glpi_plugin_monitoring_services`.`state_type`='HARD'
            AND (
                  (`glpi_plugin_monitoring_services`.`state`='WARNING' AND `glpi_plugin_monitoring_services`.`event` IS NULL) OR
                  (`glpi_plugin_monitoring_services`.`state`='UNKNOWN') OR
                  (`glpi_plugin_monitoring_services`.`state` IS NULL)
            )
            AND `glpi_plugin_monitoring_hosts`.`is_acknowledged`='0'
            AND `glpi_plugin_monitoring_services`.`is_acknowledged`='0'");

         $critical = $this->countServicesQuery("
            `glpi_plugin_monitoring_services`.`state_type`='HARD'
            AND `glpi_plugin_monitoring_services`.`state`='CRITICAL'
            AND `glpi_plugin_monitoring_hosts`.`is_acknowledged`='0'
            AND `glpi_plugin_monitoring_services`.`is_acknowledged`='0'");


         $ok_soft = $this->countServicesQuery("
            `glpi_plugin_monitoring_services`.`state_type`!='HARD'
            AND `glpi_plugin_monitoring_services`.`state`='OK'
            AND `glpi_plugin_monitoring_hosts`.`is_acknowledged`='0'
            AND `glpi_plugin_monitoring_services`.`is_acknowledged`='0'");

         $warningdata_soft = $this->countServicesQuery("
            `glpi_plugin_monitoring_services`.`state_type`!='HARD'
            AND (
                  (`glpi_plugin_monitoring_services`.`state`='WARNING' AND `glpi_plugin_monitoring_services`.`event` IS NOT NULL) OR
                  (`glpi_plugin_monitoring_services`.`state`='RECOVERY') OR
                  (`glpi_plugin_monitoring_services`.`state`='FLAPPING')
            )
            AND `glpi_plugin_monitoring_hosts`.`is_acknowledged`='0'
            AND `glpi_plugin_monitoring_services`.`is_acknowledged`='0'");

         $warningconnection_soft = $this->countServicesQuery("
            `glpi_plugin_monitoring_services`.`state_type`!='HARD'
            AND (
                  (`glpi_plugin_monitoring_services`.`state`='WARNING' AND `glpi_plugin_monitoring_services`.`event` IS NULL) OR
                  (`glpi_plugin_monitoring_services`.`state`='UNKNOWN') OR
                  (`glpi_plugin_monitoring_services`.`state` IS NULL)
            )
            AND `glpi_plugin_monitoring_hosts`.`is_acknowledged`='0'
            AND `glpi_plugin_monitoring_services`.`is_acknowledged`='0'");

         $critical_soft = $this->countServicesQuery("
            `glpi_plugin_monitoring_services`.`state_type`!='HARD'
            AND `glpi_plugin_monitoring_services`.`state`='CRITICAL'
            AND `glpi_plugin_monitoring_hosts`.`is_acknowledged`='0'
            AND `glpi_plugin_monitoring_services`.`is_acknowledged`='0'");


         $acknowledge = $this->countServicesQuery("
            `glpi_plugin_monitoring_services`.`is_acknowledged`='1'");
            // `glpi_plugin_monitoring_hosts`.`is_acknowledged`='1'
            // OR `glpi_plugin_monitoring_services`.`is_acknowledged`='1'");

         // ** Manage play sound if critical increase since last refresh
            if (isset($_SESSION['plugin_monitoring_dashboard_Ressources'])) {
               if ($critical > $_SESSION['plugin_monitoring_dashboard_Ressources']) {
                  $play_sound = 1;
               }
            }
            $_SESSION['plugin_monitoring_dashboard_Ressources'] = $critical;

      } else if ($type == 'Componentscatalog') {
         $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host();
         $queryCat = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs`";
         $resultCat = $DB->query($queryCat);
         while ($data=$DB->fetch_array($resultCat)) {

            $query = "SELECT COUNT(*) AS cpt FROM `".$pmComponentscatalog_Host->getTable()."`
               LEFT JOIN `glpi_plugin_monitoring_services`
                  ON `plugin_monitoring_componentscatalogs_hosts_id`=`".$pmComponentscatalog_Host->getTable()."`.`id`
               WHERE `plugin_monitoring_componentscalalog_id`='".$data['id']."'
                  AND (`state`='DOWN' OR `state`='UNREACHABLE' OR `state`='CRITICAL' OR `state`='DOWNTIME')
                  AND `state_type`='HARD'
                  AND `entities_id` IN (".$_SESSION['glpiactiveentities_string'].")
                  AND `is_acknowledged`='0'";
//            Toolbox::logInFile("pm", "Query critical - $query\n");
            $result = $DB->query($query);
            $data2 = $DB->fetch_assoc($result);
            if ($data2['cpt'] > 0) {
               $critical++;
            } else {
               $query = "SELECT COUNT(*) AS cpt, `glpi_plugin_monitoring_services`.`state`
                     FROM `".$pmComponentscatalog_Host->getTable()."`
                  LEFT JOIN `glpi_plugin_monitoring_services`
                     ON `plugin_monitoring_componentscatalogs_hosts_id`=`".$pmComponentscatalog_Host->getTable()."`.`id`
                  WHERE `plugin_monitoring_componentscalalog_id`='".$data['id']."'
                     AND (`state`='WARNING' OR `state`='UNKNOWN' OR `state`='RECOVERY' OR `state`='FLAPPING' OR `state` IS NULL)
                     AND `state_type`='HARD'
                     AND `entities_id` IN (".$_SESSION['glpiactiveentities_string'].")
                     AND `is_acknowledged`='0'";
               $result = $DB->query($query);
               $data2 = $DB->fetch_assoc($result);
               if ($data2['cpt'] > 0) {
                  $warningdata++;
               } else {
                  $query = "SELECT COUNT(*) AS cpt FROM `".$pmComponentscatalog_Host->getTable()."`
                     LEFT JOIN `glpi_plugin_monitoring_services`
                        ON `plugin_monitoring_componentscatalogs_hosts_id`=`".$pmComponentscatalog_Host->getTable()."`.`id`
                     WHERE `plugin_monitoring_componentscalalog_id`='".$data['id']."'
                     AND (`state`='OK' OR `state`='UP') AND `state_type`='HARD'
                     AND `entities_id` IN (".$_SESSION['glpiactiveentities_string'].")
                     AND `is_acknowledged`='0'";
                  $result = $DB->query($query);
                  $data2 = $DB->fetch_assoc($result);
                  if ($data2['cpt'] > 0) {
                     $ok++;
                  }
               }
            }

           $query = "SELECT COUNT(*) AS cpt FROM `".$pmComponentscatalog_Host->getTable()."`
               LEFT JOIN `glpi_plugin_monitoring_services`
                  ON `plugin_monitoring_componentscatalogs_hosts_id`=`".$pmComponentscatalog_Host->getTable()."`.`id`
               WHERE `plugin_monitoring_componentscalalog_id`='".$data['id']."'
                  AND (`state`='DOWN' OR `state`='UNREACHABLE' OR `state`='CRITICAL' OR `state`='DOWNTIME')
                  AND `state_type`='SOFT'
                  AND `entities_id` IN (".$_SESSION['glpiactiveentities_string'].")
                  AND `is_acknowledged`='0'";
            $result = $DB->query($query);
            $data2 = $DB->fetch_assoc($result);
            if ($data2['cpt'] > 0) {
               $critical_soft++;
            } else {
               $query = "SELECT COUNT(*) AS cpt FROM `".$pmComponentscatalog_Host->getTable()."`
                  LEFT JOIN `glpi_plugin_monitoring_services`
                     ON `plugin_monitoring_componentscatalogs_hosts_id`=`".$pmComponentscatalog_Host->getTable()."`.`id`
                  WHERE `plugin_monitoring_componentscalalog_id`='".$data['id']."'
                     AND (`state`='WARNING' OR `state`='UNKNOWN' OR `state`='RECOVERY' OR `state`='FLAPPING' OR `state` IS NULL)
                     AND `state_type`='SOFT'
                     AND `entities_id` IN (".$_SESSION['glpiactiveentities_string'].")
                     AND `is_acknowledged`='0'";
               $result = $DB->query($query);
               $data2 = $DB->fetch_assoc($result);
               if ($data2['cpt'] > 0) {
                  $warningdata_soft++;
               } else {
                  $query = "SELECT COUNT(*) AS cpt FROM `".$pmComponentscatalog_Host->getTable()."`
                     LEFT JOIN `glpi_plugin_monitoring_services`
                        ON `plugin_monitoring_componentscatalogs_hosts_id`=`".$pmComponentscatalog_Host->getTable()."`.`id`
                     WHERE `plugin_monitoring_componentscalalog_id`='".$data['id']."'
                        AND (`state`='OK' OR `state`='UP') AND `state_type`='SOFT'
                        AND `entities_id` IN (".$_SESSION['glpiactiveentities_string'].")
                        AND `is_acknowledged`='0'";
                  $result = $DB->query($query);
                  $data2 = $DB->fetch_assoc($result);
                  if ($data2['cpt'] > 0) {
                     $ok_soft++;
                  }
               }
            }
         }

         // ** Manage play sound if critical increase since last refresh
            if (isset($_SESSION['plugin_monitoring_dashboard_Componentscatalog'])) {
               if ($critical > $_SESSION['plugin_monitoring_dashboard_Componentscatalog']) {
                  $play_sound = 1;
               }
            }
            $_SESSION['plugin_monitoring_dashboard_Componentscatalog'] = $critical;

      } else if ($type == 'Businessrules') {
         $ok = countElementsInTable("glpi_plugin_monitoring_servicescatalogs",
                 "(`state`='OK' OR `state`='UP') AND `state_type`='HARD'
                 AND `entities_id` IN (".$_SESSION['glpiactiveentities_string'].")
                 AND `is_acknowledged`='0'");

         $warningdata = countElementsInTable("glpi_plugin_monitoring_servicescatalogs",
                 "(`state`='WARNING' OR `state`='UNKNOWN'
                        OR `state`='RECOVERY' OR `state`='FLAPPING')
                    AND `state_type`='HARD'
                    AND `entities_id` IN (".$_SESSION['glpiactiveentities_string'].")
                    AND `is_acknowledged`='0'");

         $critical = countElementsInTable("glpi_plugin_monitoring_servicescatalogs",
                 "(`state`='DOWN' OR `state`='UNREACHABLE' OR `state`='CRITICAL' OR `state`='DOWNTIME')
                    AND `state_type`='HARD'
                    AND `entities_id` IN (".$_SESSION['glpiactiveentities_string'].")
                    AND `is_acknowledged`='0'");

         $warningdata_soft = countElementsInTable("glpi_plugin_monitoring_servicescatalogs",
                 "(`state`='WARNING' OR `state`='UNKNOWN'
                        OR `state`='RECOVERY' OR `state`='FLAPPING')
                    AND `state_type`='SOFT'
                    AND `entities_id` IN (".$_SESSION['glpiactiveentities_string'].")
                    AND `is_acknowledged`='0'");

         $critical_soft = countElementsInTable("glpi_plugin_monitoring_servicescatalogs",
                 "(`state`='DOWN' OR `state`='UNREACHABLE' OR `state`='CRITICAL' OR `state`='DOWNTIME')
                    AND `state_type`='SOFT'
                    AND `entities_id` IN (".$_SESSION['glpiactiveentities_string'].")
                    AND `is_acknowledged`='0'");

         $ok_soft = countElementsInTable("glpi_plugin_monitoring_servicescatalogs",
                 "(`state`='OK' OR `state`='UP') AND `state_type`='SOFT'
                  AND `entities_id` IN (".$_SESSION['glpiactiveentities_string'].")
                    AND `is_acknowledged`='0'");

         // ** Manage play sound if critical increase since last refresh
            if (isset($_SESSION['plugin_monitoring_dashboard_Businessrules'])) {
               if ($critical > $_SESSION['plugin_monitoring_dashboard_Businessrules']) {
                  $play_sound = 1;
               }
            }
            $_SESSION['plugin_monitoring_dashboard_Businessrules'] = $critical;

      }
      if ($display == '0') {
         $a_return = array();
         $a_return['ok'] = strval($ok);
         $a_return['ok_soft'] = strval($ok_soft);
         $a_return['warningdata'] = strval($warningdata);
         $a_return['warningconnection'] = strval($warningconnection);
         $a_return['warningdata_soft'] = strval($warningdata_soft);
         $a_return['warningconnection_soft'] = strval($warningconnection_soft);
         $a_return['critical'] = strval($critical);
         $a_return['critical_soft'] = strval($critical_soft);
         $a_return['acknowledge'] = strval($acknowledge);
         return $a_return;
      }

      $critical_link = $CFG_GLPI['root_doc'].
               "/plugins/monitoring/front/service.php?hidesearch=1"
//              . "&reset=reset"
              . "&criteria[0][field]=3"
              . "&criteria[0][searchtype]=contains"
              . "&criteria[0][value]=CRITICAL"

              . "&criteria[1][link]=AND"
              . "&criteria[1][field]=7"
              . "&criteria[1][searchtype]=equals"
              . "&criteria[1][value]=0"

              . "&criteria[2][link]=AND"
              . "&criteria[2][field]=8"
              . "&criteria[2][searchtype]=equals"
              . "&criteria[2][value]=0"
              . "&search=Search"
              . "&itemtype=PluginMonitoringService"
              . "&start=0"
              . "&glpi_tab=3'";
      //_glpi_csrf_token=
      $warning_link = $CFG_GLPI['root_doc'].
               "/plugins/monitoring/front/service.php?hidesearch=1"
//              . "&reset=reset"
              . "&criteria[0][field]=3"
              . "&criteria[0][searchtype]=contains"
              . "&criteria[0][value]=FLAPPING"

              . "&criteria[1][link]=AND"
              . "&criteria[1][field]=7"
              . "&criteria[1][searchtype]=equals"
              . "&criteria[1][value]=0"

              . "&criteria[2][link]=AND"
              . "&criteria[2][field]=8"
              . "&criteria[2][searchtype]=equals"
              . "&criteria[2][value]=0"

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

              . "&criteria[4][link]=AND"
              . "&criteria[4][field]=7"
              . "&criteria[4][searchtype]=equals"
              . "&criteria[4][value]=0"

              . "&criteria[5][link]=AND"
              . "&criteria[5][field]=8"
              . "&criteria[5][searchtype]=equals"
              . "&criteria[5][value]=0"

              . "&criteria[6][link]=OR"
              . "&criteria[6][field]=3"
              . "&criteria[6][searchtype]=contains"
              . "&criteria[6][value]=UNKNOWN"

              . "&criteria[7][link]=AND"
              . "&criteria[7][field]=7"
              . "&criteria[7][searchtype]=equals"
              . "&criteria[7][value]=0"

              . "&criteria[8][link]=AND"
              . "&criteria[8][field]=8"
              . "&criteria[8][searchtype]=equals"
              . "&criteria[8][value]=0"

              . "&criteria[9][link]=AND"
              . "&criteria[9][field]=3"
              . "&criteria[9][searchtype]=contains"
              . "&criteria[9][value]=WARNING"

              . "&criteria[10][link]=AND"
              . "&criteria[10][field]=7"
              . "&criteria[10][searchtype]=equals"
              . "&criteria[10][value]=0"

              . "&criteria[11][link]=AND"
              . "&criteria[11][field]=8"
              . "&criteria[11][searchtype]=equals"
              . "&criteria[11][value]=0"

              . "&search=Search"
              . "&itemtype=PluginMonitoringService"
              . "&start=0"
              . "&glpi_tab=3'";
      $warningdata_link = $CFG_GLPI['root_doc'].
               "/plugins/monitoring/front/service.php?hidesearch=1"
//              . "&reset=reset"
              . "&criteria[0][field]=3"
              . "&criteria[0][searchtype]=contains"
              . "&criteria[0][value]=FLAPPING"

              . "&criteria[1][link]=AND"
              . "&criteria[1][field]=7"
              . "&criteria[1][searchtype]=equals"
              . "&criteria[1][value]=0"

              . "&criteria[2][link]=AND"
              . "&criteria[2][field]=8"
              . "&criteria[2][searchtype]=equals"
              . "&criteria[2][value]=0"

              . "&criteria[2][link]=OR"
              . "&criteria[3][field]=3"
              . "&criteria[3][searchtype]=contains"
              . "&criteria[3][value]=RECOVERY"

              . "&criteria[4][link]=AND"
              . "&criteria[4][field]=7"
              . "&criteria[4][searchtype]=equals"
              . "&criteria[4][value]=0"

              . "&criteria[5][link]=AND"
              . "&criteria[5][field]=8"
              . "&criteria[5][searchtype]=equals"
              . "&criteria[5][value]=0"

              . "&criteria[6][link]=OR"
              . "&criteria[6][field]=3"
              . "&criteria[6][searchtype]=contains"
              . "&criteria[6][value]=WARNING"

              . "&criteria[7][link]=AND"
              . "&criteria[7][field]=7"
              . "&criteria[7][searchtype]=equals"
              . "&criteria[7][value]=0"

              . "&criteria[8][link]=AND"
              . "&criteria[8][field]=8"
              . "&criteria[8][searchtype]=equals"
              . "&criteria[8][value]=0"

              . "&itemtype=PluginMonitoringService"
              . "&start=0"
              . "&glpi_tab=3'";
      $warningconnection_link = $CFG_GLPI['root_doc'].
               "/plugins/monitoring/front/service.php?hidesearch=1"
//              . "&reset=reset"
              . "&criteria[0][field]=3"
              . "&criteria[0][searchtype]=contains"
              . "&criteria[0][value]=UNKNOWN"

              . "&criteria[1][link]=AND"
              . "&criteria[1][field]=7"
              . "&criteria[1][searchtype]=equals"
              . "&criteria[1][value]=0"

              . "&criteria[2][link]=AND"
              . "&criteria[2][field]=8"
              . "&criteria[2][searchtype]=equals"
              . "&criteria[2][value]=0"

              . "&criteria[3][link]=OR"
              . "&criteria[3][field]=3"
              . "&criteria[3][searchtype]=contains"
              . "&criteria[3][value]=NULL"

              . "&criteria[4][link]=AND"
              . "&criteria[4][field]=7"
              . "&criteria[4][searchtype]=equals"
              . "&criteria[4][value]=0"

              . "&criteria[5][link]=AND"
              . "&criteria[5][field]=8"
              . "&criteria[5][searchtype]=equals"
              . "&criteria[5][value]=0"

              . "&itemtype=PluginMonitoringService"
              . "&start=0"
              . "&glpi_tab=3'";
      $ok_link = $CFG_GLPI['root_doc'].
               "/plugins/monitoring/front/service.php?hidesearch=1"
//              . "&reset=reset"
              . "&criteria[0][field]=3"
              . "&criteria[0][searchtype]=contains"
              . "&criteria[0][value]=OK"

              . "&itemtype=PluginMonitoringService"
              . "&start=0"
              . "&glpi_tab=3'";
      $acknowledge_link = $CFG_GLPI['root_doc'].
               "/plugins/monitoring/front/service.php?hidesearch=1"
//              . "&reset=reset"
              . "&criteria[0][field]=7"
              . "&criteria[0][searchtype]=equals"
              . "&criteria[0][value]=1"

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

      echo "<table align='center'>";
      echo "<tr>";
      echo "<td width='414'>";
         $background = '';
         if ($critical > 0) {
            $background = 'background="'.$CFG_GLPI['root_doc'].'/plugins/monitoring/pics/bg_critical.png"';
         }
         echo "<table class='tab_cadre' width='100%' height='130' ".$background." >";
         echo "<tr>";
         echo "<th style='background-color:transparent;'>";
         if ($type == 'Ressources' OR $type == 'Componentscatalog') {
            echo "<a href='".$critical_link.">".
                    "<font color='black' style='font-size: 12px;font-weight: bold;'>".__('Critical', 'monitoring')."</font></a>";
         } else {
            echo __('Critical', 'monitoring');
         }
         echo "</td>";
         echo "</tr>";
         echo "<tr>";
         echo "<th style='background-color:transparent;'>";
         if ($type == 'Ressources' OR $type == 'Componentscatalog') {
            echo "<a href='".$critical_link.">".
                    "<font color='black' style='font-size: 52px;font-weight: bold;'>".$critical."</font></a>";
         } else {
            echo "<font style='font-size: 52px;'>".$critical."</font>";
        }
         echo "</th>";
         echo "</tr>";
         echo "<tr><td>";
         echo "<p style='font-size: 11px; text-align: center;'> Soft : ".$critical_soft."</p>";
         echo "</td></tr>";
         echo "</table>";
      echo "</td>";

      echo "<td width='188'>";
         $background = '';
         if ($warningdata > 0) {
            $background = 'background="'.$CFG_GLPI['root_doc'].'/plugins/monitoring/pics/bg_warning.png"';
         }
         if ($type == 'Ressources') {
            echo "<table class='tab_cadre' width='100%' height='130' ".$background." >";
         } else {
            echo "<table class='tab_cadre' width='100%' height='130' ".$background." >";
         }
         echo "<tr>";
         echo "<th style='background-color:transparent;'>";
         if ($type == 'Ressources') {
            echo "<a href='".$warningdata_link.">".
                    "<font color='black' style='font-size: 12px;font-weight: bold;'>".__('Warning', 'monitoring')."</font></a>";
         } else {
            if ($type == 'Componentscatalog') {
               echo "<a href='".$warning_link.">".
                       "<font color='black' style='font-size: 12px;font-weight: bold;'>".__('Warning', 'monitoring')."</font></a>";
            } else {
               echo __('Warning', 'monitoring');
            }
         }
         echo "</td>";
         echo "</tr>";
         echo "<tr>";
         echo "<th style='background-color:transparent;'>";
         if ($type == 'Ressources') {
            echo "<a href='".$warningdata_link.">".
                    "<font color='black' style='font-size: 52px;'>".$warningdata."</font></a>";
         } else if ($type == 'Componentscatalog') {
            echo "<a href='".$warning_link.">".
                    "<font color='black' style='font-size: 52px;'>".$warningdata."</font></a>";
         } else {
            echo "<font style='font-size: 52px;'>".$warningdata."</font>";
         }
         echo "</th>";
         echo "</tr>";
         echo "<tr><td>";
         echo "<p style='font-size: 11px; text-align: center;'> Soft : ".$warningdata_soft."</p>";
         echo "</td></tr>";
         echo "</table>";
      echo "</td>";

      if ($type == 'Ressources') {
         echo "<td width='188'>";
            $background = '';
            if ($warningconnection > 0) {
               $background = 'background="'.$CFG_GLPI['root_doc'].'/plugins/monitoring/pics/bg_warning_yellow.png"';
            }
            echo "<table class='tab_cadre' width='100%' height='130' ".$background." >";
            echo "<tr>";
            echo "<th style='background-color:transparent;'>";
            if ($type == 'Ressources' OR $type == 'Componentscatalog') {
               echo "<a href='".$warningconnection_link.">".
                       "<font color='black' style='font-size: 12px;font-weight: bold;'>".__('Warning (connection)', 'monitoring')."</font></a>";
            } else {
               echo __('Warning (connection)', 'monitoring');
            }
            echo "</td>";
            echo "</tr>";
            echo "<tr>";
            echo "<th style='background-color:transparent;'>";
            if ($type == 'Ressources' OR $type == 'Componentscatalog') {
               echo "<a href='".$warningconnection_link.">".
                       "<font color='black' style='font-size: 52px;'>".$warningconnection."</font></a>";
            } else {
               echo "<font style='font-size: 52px;'>".$warningconnection."</font>";
            }
            echo "</th>";
            echo "</tr>";
            echo "<tr><td>";
            echo "<p style='font-size: 11px; text-align: center;'> Soft : ".$warningconnection_soft."</p>";
            echo "</td></tr>";
            echo "</table>";
         echo "</td>";
      }

      echo "<td width='148'>";
         $background = '';
         if ($ok > 0) {
            $background = 'background="'.$CFG_GLPI['root_doc'].'/plugins/monitoring/pics/bg_ok.png"';
         }
         echo "<table class='tab_cadre' width='100%' height='130' ".$background." >";
         echo "<tr>";
         echo "<th style='background-color:transparent;'>";
         if ($type == 'Ressources' OR $type == 'Componentscatalog') {
            echo "<a href='".$ok_link.">".
                    "<font color='black' style='font-size: 12px;font-weight: bold;'>".__('OK', 'monitoring')."</font></a>";
         } else {
            echo __('OK', 'monitoring');
         }
         echo "</td>";
         echo "</tr>";
         echo "<tr>";
         echo "<th style='background-color:transparent;'>";
         if ($type == 'Ressources' OR $type == 'Componentscatalog') {
            echo "<a href='".$ok_link.">".
                    "<font color='black' style='font-size: 52px;font-weight: bold;'>".$ok."</font></a>";
         } else {
            echo "<font style='font-size: 52px;'>".$ok."</font>";
         }
         echo "</th>";
         echo "</tr>";
         echo "<tr><td>";
         echo "<p style='font-size: 11px; text-align: center;'> Soft : ".$ok_soft."</p>";
         echo "</td></tr>";
         echo "</table>";
      echo "</td>";

      echo "<td width='120'>";
         $background = '';
         if ($acknowledge > 0) {
            $background = 'background="'.$CFG_GLPI['root_doc'].'/plugins/monitoring/pics/bg_acknowledge.png"';
         }
         echo "<table class='tab_cadre' width='100%' height='130' ".$background." >";
         echo "<tr>";
         echo "<th style='background-color:transparent;'>";
         if ($type == 'Ressources' OR $type == 'Componentscatalog') {
            echo "<a href='".$acknowledge_link."'>".
                    "<font color='black' style='font-size: 12px;font-weight: bold;'>".__('Acknowledge', 'monitoring')."</font></a>";
         } else {
            echo __('Acknowledge', 'monitoring');
         }
         echo "</td>";
         echo "</tr>";
         echo "<tr>";
         echo "<th style='background-color:transparent;'>";
         if ($type == 'Ressources' OR $type == 'Componentscatalog') {
            echo "<a href='".$acknowledge_link."'>".
                    "<font color='black' style='font-size: 52px;font-weight: bold;'>".$acknowledge."</font></a>";
         } else {
            echo "<font style='font-size: 52px;'>".$acknowledge."</font>";
         }
         echo "</th>";
         echo "</tr>";
         echo "<tr><td>";
         echo "<p style='font-size: 11px; text-align: center;'>&nbsp;</p>";
         echo "</td></tr>";
         echo "</table>";
      echo "</td>";

      echo "</tr>";
      echo "</table><br/>";

      // ** play sound
      if ($play_sound == '1') {
         echo '<audio autoplay="autoplay">
                 <source src="../audio/star-trek.ogg" type="audio/ogg" />
                 Your browser does not support the audio element.
               </audio>';
      }
   }