function getInfoOfCatalog($componentscatalogs_id) { global $DB; $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host(); $pmService = new PluginMonitoringService(); $stateg = array(); $stateg['OK'] = 0; $stateg['WARNING'] = 0; $stateg['CRITICAL'] = 0; $stateg['UNKNOWN'] = 0; $stateg['ACKNOWLEDGE'] = 0; $a_gstate = array(); $nb_ressources = 0; $hosts_ids = array(); $hosts_states = array(); $services_ids = array(); $hosts_ressources = array(); $a_componentscatalogs_hosts = array(); $query = " SELECT CONCAT_WS('', `glpi_computers`.`name`, `glpi_printers`.`name`, `glpi_networkequipments`.`name`) AS name, CONCAT_WS('', `glpi_computers`.`entities_id`, `glpi_printers`.`entities_id`, `glpi_networkequipments`.`entities_id`) AS entities_id, `glpi_plugin_monitoring_componentscatalogs_hosts`.`id` AS catalog_id, `glpi_plugin_monitoring_hosts`.* FROM `glpi_plugin_monitoring_componentscatalogs_hosts` LEFT JOIN `glpi_computers` ON `glpi_plugin_monitoring_componentscatalogs_hosts`.`items_id` = `glpi_computers`.`id` AND `glpi_plugin_monitoring_componentscatalogs_hosts`.`itemtype`='Computer' LEFT JOIN `glpi_printers` ON `glpi_plugin_monitoring_componentscatalogs_hosts`.`items_id` = `glpi_printers`.`id` AND `glpi_plugin_monitoring_componentscatalogs_hosts`.`itemtype`='Printer' LEFT JOIN `glpi_networkequipments` ON `glpi_plugin_monitoring_componentscatalogs_hosts`.`items_id` = `glpi_networkequipments`.`id` AND `glpi_plugin_monitoring_componentscatalogs_hosts`.`itemtype`='NetworkEquipment' INNER JOIN `glpi_plugin_monitoring_hosts` ON (`glpi_plugin_monitoring_componentscatalogs_hosts`.`items_id` = `glpi_plugin_monitoring_hosts`.`items_id` AND `glpi_plugin_monitoring_componentscatalogs_hosts`.`itemtype` = `glpi_plugin_monitoring_hosts`.`itemtype`) WHERE `plugin_monitoring_componentscalalog_id`='".$componentscatalogs_id."' AND CONCAT_WS('', `glpi_computers`.`entities_id`, `glpi_printers`.`entities_id`, `glpi_networkequipments`.`entities_id`) IN (".$_SESSION['glpiactiveentities_string'].") ORDER BY entities_id ASC, name ASC"; // Toolbox::logInFile("pm", "query : $query\n"); $result = $DB->query($query); while ($dataComponentscatalog_Host=$DB->fetch_array($result)) { $ressources = array(); $fakeService = array(); $host_overall_state_ok = false; // Dummy service id ... $fakeService['name'] = '_fake_'; $fakeService['id'] = $dataComponentscatalog_Host['id'] + 1000000; $fakeService['is_acknowledged'] = $dataComponentscatalog_Host['is_acknowledged']; $fakeService['last_check'] = $dataComponentscatalog_Host['last_check']; $fakeService['event'] = $dataComponentscatalog_Host['event']; $fakeService['perf_data'] = $dataComponentscatalog_Host['perf_data']; $fakeService['state_type'] = $dataComponentscatalog_Host['state_type']; $fakeService['state'] = ($dataComponentscatalog_Host['is_acknowledged']=='1') ? 'ACKNOWLEDGE' : $dataComponentscatalog_Host['state']; $fakeService['state'] = ($dataComponentscatalog_Host['state_type']=='HARD') ? $fakeService['state'] : 'UNKNOWN'; switch($fakeService['state']) { case 'UP': $fakeService['state'] = 'OK'; $host_overall_state_ok = true; break; case 'DOWN': case 'UNREACHABLE': $fakeService['state'] = 'CRITICAL'; break; case 'DOWNTIME': $fakeService['state'] = 'ACKNOWLEDGE'; break; case 'WARNING': case 'RECOVERY': case 'FLAPPING': $fakeService['state'] = 'WARNING'; break; default: $fakeService['state'] = 'UNKNOWN'; break; } $queryService = "SELECT *, `glpi_plugin_monitoring_services`.`id` as serviceId, `glpi_plugin_monitoring_components`.`name`, `glpi_plugin_monitoring_components`.`description` FROM `".$pmService->getTable()."` INNER JOIN `glpi_plugin_monitoring_components` ON (`plugin_monitoring_components_id` = `glpi_plugin_monitoring_components`.`id`) WHERE `plugin_monitoring_componentscatalogs_hosts_id`='".$dataComponentscatalog_Host['catalog_id']."' AND `entities_id` IN (".$_SESSION['glpiactiveentities_string'].") ORDER BY `glpi_plugin_monitoring_services`.`name` ASC;"; // Toolbox::logInFile("pm", "query services - $queryService\n"); $resultService = $DB->query($queryService); while ($dataService=$DB->fetch_array($resultService)) { $nb_ressources++; $pmService->getFromDB($dataService["serviceId"]); if ($dataService['is_acknowledged'] == '1') { $dataService['state'] = 'ACKNOWLEDGE'; } // If not hard state, then unknown ... if ($dataService['state_type'] != "HARD") { $a_gstate[$dataService['id']] = "UNKNOWN"; if ($host_overall_state_ok) $host_overall_state_ok = false; } else { // $statecurrent = PluginMonitoringHost::getState($dataService['state'], // $dataService['state_type'], // $dataService['event'], // $dataService['is_acknowledged']); $statecurrent = $pmService->getShortState(); if ($statecurrent == 'green') { $a_gstate[$dataService['id']] = "OK"; } else if ($statecurrent == 'orange') { $a_gstate[$dataService['id']] = "WARNING"; if ($host_overall_state_ok) $host_overall_state_ok = false; } else if ($statecurrent == 'yellow') { $a_gstate[$dataService['id']] = "WARNING"; if ($host_overall_state_ok) $host_overall_state_ok = false; } else if ($statecurrent == 'red') { $a_gstate[$dataService['id']] = "CRITICAL"; if ($host_overall_state_ok) $host_overall_state_ok = false; } else if ($statecurrent == 'redblue') { $a_gstate[$dataService['id']] = "ACKNOWLEDGE"; if ($host_overall_state_ok) $host_overall_state_ok = false; } } $ressources[$dataService['name']] = $dataService; $services_ids[$dataService['name']] = $dataService['plugin_monitoring_components_id']; if (isset($dataService['id']) && isset($a_gstate[$dataService['id']])) { $stateg[$a_gstate[$dataService['id']]]++; } } if ($host_overall_state_ok) { $fakeService['state'] = 'OK'; } else { $fakeService['state'] = 'CRITICAL'; } $ressources[$fakeService['name']] = $fakeService; $services_ids[$fakeService['name']] = ''; $a_gstate[$fakeService['id']] = $fakeService['state']; // $stateg[$a_gstate[$fakeService['id']]]++; $hosts_ids[$dataComponentscatalog_Host['id']] = $dataComponentscatalog_Host; $hosts_states[$dataComponentscatalog_Host['id']] = $host_overall_state_ok; $a_componentscatalogs_hosts[$dataComponentscatalog_Host['catalog_id']] = $dataComponentscatalog_Host['catalog_id']; $hosts_ressources[$dataComponentscatalog_Host['id']] = $ressources; } return array($nb_ressources, $stateg, $hosts_ids, $services_ids, $hosts_ressources, $hosts_states, $a_componentscatalogs_hosts); }
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'] . " "; $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] . " :"; $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; }
function getInfoOfCatalog($componentscatalogs_id) { global $DB; $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host(); $pmService = new PluginMonitoringService(); $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`='" . $componentscatalogs_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++; if ($dataService['state_type'] != "HARD") { $a_gstate[$dataService['id']] = "OK"; } else { $statecurrent = PluginMonitoringDisplay::getState($dataService['state'], $dataService['state_type'], $dataService['event'], $dataService['is_acknowledged']); if ($statecurrent == 'green') { $a_gstate[$dataService['id']] = "OK"; } else { if ($statecurrent == 'orange') { $a_gstate[$dataService['id']] = "WARNING"; } else { if ($statecurrent == 'yellow') { $a_gstate[$dataService['id']] = "WARNING"; } else { if ($statecurrent == 'red') { $a_gstate[$dataService['id']] = "CRITICAL"; } } } } } } } foreach ($a_gstate as $value) { $stateg[$value]++; } return array($nb_ressources, $stateg); }