/**
* 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'])), '&');
$parameters = "sort=" . $data['search']['sort'] . "&order=" . $data['search']['order'] . '&' . $globallinkto;
if (isset($_GET['_in_modal'])) {
$parameters .= "&_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);
}