constructDatas() static public method

add to data array a field data containing : cols : columns definition rows : rows data
static public constructDatas ( array &$data ) : nothing
$data array array of search datas prepared to get datas
return nothing
 /**
  * Display list of hosts
  */
 function showHostsBoard($params, $width = '', $limit = '')
 {
     global $DB, $CFG_GLPI;
     if (!isset($_SESSION['plugin_monitoring_reduced_interface'])) {
         $_SESSION['plugin_monitoring_reduced_interface'] = false;
     }
     $col_to_display = array(0, 10, 1, 2, 3, 6, 7, 8, 9, 11);
     $data = Search::prepareDatasForSearch('PluginMonitoringHost', $params, $col_to_display);
     $data['tocompute'] = $data['toview'];
     Search::constructSQL($data);
     //echo "<pre>";      print_r($data['sql']['search']);
     Search::constructDatas($data);
     //      if (! isset($_GET['order'])) {
     //         $_GET['order'] = "ASC";
     //      }
     //      if (! isset($_GET['sort'])) {
     //         $_GET['sort'] = "";
     //      }
     //
     //      $order = "ASC";
     //      if (isset($_GET['order'])) {
     //         $order = $_GET['order'];
     //      }
     //      $where = '';
     //      if (isset($_GET['field'])) {
     //         foreach ($_GET['field'] as $key=>$value) {
     //            $wheretmp = '';
     //            if (isset($_GET['link'][$key])) {
     //               $wheretmp.= " ".$_GET['link'][$key]." ";
     //            }
     //            $wheretmp .= Search::addWhere(
     //                                   "",
     //                                   0,
     //                                   "PluginMonitoringHost",
     //                                   $_GET['field'][$key],
     //                                   $_GET['searchtype'][$key],
     //                                   $_GET['contains'][$key]);
     //            if (!strstr($wheretmp, "``.``")) {
     //               if ($where != ''
     //                       AND !isset($_GET['link'][$key])) {
     //                  $where .= " AND ";
     //               }
     //               $where .= $wheretmp;
     //            }
     //         }
     //      }
     //      if ($where != '') {
     //         $where = "(".$where;
     //         $where .= ") AND ";
     //      }
     //      $where .= " CONCAT_WS('', `glpi_computers`.`entities_id`, `glpi_printers`.`entities_id`, `glpi_networkequipments`.`entities_id`) IN (".$_SESSION['glpiactiveentities_string'].")";
     //
     //      if ($where != '') {
     //         $where = " WHERE ".$where;
     //         $where = str_replace("`".getTableForItemType("PluginMonitoringDisplay")."`.",
     //                 "", $where);
     //
     //      }
     //
     //      $leftjoin = "
     //         LEFT JOIN `glpi_computers`
     //            ON `glpi_plugin_monitoring_hosts`.`items_id` = `glpi_computers`.`id`
     //               AND `glpi_plugin_monitoring_hosts`.`itemtype`='Computer'
     //         LEFT JOIN `glpi_printers`
     //            ON `glpi_plugin_monitoring_hosts`.`items_id` = `glpi_printers`.`id`
     //               AND `glpi_plugin_monitoring_hosts`.`itemtype`='Printer'
     //         LEFT JOIN `glpi_networkequipments`
     //            ON `glpi_plugin_monitoring_hosts`.`items_id` = `glpi_networkequipments`.`id`
     //               AND `glpi_plugin_monitoring_hosts`.`itemtype`='NetworkEquipment'
     //         LEFT JOIN `glpi_entities`
     //            ON CONCAT_WS('', `glpi_computers`.`entities_id`, `glpi_printers`.`entities_id`, `glpi_networkequipments`.`entities_id`) = `glpi_entities`.`id`
     //
     //      ";
     //
     //      // * ORDER
     //      $ORDERQUERY = "ORDER BY entity_name ASC, host_name ASC";
     //      $toview = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
     //      $toviewComplete = array(
     //          'ITEM_0' => 'entity_name',
     //          'ITEM_1' => 'host_name',
     //          'ITEM_2' => 'host_state',
     //          'ITEM_3' => 'service_state',
     //          'ITEM_4' => 'last_check',
     //          'ITEM_5' => 'event',
     //          'ITEM_6' => 'perf_data',
     //          'ITEM_7' => 'is_acknowledged'
     //      );
     //      foreach ($toview as $key => $val) {
     //         if ($_GET['sort']==$val) {
     //            $ORDERQUERY = Search::addOrderBy("PluginMonitoringHost", $_GET['sort'],
     //                                             $_GET['order'], $key);
     //            foreach ($toviewComplete as $keyi=>$vali) {
     //               $ORDERQUERY= str_replace($keyi, $vali, $ORDERQUERY);
     //            }
     //         }
     //      }
     //
     ////            `glpi_computers`.*
     //
     //      $query = "SELECT
     //            `glpi_entities`.`name` AS entity_name,
     //            CONCAT_WS('', `glpi_computers`.`id`, `glpi_printers`.`id`, `glpi_networkequipments`.`id`) AS idComputer,
     //            CONCAT_WS('', `glpi_computers`.`name`, `glpi_printers`.`name`, `glpi_networkequipments`.`name`) AS host_name,
     //            `glpi_plugin_monitoring_hosts`.*,
     //            `glpi_plugin_monitoring_hosts`.`state` AS host_state,
     //            `glpi_plugin_monitoring_hosts`.`is_acknowledged` AS host_acknowledged
     //         FROM `glpi_plugin_monitoring_hosts`
     //         ".$leftjoin."
     //         ".$where."
     //         ".$ORDERQUERY;
     //      // Toolbox::logInFile("pm", "Query hosts - $query\n");
     //
     //      $result = $DB->query($query);
     //
     //      if (! isset($_GET["start"])) {
     //         $_GET["start"]=0;
     //      }
     //      $start=$_GET['start'];
     //      if (! isset($_GET["order"])) {
     //         $_GET["order"]="ASC";
     //      }
     $rand = mt_rand();
     if (!isset($data['data']) || !isset($data['data']['totalcount'])) {
         return false;
     }
     // Contruct Pager parameters
     $globallinkto = Toolbox::append_params(array('criteria' => Toolbox::stripslashes_deep($data['search']['criteria']), 'metacriteria' => Toolbox::stripslashes_deep($data['search']['metacriteria'])), '&amp;');
     $parameters = "sort=" . $data['search']['sort'] . "&amp;order=" . $data['search']['order'] . '&amp;' . $globallinkto;
     if (isset($_GET['_in_modal'])) {
         $parameters .= "&amp;_in_modal=1";
     }
     // If the begin of the view is before the number of items
     if ($data['data']['count'] > 0) {
         // Display pager only for HTML
         if ($data['display_type'] == Search::HTML_OUTPUT) {
             $search_config_top = "";
             $search_config_bottom = "";
             Html::printPager($data['search']['start'], $data['data']['totalcount'], $data['search']['target'], $parameters, $data['itemtype'], 0, $search_config_top);
         }
         // Define begin and end var for loop
         // Search case
         $begin_display = $data['data']['begin'];
         $end_display = $data['data']['end'];
     }
     echo '<div id="custom_date" style="display:none"></div>';
     echo '<div id="custom_time" style="display:none"></div>';
     if ($width == '') {
         echo "<table class='tab_cadrehov' style='width:100%;'>";
     } else {
         echo "<table class='tab_cadrehov' style='width:" . $width . "px;'>";
     }
     $num = 0;
     if (Session::haveRight("plugin_monitoring_hostcommand", CREATE)) {
         // Host test command ...
         $pmCommand = new PluginMonitoringCommand();
         $a_commands = array();
         $a_list = $pmCommand->find("command_name LIKE 'host_action'");
         foreach ($a_list as $dt) {
             $host_command_name = $dt['name'];
             $host_command_command = $dt['command_line'];
         }
     }
     echo "<tr class='tab_bg_1'>";
     $this->showHeaderItem(__('Entity'), 0, $num, $begin_display, $globallinkto, 'host.php', 'PluginMonitoringHost');
     $this->showHeaderItem(__('Type'), 0, $num, $begin_display, $globallinkto, 'host.php', 'PluginMonitoringHost');
     $this->showHeaderItem(__('Host', 'monitoring'), 1, $num, $begin_display, $globallinkto, 'host.php', 'PluginMonitoringHost');
     $this->showHeaderItem(__('Host state'), 2, $num, $begin_display, $globallinkto, 'host.php', 'PluginMonitoringHost');
     if (isset($host_command_name)) {
         echo '<th>' . __('Host action', 'monitoring') . '</th>';
     }
     echo '<th>' . __('Host resources state', 'monitoring') . '</th>';
     echo '<th>' . __('IP address', 'monitoring') . '</th>';
     $this->showHeaderItem(__('Last check', 'monitoring'), 4, $num, $begin_display, $globallinkto, 'host.php', 'PluginMonitoringHost');
     $this->showHeaderItem(__('Result details', 'monitoring'), 5, $num, $begin_display, $globallinkto, 'host.php', 'PluginMonitoringHost');
     $this->showHeaderItem(__('Performance data', 'monitoring'), 6, $num, $begin_display, $globallinkto, 'host.php', 'PluginMonitoringHost');
     if (Session::haveRight("plugin_monitoring_acknowledge", READ) || Session::haveRight("plugin_monitoring_downtime", READ)) {
         $this->showHeaderItem(__('Maintenance', 'monitoring'), 7, $num, $begin_display, $globallinkto, 'host.php', 'PluginMonitoringHost');
     }
     echo "</tr>";
     foreach ($data['data']['rows'] as $row) {
         // Reduced array or not ?
         if ($_SESSION['plugin_monitoring_reduced_interface'] && $row[3]['displayname'] == 'UP') {
             continue;
         }
         if (isset($host_command_name)) {
             $row['host_command_name'] = $host_command_name;
             $row['host_command_command'] = $host_command_command;
         }
         // Get all host services except if state is ok or is already acknowledged ...
         $a_ret = PluginMonitoringHost::getServicesState($row['id'], "`glpi_plugin_monitoring_services`.`state` != 'OK'\n                                                         AND `glpi_plugin_monitoring_services`.`is_acknowledged` = '0'");
         $row['host_services_state'] = $a_ret[0];
         $row['host_services_state_list'] = $a_ret[1];
         // Get host first IP address
         $row['ip'] = __('Unknown IP address', 'monitoring');
         $ip = PluginMonitoringHostaddress::getIp($row[9]['displayname'], $row[1]['displayname'], '');
         if ($ip != '') {
             $row['ip'] = $ip;
         }
         echo "<tr class='tab_bg_3'>";
         $this->displayHostLine($row);
         echo "</tr>";
     }
     echo "</table>";
     echo "<br/>";
     Html::printPager($data['search']['start'], $data['data']['totalcount'], $data['search']['target'], $parameters, '', 0, $search_config_bottom);
 }
