{ if(substr($selected,0,5) == 'NODE:') { $nodename = substr($selected,5); $map->nodes[$nodename]->selected=1; } if(substr($selected,0,5) == 'LINK:') { $linkname = substr($selected,5); $map->links[$linkname]->selected=1; } } $map->sizedebug = TRUE; $map->DrawMap('','',250,TRUE,$use_overlay,$use_relative_overlay); exit(); break; case 'show_config': header('Content-type: text/plain'); $fd = fopen($mapfile,'r'); while (!feof($fd)) { $buffer = fgets($fd, 4096); echo $buffer; } fclose($fd); exit();
/** * Run a config-based test. * Read in config from $conffile, and produce an image and HTML output * Optionally Produce a new config file in $newconffile (for testing WriteConfig) * Optionally collect config-keyword-coverage stats about this config file * * * * @param string $conffile * @param string $imagefile * @param string $htmlfile * @param string $newconffile * @param string $coveragefile */ function TestOutput_RunTest($conffile, $imagefile, $htmlfile, $newconffile, $coveragefile) { global $weathermap_map; global $WEATHERMAP_VERSION; $map = new WeatherMap(); if ($coveragefile != '') { $map->SeedCoverage(); if (file_exists($coveragefile)) { $map->LoadCoverage($coveragefile); } } $weathermap_map = $conffile; $map->ReadConfig($conffile); $skip = 0; $nwarns = 0; if (!strstr($WEATHERMAP_VERSION, "dev")) { # Allow tests to be from the future. Global SET in test file can excempt test from running # SET REQUIRES_VERSION 0.98 # but don't check if the current version is a dev version $required_version = $map->get_hint("REQUIRES_VERSION"); if ($required_version != "") { // doesan't need to be complete, just in the right order $known_versions = array("0.97", "0.97a", "0.97b", "0.98"); $my_version = array_search($WEATHERMAP_VERSION, $known_versions); $req_version = array_search($required_version, $known_versions); if ($req_version > $my_version) { $skip = 1; $nwarns = -1; } } } if ($skip == 0) { $map->ReadData(); $map->DrawMap($imagefile); $map->imagefile = $imagefile; if ($htmlfile != '') { TestOutput_HTML($htmlfile, $map); } if ($newconffile != '') { $map->WriteConfig($newconffile); } if ($coveragefile != '') { $map->SaveCoverage($coveragefile); } $nwarns = $map->warncount; } $map->CleanUp(); unset($map); return intval($nwarns); }
<?php print "<tr><td>"; # print "Generating map $id here now from ".$map[0]['configfile']; $confdir = dirname(__FILE__) . '/configs/'; // everything else in this file is inside this else $mapname = $map[0]['configfile']; $mapfile = $confdir . '/' . $mapname; $orig_cwd = getcwd(); chdir(dirname(__FILE__)); $map = new WeatherMap(); // $map->context = "cacti"; $map->rrdtool = read_config_option("path_rrdtool"); print "<pre>"; $map->ReadConfig($mapfile); $map->ReadData(); $map->DrawMap('null'); $map->PreloadMapHTML(); print "</pre>"; print ""; print "<img src='?action=liveviewimage&id={$id}' />\n"; print $map->imap->subHTML("LEGEND:"); print $map->imap->subHTML("TIMESTAMP"); print $map->imap->subHTML("NODE:"); print $map->imap->subHTML("LINK:"); chdir($orig_cwd); print "</td></tr>"; html_graph_end_box(); } else { print "Map unavailable."; } } else {
function generateWeathermap($weathermaps_id, $force = 0, $makehtml = 0) { if ($force == '0' and file_exists(GLPI_PLUGIN_DOC_DIR . "/monitoring/weathermap-" . $weathermaps_id . ".png")) { $time_generate = filectime(GLPI_PLUGIN_DOC_DIR . "/monitoring/weathermap-" . $weathermaps_id . ".png"); if ($time_generate + 150 > date('U')) { return; } } require_once GLPI_ROOT . "/plugins/monitoring/lib/weathermap/WeatherMap.functions.php"; require_once GLPI_ROOT . "/plugins/monitoring/lib/weathermap/HTML_ImageMap.class.php"; require_once GLPI_ROOT . "/plugins/monitoring/lib/weathermap/Weathermap.class.php"; require_once GLPI_ROOT . "/plugins/monitoring/lib/weathermap/WeatherMapNode.class.php"; require_once GLPI_ROOT . "/plugins/monitoring/lib/weathermap/WeatherMapLink.class.php"; $map = new WeatherMap(); if ($map->ReadConfig($this->generateConfig($weathermaps_id))) { $imagefile = GLPI_PLUGIN_DOC_DIR . "/monitoring/weathermap-" . $weathermaps_id . ".png"; $map->ReadData(); if ($imagefile != '') { $map->DrawMap($imagefile); $map->imagefile = $imagefile; } } else { echo "Problem to generate weathermap"; } if ($makehtml == '1') { $map->htmlstyle = ''; $fd = fopen(GLPI_PLUGIN_DOC_DIR . "/monitoring/weathermap-" . $weathermaps_id . ".html", 'w'); $html = $map->MakeHTML(); $lines = explode("\n", $html); $objects_id = array(); $services_id = array(); foreach ($lines as $line) { $match = array(); preg_match_all("/\\<area id=\"([\\w\\d:]*)\" href=\"(?:.*)items_id=(\\d+)\" /", $line, $match); if (isset($match[1][0])) { $objects_id[$match[1][0]] = $match[1][0]; $services_id[$match[1][0]] = $match[2][0]; } } $pmService = new PluginMonitoringService(); $pmComponent = new PluginMonitoringComponent(); $pmServicegraph = new PluginMonitoringServicegraph(); $i = 0; foreach ($objects_id as $o_id) { $pmService->getFromDB($services_id[$o_id]); $pmComponent->getFromDB($pmService->fields['plugin_monitoring_components_id']); ob_start(); $pmServicegraph->displayGraph($pmComponent->fields['graph_template'], "PluginMonitoringService", $services_id[$o_id], "0", '2h', "div", "400"); $chart = ''; $chart = ob_get_contents(); ob_end_clean(); $chart = str_replace('<div id="chart' . $services_id[$o_id] . '2h">', '<div id="chart' . $services_id[$o_id] . '2h' . $i . '">', $chart); $chart = str_replace('<div id="updategraph' . $services_id[$o_id] . '2h">', '<div id="updategraph' . $services_id[$o_id] . '2h' . $i . '">', $chart); $chart = "<table width='400' class='tab_cadre'><tr><td>" . $chart . "</td></tr></table>"; $html .= "\n" . $this->showToolTip($chart, array('applyto' => $o_id, 'display' => false)); ob_start(); $pmServicegraph->displayGraph($pmComponent->fields['graph_template'], "PluginMonitoringService", $services_id[$o_id], "0", '2h', "js"); $chart = ''; $chart = ob_get_contents(); ob_end_clean(); $chart = str_replace('"updategraph' . $services_id[$o_id] . '2h"', '"updategraph' . $services_id[$o_id] . '2h' . $i . '"', $chart); $chart = str_replace('&time=2h&', '&time=2h&suffix=' . $i . '&', $chart); $html .= "\n" . $chart; $i++; } fwrite($fd, $html); fwrite($fd, '<hr /><span id="byline">Network Map created with <a href="http://www.network-weathermap.com/?vs= 0.97a">PHP Network Weathermap v0.97a</a></span></body></html>'); fclose($fd); } }
function generateWeathermap($weathermaps_id, $force = 0, $makehtml = 0) { global $CFG_GLPI; if ($force == '0' and file_exists(GLPI_PLUGIN_DOC_DIR . "/monitoring/weathermap-" . $weathermaps_id . ".png")) { $time_generate = filectime(GLPI_PLUGIN_DOC_DIR . "/monitoring/weathermap-" . $weathermaps_id . ".png"); if ($time_generate + 150 > date('U')) { return; } } require_once GLPI_ROOT . "/plugins/monitoring/lib/weathermap/WeatherMap.functions.php"; require_once GLPI_ROOT . "/plugins/monitoring/lib/weathermap/HTML_ImageMap.class.php"; require_once GLPI_ROOT . "/plugins/monitoring/lib/weathermap/Weathermap.class.php"; require_once GLPI_ROOT . "/plugins/monitoring/lib/weathermap/WeatherMapNode.class.php"; require_once GLPI_ROOT . "/plugins/monitoring/lib/weathermap/WeatherMapLink.class.php"; $map = new WeatherMap(); //$map->context="cli"; //echo $this->generateConfig($weathermaps_id);exit; if ($map->ReadConfig($this->generateConfig($weathermaps_id))) { $imagefile = GLPI_PLUGIN_DOC_DIR . "/monitoring/weathermap-" . $weathermaps_id . ".png"; $map->ReadData(); if ($imagefile != '') { $map->DrawMap($imagefile); $map->imagefile = $imagefile; } } else { echo "Problem to generate weathermap"; } if ($makehtml == '1') { $map->htmlstyle = ''; $fd = fopen(GLPI_PLUGIN_DOC_DIR . "/monitoring/weathermap-" . $weathermaps_id . ".html", 'w'); $html = $map->MakeHTML(); $lines = explode("\n", $html); $objects_id = array(); $services_id = array(); foreach ($lines as $line) { $match = array(); preg_match_all("/\\<area id=\"([\\w\\d:]*)\" href=\"(?:.*)items_id=(\\d+)\" /", $line, $match); if (isset($match[1][0])) { $objects_id[$match[1][0]] = $match[1][0]; $services_id[$match[1][0]] = $match[2][0]; } } foreach ($objects_id as $o_id) { $html .= "\n" . $this->showToolTip("<img src='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/send.php?file=PluginMonitoringService-" . $services_id[$o_id] . "-2h0.png' width='500' height='164' />", array('applyto' => $o_id, 'display' => false)); } fwrite($fd, $html); fwrite($fd, '<hr /><span id="byline">Network Map created with <a href="http://www.network-weathermap.com/?vs= 0.97a">PHP Network Weathermap v0.97a</a></span></body></html>'); fclose($fd); } }