function showBADetail($id) { global $CFG_GLPI; $pMonitoringBusinessrule = new PluginMonitoringBusinessrule(); $pMonitoringBusinessrulegroup = new PluginMonitoringBusinessrulegroup(); $pMonitoringService = new PluginMonitoringService(); $this->getFromDB($id); echo "<table class='tab_cadrehov'>"; $a_groups = $pMonitoringBusinessrulegroup->find("`plugin_monitoring_servicescatalogs_id`='" . $id . "'"); echo "<tr class='tab_bg_1'>"; $color = PluginMonitoringDisplay::getState($this->fields['state'], $this->fields['state_type']); $pic = $color; $color = str_replace("_soft", "", $color); echo "<td rowspan='" . count($a_groups) . "' class='center' width='200' bgcolor='" . $color . "'>"; echo "<strong style='font-size: 20px'>" . $this->getName() . "</strong><br/>"; echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/box_" . $pic . "_40.png'/>"; echo "</td>"; $i = 0; foreach ($a_groups as $gdata) { $a_brulesg = $pMonitoringBusinessrule->find("`plugin_monitoring_businessrulegroups_id`='" . $gdata['id'] . "'"); if ($i > 0) { echo "<tr>"; } $state = array(); $state['red'] = 0; $state['red_soft'] = 0; $state['orange'] = 0; $state['orange_soft'] = 0; $state['green'] = 0; $state['green_soft'] = 0; foreach ($a_brulesg as $brulesdata) { $pMonitoringService->getFromDB($brulesdata['plugin_monitoring_services_id']); $state[PluginMonitoringDisplay::getState($pMonitoringService->fields['state'], $pMonitoringService->fields['state_type'])]++; } $color = ""; if ($gdata['operator'] == 'or') { if ($state['green'] >= 1) { $color = "green"; } else { if ($state['orange'] >= 1) { $color = "orange"; } else { if ($state['orange_soft'] >= 1) { $color = "orange"; } else { if ($state['red'] >= 1) { $color = "red"; } else { if ($state['red_soft'] >= 1) { $color = "red"; } } } } } } else { $num_min = str_replace(" of:", "", $gdata['operator']); if ($state['green'] >= $num_min) { $color = "green"; } else { if ($state['orange'] >= $num_min) { $color = "orange"; } else { if ($state['orange_soft'] >= $num_min) { $color = "orange"; } else { if ($state['red'] >= $num_min) { $color = "red"; } else { if ($state['red_soft'] >= $num_min) { $color = "red"; } } } } } } echo "<td class='center' bgcolor='" . $color . "'>"; echo $gdata['name'] . "<br/>[ " . $gdata['operator'] . " ]"; echo "</td>"; echo "<td bgcolor='" . $color . "'>"; echo "<table>"; foreach ($a_brulesg as $brulesdata) { echo "<tr class='tab_bg_1'>"; $pMonitoringService->getFromDB($brulesdata['plugin_monitoring_services_id']); PluginMonitoringDisplay::displayLine($pMonitoringService->fields); echo "</tr>"; } echo "</table>"; echo "</th>"; echo "</tr>"; $i++; } echo "</tr>"; echo "</table>"; }
function showBADetail($id) { global $CFG_GLPI; $pmParentSC = new PluginMonitoringServicescatalog(); $pMonitoringBusinessrule = new PluginMonitoringBusinessrule(); $pMonitoringBusinessrulegroup = new PluginMonitoringBusinessrulegroup(); $pMonitoringService = new PluginMonitoringService(); $this->getFromDB($id); $derivated = false; if ($this->getField('plugin_monitoring_servicescatalogs_id') > 0) { $derivated = true; $pmParentSC->getFromDB($this->getField('plugin_monitoring_servicescatalogs_id')); } // If SC is derivated from a template, get groups from its parent ... if ($derivated) { $a_groups = $pMonitoringBusinessrulegroup->find("`plugin_monitoring_servicescatalogs_id`='" . $pmParentSC->fields['id'] . "'"); } else { $a_groups = $pMonitoringBusinessrulegroup->find("`plugin_monitoring_servicescatalogs_id`='" . $id . "'"); } echo "<table class='tab_cadrehov'>"; echo "<tr class='tab_bg_1'>"; /* $color = $this->getShortState(); // $color = PluginMonitoringHost::getState($this->fields['state'], // $this->fields['state_type'], // 'data', // $this->fields['is_acknowledged']); $pic = $color; $color = str_replace("_soft", "", $color); */ echo "<td rowspan='" . count($a_groups) . "' class='center service" . $this->getField('state') . "' width='200'>"; echo "<strong style='font-size: 20px'>" . $this->getName() . "</strong><br/>"; echo "<img src='" . $this->getShortState(array('image' => '40')) . "'/>"; echo "</td>"; $i = 0; foreach ($a_groups as $gdata) { $a_brulesg = $pMonitoringBusinessrule->find("`plugin_monitoring_businessrulegroups_id`='" . $gdata['id'] . "'"); if ($i > 0) { echo "<tr>"; } $state = array(); $state['OK'] = 0; $state['WARNING'] = 0; $state['CRITICAL'] = 0; $state['UNKNOWN'] = 0; foreach ($a_brulesg as $brulesdata) { // If SC is derivated from a template, do not care about services not from the same entity ... if (!$pMonitoringService->getFromDB($brulesdata['plugin_monitoring_services_id'])) { continue; } if ($derivated && $pMonitoringService->getField('entities_id') != $this->getField('entities_id')) { continue; } $state[$pMonitoringService->getState()]++; } $overall_state = "OK"; if ($gdata['operator'] == 'and') { if ($state['UNKNOWN'] >= 1) { $overall_state = "UNKNOWN"; } else { if ($state['CRITICAL'] >= 1) { $overall_state = "CRITICAL"; } else { if ($state['WARNING'] >= 1) { $overall_state = "WARNING"; } else { if ($state['OK'] >= 1) { $overall_state = "OK"; } } } } } else { if ($gdata['operator'] == 'or') { if ($state['OK'] >= 1) { $overall_state = "OK"; } else { if ($state['WARNING'] >= 1) { $overall_state = "WARNING"; } else { if ($state['CRITICAL'] >= 1) { $overall_state = "CRITICAL"; } else { if ($state['UNKNOWN'] >= 1) { $overall_state = "UNKNOWN"; } } } } } else { $num_min = str_replace(" of:", "", $gdata['operator']); if ($state['OK'] >= $num_min) { $overall_state = "OK"; } else { if ($state['WARNING'] >= $num_min) { $overall_state = "WARNING"; } else { if ($state['CRITICAL'] >= $num_min) { $overall_state = "CRITICAL"; } else { if ($state['UNKNOWN'] >= $num_min) { $overall_state = "UNKNOWN"; } } } } } } echo "<td class='center service" . $overall_state . "'>"; echo $gdata['name'] . "<br/>[ " . $gdata['operator'] . " ]"; echo "</td>"; echo "<td class='service" . $overall_state . "'>"; echo "<table>"; foreach ($a_brulesg as $brulesdata) { // $pMonitoringService->getFromDB($brulesdata['plugin_monitoring_services_id']); // If SC is derivated from a template, do not care about services not from the same entity ... if (!$pMonitoringService->getFromDB($brulesdata['plugin_monitoring_services_id'])) { continue; } if ($derivated && $pMonitoringService->getField('entities_id') != $this->getField('entities_id')) { continue; } // Last parameter is true to display counters/graphs, false if not needed echo "<tr class='tab_bg_1'>"; // Display a line for the service including host information, no counters but graphs PluginMonitoringDisplay::displayLine($pMonitoringService->fields, true, false, true); echo "</tr>"; } echo "</table>"; echo "</th>"; echo "</tr>"; $i++; } echo "</tr>"; echo "</table>"; }
/** * 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 $LANG, $CFG_GLPI, $DB; $pmComponentscatalog = new PluginMonitoringComponentscatalog(); $query = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts`\n WHERE `items_id`='" . $items_id . "'\n AND `itemtype`='" . $itemtype . "'"; $result = $DB->query($query); // echo "<form name='form' method='post' // action='".$CFG_GLPI['root_doc']."/plugins/monitoring/front/service.form.php'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; echo "<th colspan='5'>"; echo $LANG['plugin_monitoring']['service'][0]; // echo " <a href='".$CFG_GLPI['root_doc']."/plugins/monitoring/front/service.form.php?services_id=".$a_hosts['id']."'> // <img src='".$CFG_GLPI['root_doc']."/pics/menu_add.png' /></a>"; // // echo " <a href='".$CFG_GLPI['root_doc']."/plugins/monitoring/front/servicedef.form.php?add_template=1'> // <img src='".$CFG_GLPI['root_doc']."/pics/menu_addtemplate.png' /></a>"; echo "</th>"; echo "</tr>"; echo "<table>"; while ($data = $DB->fetch_array($result)) { $pmComponentscatalog->getFromDB($data['plugin_monitoring_componentscalalog_id']); echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; echo "<th colspan='12'>" . $pmComponentscatalog->getTypeName() . " : " . $pmComponentscatalog->getLink() . "</th>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<th>"; echo $LANG['joblist'][0]; echo "</th>"; echo "<th>"; echo $LANG['entity'][0]; echo "</th>"; echo "<th>"; echo $LANG['stats'][7]; echo "</th>"; echo "<th>"; echo $LANG['plugin_monitoring']['component'][0]; echo "</th>"; echo "<th>"; echo $LANG['state'][0]; echo "</th>"; echo "<th>"; echo $LANG['plugin_monitoring']['service'][18]; echo "</th>"; echo "<th>"; echo $LANG['rulesengine'][82]; echo "</th>"; echo "<th>"; echo $LANG['plugin_monitoring']['host'][9]; echo "</th>"; echo "<th>" . $LANG['plugin_monitoring']['availability'][1] . " " . showToolTip($LANG['plugin_monitoring']['availability'][0], array('display' => false)) . "</th>"; echo "<th>" . $LANG['plugin_monitoring']['availability'][2] . " " . showToolTip($LANG['plugin_monitoring']['availability'][0], array('display' => false)) . "</th>"; echo "<th>" . $LANG['plugin_monitoring']['availability'][3] . " " . showToolTip($LANG['plugin_monitoring']['availability'][0], array('display' => false)) . "</th>"; echo "<th>"; echo $LANG['plugin_monitoring']['service'][4]; echo "</th>"; echo "</tr>"; $querys = "SELECT `glpi_plugin_monitoring_services`.* FROM `glpi_plugin_monitoring_services`\n LEFT JOIN `glpi_plugin_monitoring_components`\n on `plugin_monitoring_components_id` = `glpi_plugin_monitoring_components`.`id`\n WHERE `plugin_monitoring_componentscatalogs_hosts_id`='" . $data['id'] . "'\n 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($datas, 0); echo "</tr>"; } echo "</table>"; } // echo "<tr class='tab_bg_1'>"; // echo "<td colspan='8' align='center'>"; // echo "<input type='submit' class='submit' name='update' value='".$LANG['buttons'][7]."'>"; // echo "</td>"; // echo "</tr>"; echo "</table>"; echo "</form>"; }
/** * 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()." : ".$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(); }
/** * 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; $pmComponentscatalog = new PluginMonitoringComponentscatalog(); $query = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts`\n WHERE `items_id`='" . $items_id . "'\n AND `itemtype`='" . $itemtype . "'"; $result = $DB->query($query); // echo "<form name='form' method='post' // action='".$CFG_GLPI['root_doc']."/plugins/monitoring/front/service.form.php'>"; 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 " <a href='".$CFG_GLPI['root_doc']."/plugins/monitoring/front/service.form.php?services_id=".$a_hosts['id']."'> // <img src='".$CFG_GLPI['root_doc']."/pics/menu_add.png' /></a>"; // // echo " <a href='".$CFG_GLPI['root_doc']."/plugins/monitoring/front/servicedef.form.php?add_template=1'> // <img src='".$CFG_GLPI['root_doc']."/pics/menu_addtemplate.png' /></a>"; echo "</th>"; echo "</tr>"; echo "<table class='tab_cadre_fixe'>"; while ($data = $DB->fetch_array($result)) { $pmComponentscatalog->getFromDB($data['plugin_monitoring_componentscalalog_id']); echo "<tr class='tab_bg_1'>"; echo "<th colspan='14'>" . $pmComponentscatalog->getTypeName() . " : " . $pmComponentscatalog->getLink() . "</th>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<th>"; echo __('Status'); echo "</th>"; echo "<th>"; echo __('Entity'); echo "</th>"; echo "<th>"; echo __('Components', 'monitoring'); echo "</th>"; echo "<th>"; echo __('Components', 'monitoring'); echo "</th>"; echo "<th>"; echo __('Status'); echo "</th>"; echo "<th>"; echo __('Last check', 'monitoring'); echo "</th>"; echo "<th>"; echo __('Result details'); 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>"; echo __('Arguments', 'monitoring'); echo "</th>"; echo "</tr>"; $querys = "SELECT `glpi_plugin_monitoring_services`.* FROM `glpi_plugin_monitoring_services`\n LEFT JOIN `glpi_plugin_monitoring_components`\n on `plugin_monitoring_components_id` = `glpi_plugin_monitoring_components`.`id`\n WHERE `plugin_monitoring_componentscatalogs_hosts_id`='" . $data['id'] . "'\n 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($datas, 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(); }