Esempio n. 2
0
   /**
    * Display services associated with host
    *
    * @param $itemtype value type of item
    * @param $items_id integer id of the object
    *
    **/
   function listByHost($itemtype, $items_id) {
      global $CFG_GLPI,$DB;

      $params = Search::manageParams("PluginMonitoringService", array(), false);
      $num = 20; // Computer
      if ($itemtype == 'Printer') {
         $num = 21;
      } else if ($itemtype == 'NetworkEquipment') {
         $num = 22;
      }
      $params['criteria'][0] = array(
         'field'      => $num,
         'searchtype' => 'is',
         'value'      => $items_id
      );
      $col_to_display = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);

      $data = Search::prepareDatasForSearch('PluginMonitoringService', $params, $col_to_display);
      $data['tocompute'] = $data['toview'];
      Search::constructSQL($data);
      Search::constructDatas($data);

      $pmComponentscatalog = new PluginMonitoringComponentscatalog();

      $services_id = array();
      foreach ($data['data']['rows'] as $row) {
         $services_id[] = $row['id'];
      }
      $oldvalue = current(getAllDatasFromTable(
              'glpi_plugin_monitoring_serviceevents',
              "`plugin_monitoring_services_id` IN ('".implode("', '", $services_id)."')",
              false,
              'date ASC LIMIT 1'));
      $date = new DateTime($oldvalue['date']);
      $start = time();
      if ($date->getTimestamp() < $start) {
         $start = $date->getTimestamp();
      }

      $nbdays = round((date('U') - $start) / 86400);
      echo "<script type=\"text/javascript\">
      $(function() {
          $( \"#custom_date\" ).datepicker({ minDate: -".$nbdays.", maxDate: \"+0D\", dateFormat:'mm/dd/yy' });
          $( \"#custom_time\" ).timepicker();

      });
      </script>";

      echo '<center><input type="text" id="custom_date" value="'.date('m/d/Y').'"> '
              . ' <input type="text" id="custom_time" value="'.date('H:i').'"></center>';

      echo '<div id="custom_date" style="display:none"></div>';
      echo '<div id="custom_time" style="display:none"></div>';

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

      echo "<tr class='tab_bg_1'>";
      echo "<th colspan='5'>";
      echo __('Resources', 'monitoring');
      $item = new $itemtype();
      $item->getFromDB($items_id);
      echo " - ".$item->getTypeName();
      echo " - ".$item->getName();
      echo "</th>";
      echo "</tr>";

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

      foreach ($data['data']['rows'] as $row) {
         $pmComponentscatalog->getFromDB($row[8][0]['id']);

         echo "<tr class='tab_bg_1'>";
         echo "<th colspan='14'>".$pmComponentscatalog->getTypeName()."&nbsp;:&nbsp;".$pmComponentscatalog->getLink()."</th>";
         echo "</tr>";

         echo "<tr class='tab_bg_1'>";
         // echo "<th>";
         // echo __('Show counters', 'monitoring');
         // echo "</th>";
         echo "<th>";
         echo __('Show graphics', 'monitoring');
         echo "</th>";
         echo "<th>";
         echo __('Component', 'monitoring');
         echo "</th>";
         echo "<th>";
         echo __('Resource state', 'monitoring');
         echo "</th>";
         echo "<th>";
         echo __('Last check', 'monitoring');
         echo "</th>";
         echo "<th>";
         echo __('Result details', 'monitoring');
         echo "</th>";
         echo "<th>";
         echo __('Check period', 'monitoring');
         echo "</th>";
         echo "<th>".__('Current month', 'monitoring')." ".Html::showToolTip(__('Availability', 'monitoring'), array('display'=>false))."</th>";
         echo "<th>".__('Last month', 'monitoring')." ".Html::showToolTip(__('Availability', 'monitoring'), array('display'=>false))."</th>";
         echo "<th>".__('Current year', 'monitoring')." ".Html::showToolTip(__('Availability', 'monitoring'), array('display'=>false))."</th>";
         echo "<th>".__('Detail', 'monitoring')."</th>";
         echo '<th>'.__('Acknowledge', 'monitoring').'</th>';
         echo "<th>".__('Arguments', 'monitoring')."</th>";
         echo "</tr>";

//         $querys = "SELECT `glpi_plugin_monitoring_services`.* FROM `glpi_plugin_monitoring_services`
//            LEFT JOIN `glpi_plugin_monitoring_components`
//               on `plugin_monitoring_components_id` = `glpi_plugin_monitoring_components`.`id`
//            WHERE `plugin_monitoring_componentscatalogs_hosts_id`='".$row['id']."'
//               ORDER BY `name`";
//         $results = $DB->query($querys);
//         while ($datas=$DB->fetch_array($results)) {
//            $this->getFromDB($datas['id']);

            echo "<tr class='tab_bg_1'>";
            PluginMonitoringDisplay::displayLine($row, 0);
            echo "</tr>";

//         }

         echo "<tr style='border:1px solid #ccc;background-color:#ffffff'>";
         echo "<td colspan='14' height='5'></td>";
         echo "</tr>";
      }

      echo "</table>";

      Html::closeForm();
   }