GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with Monitoring. If not, see <http://www.gnu.org/licenses/>. ------------------------------------------------------------------------ @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 2013 ------------------------------------------------------------------------ */ include "../../../inc/includes.php"; Session::checkRight("plugin_monitoring_unavailability", READ); Html::header(__('Monitoring - unavailabilities', 'monitoring'), $_SERVER["PHP_SELF"], "plugins", "monitoring", "unavailability"); if (isset($_GET['id'])) { $pmUnavailability = new PluginMonitoringUnavailability(); $pmUnavailability->getFromDB($_GET['id']); $input = array(); $input['id'] = $_GET['id']; $input['scheduled'] = $_GET['scheduled']; $pmUnavailability->update($input); } Html::redirect($_SERVER['HTTP_REFERER']);
static function runUnavailability($services_id = 0, $start = 0, $limit = 100000) { global $DB; $limit = 10000; $pmUnavailability = new PluginMonitoringUnavailability(); $pmUnavailabilityState = new PluginMonitoringUnavailabilityState(); $pmServiceevent = new PluginMonitoringServiceevent(); $where = ''; if ($services_id != '0') { $where = " WHERE `id`='" . $services_id . "' "; } $query = "SELECT `id` FROM `glpi_plugin_monitoring_services` " . $where . " "; $result = $DB->query($query); // $nb = 0; // $tttime = 0; while ($data = $DB->fetch_array($result)) { $pmUnavailability->getCurrentState($data['id']); // Toolbox::logInFile('UNAV', "======= ".$data['id']." =======\n"); $serviceevents_id = $pmUnavailabilityState->getLastID($data['id']); // $loop = 0; while (true) { // Toolbox::logInFile('UNAV', "start (loop ".$loop.")\n"); // $time = microtime(); // $time = explode(' ', $time); // $time = $time[1] + $time[0]; // $start = $time; $query2 = "SELECT `id`,`state`,`date`,`event`\n FROM `glpi_plugin_monitoring_serviceevents`\n USE INDEX (unavailability)\n WHERE `unavailability` IN (0, 1)\n AND `state_type`='HARD'\n AND `plugin_monitoring_services_id`='" . $data['id'] . "'\n ORDER BY `id`\n LIMIT {$serviceevents_id}, {$limit}"; $result2 = $DB->query($query2); //Toolbox::logInFile('UNAV', "LIMIT $serviceevents_id, $limit (".$DB->numrows($result2).")\n"); $stop = False; if ($DB->numrows($result2) < $limit) { $stop = True; // $nb += $DB->numrows($result2); $serviceevents_id += $DB->numrows($result2); } else { $serviceevents_id += $limit; // $nb += $limit; } while ($data2 = $DB->fetch_array($result2)) { $pmUnavailability->checkState($data2['state'], $data2['date'], $data['id'], $DB->escape($data2['event'])); } $pmUnavailabilityState->setLastID($data['id'], $serviceevents_id); // $time = microtime(); // $time = explode(' ', $time); // $time = $time[1] + $time[0]; // $finish = $time; // $total_time = round(($finish - $start), 4); // $tttime += $total_time; // Toolbox::logInFile('UNAV', "end (".$total_time." seconds - ".$nb." / ".$tttime.")\n"); // $loop++; if ($stop) { break; } } } }
static function displayLine($data, $displayhost = 1, $displayCounters = 0, $displayGraphs = true) { global $CFG_GLPI; $pMonitoringService = new PluginMonitoringService(); $pMonitoringService->getFromDB($data['id']); $pMonitoringComponent = new PluginMonitoringComponent(); $pMonitoringComponent->getFromDB($data[1][0]['id']); $networkPort = new NetworkPort(); // If host is acknowledged, force service to be displayed as unknown acknowledged. if (isset($data[7][0]['name']) && $data[7][0]['name']) { $shortstate = 'yellowblue'; $data['state'] = 'UNKNOWN'; } else { $shortstate = PluginMonitoringHost::getState($data[2]['displayname'], $data[3]['displayname'], $data[5]['displayname'], $pMonitoringService->isCurrentlyAcknowledged()); } $timezone = '0'; if (isset($_SESSION['plugin_monitoring_timezone'])) { $timezone = $_SESSION['plugin_monitoring_timezone']; } if ($displayGraphs) { if (!isset($_SESSION['plugin_monitoring_reduced_interface']) || !$_SESSION['plugin_monitoring_reduced_interface']) { echo "<td class='center'>"; // Even if not exist incremental perfdata ... if ($pMonitoringComponent->hasPerfdata()) { echo "<a href='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/display.form.php?itemtype=PluginMonitoringService&items_id=" . $data['id'] . "'>"; ob_start(); $pmServicegraph = new PluginMonitoringServicegraph(); $pmServicegraph->displayGraph($pMonitoringComponent->fields['graph_template'], "PluginMonitoringService", $data['id'], "0", '2h', "div", "600"); $div = ob_get_contents(); ob_end_clean(); $chart = "<table width='600' class='tab_cadre'><tr><td>" . $div . "</td></tr></table>"; $qtip = Html::showToolTip($chart, array('img' => $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/stats_32.png' width='26' height='32'", 'display' => false)); $qtip = str_replace('qtip-shadow qtip-bootstrap', 'qtip-shadow qtip-bootstrap qtip-monitoring', $qtip); echo $qtip; $pmServicegraph->displayGraph($pMonitoringComponent->fields['graph_template'], "PluginMonitoringService", $data['id'], "0", '2h', "js"); echo "</a>"; } echo "</td>"; } } if ($displayhost) { $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host(); $pmComponentscatalog_Host->getFromDB($data[10]["displayname"]); if (isset($pmComponentscatalog_Host->fields['itemtype']) and $pmComponentscatalog_Host->fields['itemtype'] != '') { echo "<td>"; $itemtype = $pmComponentscatalog_Host->fields['itemtype']; $item = new $itemtype(); $item->getFromDB($pmComponentscatalog_Host->fields['items_id']); // echo "<span>".$item->getLink(array ("monitoring" => "1"))."</span> "; if (!is_null($pMonitoringService->fields['networkports_id']) and $pMonitoringService->fields['networkports_id'] > 0) { $networkPort->getFromDB($pMonitoringService->fields['networkports_id']); echo "[" . $networkPort->getLink() . "] "; } $pm_Host = new PluginMonitoringHost(); $pm_Host->getFromDB($pMonitoringService->getHostID()); echo "<span>" . $pm_Host->getLink(array("monitoring" => "1")) . "</span>"; echo "</td>"; } else { echo "<td>" . __('Resources', 'monitoring') . "</td>"; } } echo "<td>"; if (Session::haveRight("plugin_monitoring_component", READ)) { echo $pMonitoringComponent->getLink(); } else { echo $pMonitoringComponent->getName(); } if (!is_null($pMonitoringService->fields['networkports_id']) and $pMonitoringService->fields['networkports_id'] > 0) { $networkPort->getFromDB($pMonitoringService->fields['networkports_id']); echo " [" . $networkPort->getLink() . "]"; } echo "</td>"; if ($displayCounters) { $ar_counters = $pMonitoringComponent->hasCounters(); // Toolbox::logInFile("pm", "Counters : ".serialize($ar_counters)."\n"); if (is_array($ar_counters)) { $pmServicegraph = new PluginMonitoringServicegraph(); foreach ($ar_counters as $counter => $counter_title) { PluginMonitoringDisplay::$ar_counterTypes[$counter] = $counter_title; $html = $pmServicegraph->displayCounter($pMonitoringComponent->fields['graph_template'], $data['id'], false, $counter, $counter_title); echo "<td class='center'>{$html}</td>"; } } } else { echo "<td class='center page foldtl resource" . $data[2]['displayname'] . " resource" . $data[3]['displayname'] . "'>"; echo "<div class=''>"; echo "<div>"; echo $data[2]['displayname']; echo "</div>"; echo "</div>"; echo "</td>"; echo "<td>"; echo Html::convDate($data[4]['displayname']) . ' ' . substr($data[4]['displayname'], 11, 8); echo "</td>"; echo "<td>"; echo $data[5]['displayname']; echo "</td>"; echo "<td align='center'>"; $segments = CalendarSegment::getSegmentsBetween($pMonitoringComponent->fields['calendars_id'], date('w', date('U')), date('H:i:s'), date('w', date('U')), date('H:i:s')); if (count($segments) == '0') { echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/service_pause.png' />"; } else { echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/service_run.png' />"; } echo "</td>"; if (!$displayhost) { $pmUnavailability = new PluginMonitoringUnavailability(); $pmUnavailability->displayValues($pMonitoringService->fields['id'], 'currentmonth', 1); $pmUnavailability->displayValues($pMonitoringService->fields['id'], 'lastmonth', 1); $pmUnavailability->displayValues($pMonitoringService->fields['id'], 'currentyear', 1); echo "<td class='center'>"; echo "<a href='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/unavailability.php?" . "&criteria[0][field]=2" . "&criteria[0][searchtype]=equals" . "&criteria[0][value]=" . $pMonitoringService->fields['id'] . "&itemtype=PluginMonitoringUnavailability" . "&start=0" . "&sort=1" . "&order=DESC'>\n <img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/info.png'/></a>"; echo "</td>"; } if (Session::haveRight("plugin_monitoring_acknowledge", READ)) { echo "<td>"; if ($pMonitoringService->isCurrentlyAcknowledged()) { if (Session::haveRight("plugin_monitoring_acknowledge", CREATE)) { echo "<span>"; echo "<a href='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/acknowledge.form.php?itemtype=Service&items_id=" . $data['id'] . "'>" . "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/acknowledge_ok.png'" . " alt='" . htmlspecialchars(__('Modify acknowledge comment for the service', 'monitoring'), ENT_QUOTES) . "'" . " title='" . htmlspecialchars(__('Modify acknowledge comment for the service', 'monitoring'), ENT_QUOTES) . "'" . " width='25' height='20'/>" . "</a>"; echo " </span>"; } else { echo "<span>"; echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/acknowledge_ok.png'" . " alt='" . htmlspecialchars(__('Service problem has been acknowledged', 'monitoring'), ENT_QUOTES) . "'" . " title='" . htmlspecialchars(__('Service problem has been acknowledged', 'monitoring'), ENT_QUOTES) . "'" . " width='25' height='20'/>"; echo " </span>"; } // Display acknowledge data ... $pMonitoringService->getAcknowledge(); } else { if ($shortstate == 'red' || $shortstate == 'yellow' || $shortstate == 'orange' || !empty($data['host_services_state_list'])) { if (Session::haveRight("plugin_monitoring_acknowledge", CREATE)) { echo "<span>"; echo "<a href='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/acknowledge.form.php?itemtype=Service&items_id=" . $data['id'] . "'>" . "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/pics/acknowledge_ko.png'" . " alt='" . htmlspecialchars(__('Add an acknowledge for the service', 'monitoring'), ENT_QUOTES) . "'" . " title='" . htmlspecialchars(__('Add an acknowledge for the service', 'monitoring'), ENT_QUOTES) . "'" . " width='25' height='20'/>" . "</a>"; echo " </span>"; } } } echo "</td>"; } } if ($displayhost == '0') { echo "<td>"; if (Session::haveRight("plugin_monitoring_componentscatalog", UPDATE)) { if ($pMonitoringComponent->fields['remotesystem'] == 'nrpe' && $pMonitoringComponent->fields['is_arguments'] == 0) { echo __('Managed by NRPE', 'monitoring'); } else { $a_arg = importArrayFromDB($pMonitoringService->fields['arguments']); $cnt = ''; if (count($a_arg) > 0) { $cnt = " (" . count($a_arg) . ")"; } echo "<a href='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/servicearg.form.php?id=" . $data['id'] . "'>" . __('Configure', 'monitoring') . $cnt . "</a>"; } } echo "</td>"; } }
function generateSyntheseReport($array, $pdf=TRUE) { global $DB; if (count($array) == 0) { return; } $end_date = $array['synthesedate_end']; $end_date_timestamp = strtotime($end_date); $number = $array['synthesenumber']; $period = $array['syntheseperiod']; $componentscatalogs_id = $array['componentscatalogs_id']; $pmComponent = new PluginMonitoringComponent(); $pmUnavailability = new PluginMonitoringUnavailability(); $pmServiceevent = new PluginMonitoringServiceevent(); if ($pdf) { PluginMonitoringReport::beginCapture(); } echo "<table class='tab_cadrehov'>"; foreach ($array['components_id'] as $components_id) { $pmComponent->getFromDB($components_id); array_unshift($array['perfname'][$components_id], 'avaibility'); array_unshift($array['perfname_val'][$components_id], 1); echo '<tr class="tab_bg_1" height="90">'; echo '<th colspan="'.(3 + ($number * 2)).'">'; echo $pmComponent->getName(); echo '</th>'; echo '</tr>'; foreach ($array['perfname'][$components_id] as $num=>$groupname) { echo '<tr class="tab_bg_1">'; echo '<th colspan="'.(3 + ($number * 2)).'">'; if ($groupname == 'avaibility') { echo __('Avaibility', 'monitoring'); } else { echo $groupname; } echo '</th>'; echo '</tr>'; echo '<tr class="tab_bg_1">'; echo '<th rowspan="2">'; echo __('Name'); echo '</th>'; echo '<th rowspan="2">'; echo __('Entity'); echo '</th>'; echo '<th rowspan="2">'; echo __('Itemtype'); echo '</th>'; $a_year = array(); for ($i = $number; $i >= 1;$i--) { $year = date('Y', strtotime("-".$i." ".$period, $end_date_timestamp)); if (!isset($a_year[$year])) { $a_year[$year] = 2; } else { $a_year[$year] += 2; } } foreach ($a_year as $year=>$colspan) { echo '<th colspan="'.$colspan.'">'; echo $year; echo '</th>'; } echo '</tr>'; echo '<tr class="tab_bg_1">'; for ($i = $number; $i >= 1;$i--) { echo '<th colspan="2">'; echo Html::convDate(date('m-d', strtotime("-".$i." ".$period, $end_date_timestamp))); echo "<br/>"; echo Html::convDate(date('m-d', strtotime("-".($i-1)." ".$period, $end_date_timestamp))); echo '</th>'; } echo '</tr>'; $query = "SELECT `glpi_plugin_monitoring_componentscatalogs_hosts`.*, `glpi_plugin_monitoring_services`.`id` as sid FROM `glpi_plugin_monitoring_componentscatalogs_hosts` LEFT JOIN `glpi_plugin_monitoring_services` ON `glpi_plugin_monitoring_componentscatalogs_hosts`.`id`=`plugin_monitoring_componentscatalogs_hosts_id` WHERE `plugin_monitoring_componentscalalog_id`='".$componentscatalogs_id."' AND `plugin_monitoring_components_id`='".$components_id."'"; $result = $DB->query($query); $rownb = true; while ($data=$DB->fetch_array($result)) { $itemtype = $data['itemtype']; $item = new $itemtype(); $item->getFromDB($data['items_id']); if ($groupname == 'avaibility') { $a_times = $pmUnavailability->parseEvents($data['id'], '', date('Y-m-d', strtotime("-".($number + 1)." ".$period, $end_date_timestamp)), date('Y-m-d', strtotime("-".$number." ".$period, $end_date_timestamp))); $previous_value = round(((($a_times[1] - $a_times[0]) / $a_times[1]) * 100), 3); } else { $previous_value = 0; } echo '<tr class="tab_bg'.(($rownb = !$rownb)?'_4':'_1').'">'; echo '<td>'; echo $item->getLink(); echo '</td>'; echo '<td>'; echo Dropdown::getDropdownName("glpi_entities", $item->fields['entities_id']); echo '</td>'; echo '<td>'; echo $item->getTypeName(); echo '</td>'; for ($i = $number; $i >= 1;$i--) { $startdatet = date('Y-m-d', strtotime("-".$i." ".$period, $end_date_timestamp)); $enddatet = date('Y-m-d', strtotime("-".($i-1)." ".$period, $end_date_timestamp)); if ($groupname == 'avaibility') { $a_times = $pmUnavailability->parseEvents($data['id'], '', $startdatet, $enddatet); $value = round(((($a_times[1] - $a_times[0]) / $a_times[1]) * 100), 2); } else { $queryevents = "SELECT * FROM `glpi_plugin_monitoring_serviceevents` WHERE `plugin_monitoring_services_id`='".$data['sid']."' AND `date` >= '".$startdatet."' AND `date` <= '".$enddatet."' ORDER BY `date`"; $resultevents = $DB->query($queryevents); $_SESSION['plugin_monitoring_checkinterval'] = PluginMonitoringComponent::getTimeBetween2Checks($pmComponent->fields['id']); $ret = $pmServiceevent->getData($resultevents, $pmComponent->fields['graph_template'], $startdatet, $enddatet); if (!isset($ret[0][$groupname])) { $value = 0; } else { $value = round(array_sum($ret[0][$groupname]) / count($ret[0][$groupname]), 2); } } $bgcolor = ''; if ($array['perfname_val'][$components_id][$num] == 1) { if ($previous_value < $value) { $bgcolor = 'style="background-color:#d1ffc3"'; } else if ($previous_value > $value) { $bgcolor = 'style="background-color:#ffd1d3"'; } } else { if ($previous_value < $value) { $bgcolor = 'style="background-color:#ffd1d3"'; } else if ($previous_value > $value) { $bgcolor = 'style="background-color:#d1ffc3"'; } } echo '<td '.$bgcolor.'>'; if ($groupname == 'avaibility') { echo $value."%"; } else { if ($value > 3000000000) { echo round($value/1000000000, 2).'T'; } else if ($value > 3000000) { echo round($value/1000000, 2).'M'; } else if ($value > 3000) { echo round($value/1000, 2).'K'; } else { echo $value; } } echo '</td>'; echo '<td '.$bgcolor.'>'; if ($array['perfname_val'][$components_id][$num] == 1) { if ($previous_value < $value) { echo '<img src="../pics/arrow-up-right.png" width="16" />'; } else if ($previous_value == $value) { echo '<img src="../pics/arrow-right.png" width="16" />'; } else if ($previous_value > $value) { echo '<img src="../pics/arrow-down-right.png" width="16" />'; } } else { if ($previous_value < $value) { echo '<img src="../pics/arrow-up-right_inv.png" width="16" />'; } else if ($previous_value == $value) { echo '<img src="../pics/arrow-right.png" width="16" />'; } else if ($previous_value > $value) { echo '<img src="../pics/arrow-down-right_inv.png" width="16" />'; } } $previous_value = $value; echo '</td>'; } echo "</tr>"; } } echo '<tr class="tab_bg_1" height="50">'; echo '<td colspan="'.(3 + ($number * 2)).'">'; echo '</td>'; echo '</tr>'; } echo "</table>"; if ($pdf) { $content = PluginMonitoringReport::endCapture(); PluginMonitoringReport::generatePDF($content, 'L'); } }
@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 2013 ------------------------------------------------------------------------ */ include "../../../inc/includes.php"; Session::checkCentralAccess(); Html::header(__('Monitoring - unavailabilities', 'monitoring'), $_SERVER["PHP_SELF"], "plugins", "monitoring", "unavailability"); // if (isset($_GET['contains'])) { // $pmUnavailability = new PluginMonitoringUnavailability(); // $pmUnavailability->showList($_GET); // } if (isset($_GET['component_catalog_id'])) { $pmUnavailability = new PluginMonitoringUnavailability(); $pmUnavailability->displayComponentscatalog($_GET['component_catalog_id']); } // forceUpdate request parameter is to force an update ... if (isset($_GET['forceUpdate'])) { // A services_id may be specified as a parameter ... // Default services_id is 0 for all services // start and limit may also be specified, defaults are 0 / 100 PluginMonitoringUnavailability::runUnavailability(isset($_GET['services_id']) ? $_GET['services_id'] : 0, isset($_GET['start']) ? $_GET['start'] : 0, isset($_GET['limit']) ? $_GET['limit'] : 100); } Search::show('PluginMonitoringUnavailability'); Html::footer();
Plugin Monitoring for GLPI is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Plugin Monitoring for GLPI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with Monitoring. If not, see <http://www.gnu.org/licenses/>. ------------------------------------------------------------------------ @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 2014 ------------------------------------------------------------------------ */ include "../../../inc/includes.php"; $pmUnavailability = new PluginMonitoringUnavailability(); $pmUnavailability->runUnavailability(0, 0, 10000000000);