/**
  * @covers WeatherMap::processString
  */
 public function testProcessString()
 {
     global $weathermap_debugging;
     $this->assertEquals("", $this->object->processString("", $this->object, true, false));
     $this->assertEquals("dog", $this->object->processString("dog", $this->object, true, false));
     $this->assertEquals("[UNKNOWN]", $this->object->processString("{map:randomstring}", $this->object, true, false));
     $this->assertEquals("[UNKNOWN]", $this->object->processString("{node:randomstring}", $this->object, true, false));
     $this->assertEquals("[UNKNOWN]", $this->object->processString("{link:randomstring}", $this->object, true, false));
     // load a config file, so there are map objects to talk about
     $this->object->ReadConfig(dirname(__FILE__) . '/../../test-suite/tests/simple-link-1.conf');
     // initialise the data, otherwise we'll get "" instead of 0 for bandwidth, etc
     $this->object->readData();
     $n1 = $this->object->nodes['n1'];
     $l1 = $this->object->links['l1'];
     $this->assertInstanceOf("WeatherMapNode", $n1);
     $this->assertInstanceOf("WeatherMapLink", $l1);
     // $weathermap_debugging = TRUE;
     $n1->add_note("note1", "Data from another plugin");
     $n1->add_hint("note2", "User input");
     // testing notes-inclusion/exclusion
     $this->assertEquals("[UNKNOWN]", $this->object->processString("{node:this:note1}", $n1, false, false));
     $this->assertEquals("Data from another plugin", $this->object->processString("{node:this:note1}", $n1, true, false));
     // vs hints, which always work
     $this->assertEquals("User input", $this->object->processString("{node:this:note2}", $n1, false, false));
     $this->assertEquals("User input", $this->object->processString("{node:this:note2}", $n1, true, false));
     $this->assertEquals("Some Simple Links and Nodes", $this->object->processString("{map:title}", $n1, true, false));
     $this->assertEquals("Some Simple Links and Nodes", $this->object->processString("{map:title}", $this->object, true, false));
     $this->assertEquals("Some Simple Links and Nodes", $this->object->processString("{map:title}", $l1, true, false));
     // hints "overwrite" internal variables
     $this->object->add_hint("title", "fish");
     $this->assertEquals("fish", $this->object->processString("{map:title}", $n1, true, false));
     // and notes might "overwrite" internal variables depending on where we are (not in TARGETs for example)
     $this->object->delete_hint("title");
     $this->object->add_note("title", "cat");
     $this->assertEquals("cat", $this->object->processString("{map:title}", $n1, true, false));
     $this->assertEquals("Some Simple Links and Nodes", $this->object->processString("{map:title}", $n1, false, false));
     $this->assertEquals("n1", $this->object->processString("{node:this:name}", $n1, true, false));
     $this->assertEquals("l1", $this->object->processString("{link:this:name}", $l1, true, false));
     $this->assertEquals("0", $this->object->processString("{node:this:bandwidth_in}", $n1, true, false));
     $this->assertEquals("0", $this->object->processString("{link:this:bandwidth_in}", $l1, true, false));
     $this->assertEquals("0", $this->object->processString("{node:n1:bandwidth_in}", $this->object, true, false));
     $this->assertEquals("0", $this->object->processString("{link:l1:bandwidth_in}", $this->object, true, false));
 }
 /**
  * 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
  *
  * From: https://jtreminio.com/2013/03/unit-testing-tutorial-part-3-testing-protected-private-methods-coverage-reports-and-crap/
  *
  * @param string $conffile
  * @param string $imagefile
  * @param string $htmlfile
  * @param string $newconffile
  * @param string $coveragefile
  */
 public static function TestOutput_RunTest($conffile, $imagefile, $htmlfile, $newconffile)
 {
     global $WEATHERMAP_VERSION;
     $map = new WeatherMap();
     $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 exempt 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 != "") {
             // doesn'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->drawMapImage($imagefile);
         $map->imagefile = $imagefile;
         if ($htmlfile != '') {
             OutputHTML($htmlfile, $map);
         }
         if ($newconffile != '') {
             $map->writeConfig($newconffile);
         }
         $nwarns = $map->warncount;
     }
     $map->cleanUp();
     unset($map);
     return intval($nwarns);
 }
Example #3
0
		break;

	case "set_node_config":
		$map->ReadConfig($mapfile);

		$node_name = $_REQUEST['node_name'];
		$node_config = fix_gpc_string($_REQUEST['item_configtext']);
		
		if(isset($map->nodes[$node_name])) {		                
		    $map->nodes[$node_name]->config_override = $node_config;
		    
		    $map->WriteConfig($mapfile);
		    // now clear and reload the map object, because the in-memory one is out of sync
		    // - we don't know what changes the user made here, so we just have to reload.
		    unset($map);
		    $map = new WeatherMap;
		    $map->context = 'editor';
		    $map->ReadConfig($mapfile);
		}
		break;

	case "set_node_properties":
		$map->ReadConfig($mapfile);

		$node_name = $_REQUEST['node_name'];
		$new_node_name = $_REQUEST['node_new_name'];

		// first check if there's a rename...
		if($node_name != $new_node_name && strpos($new_node_name," ") === false)
		{
		    if(!isset($map->nodes[$new_node_name]))
Example #4
0
$rows = intval($map->height / $desired_height) + 1;
$cols = intval($map->width / $desired_width) + 1;
$num = $rows * $cols;
if ($num == 1) {
    print "This map is already within your constraints.\n";
} else {
    print "We'll need to make {$num} ({$cols} x {$rows}) smaller maps\n";
    for ($row = 0; $row < $rows; $row++) {
        for ($col = 0; $col < $cols; $col++) {
            print "=====================================\nMaking the submap {$col},{$row}\n";
            $min_x = $col * $desired_width;
            $min_y = $row * $desired_height;
            $max_x = ($col + 1) * $desired_width;
            $max_y = ($row + 1) * $desired_height;
            print "We'll read the map, and throw out everything not inside ({$min_x},{$min_y})->({$max_x},{$max_y})\n";
            $map = new WeatherMap();
            $map->ReadConfig($input_mapfile);
            foreach ($map->nodes as $node) {
                $target = $node->name;
                if ($node->x < $min_x || $node->x >= $max_x || $node->y < $min_y || $node->y >= $max_y) {
                    print "{$target} falls outside of this map. Deleting it and links that use it.\n";
                    foreach ($map->links as $link) {
                        if ($target == $link->a->name || $target == $link->b->name) {
                            print "link {$link->name} uses it. Deleted.\n";
                            unset($map->links[$link->name]);
                        }
                    }
                    unset($map->nodes[$target]);
                } else {
                    print "{$target} is OK, but will be moved for the new map from " . $node->x . "," . $node->y . " to ";
                    $x = $node->x;
                break;
            case '--input':
                $inputfile = $o[1];
                break;
            case '--output':
                $outputfile = $o[1];
                break;
            case 'help':
            default:
                print "Weathermap DSStats converter. Converts rrd targets to DSStats\n";
                print "-------------------------------------------------------------\n";
                print "Usage: php convert-to-dstats.php [options]\n\n";
                print " --input {filename}         - File to read from\n";
                print " --output {filename}        - File to write to\n";
                print " --debug                    - Enable debugging output\n";
                print " --help                    - Show this message\n";
                exit;
        }
    }
}
if ($inputfile == "" || $outputfile == "") {
    print "You must specify an input and output file. See --help.\n";
    exit;
}
$map = new WeatherMap();
$map->context = 'cacti';
$map->rrdtool = read_config_option("path_rrdtool");
print "Reading config from {$inputfile}\n";
$map->ReadConfig($inputfile);
$map->writeConfig($outputfile);
print "Wrote new config to {$outputfile}\n";
                break;
            case 'help':
            default:
                print "Weathermap DSStats converter. Converts rrd targets to DSStats\n";
                print "-------------------------------------------------------------\n";
                print "Usage: php convert-to-dstats.php [options]\n\n";
                print " --input {filename}         - File to read from\n";
                print " --output {filename}        - File to write to\n";
                print " --debug                    - Enable debugging output\n";
                print " --help                    - Show this message\n";
                exit;
        }
    }
}
if ($inputfile === '' || $outputfile === '') {
    print "You must specify an input and output file. See --help.\n";
    exit;
}
$map = new WeatherMap();
$map->context = 'cacti';
$map->rrdtool = read_config_option('path_rrdtool');
print 'Reading config from ' . $inputfile . "\n";
$map->ReadConfig($inputfile);
// 'Draw' the map, so that we get dimensions for all the nodes
// and offsets for links are calculated.
$map->drawMapImage(null);
// loop through all links
// adjust node offsets so that links come from correct side of nodes, and ideally still
// from underneath them (e.g. NE80 not NE)
$map->writeConfig($outputfile);
print 'Wrote new config to ' . $outputfile . "\n";
Example #7
0
 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);
     }
 }
                print $colors["panel"];
                ?>
"><td><table width="100%" cellpadding="0" cellspacing="0"><tr><td class="textHeader" nowrap><?php 
                print $maptitle;
                ?>
</td></tr></table></td></tr>
<?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);
 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);
     }
 }
Example #10
0
					print " --output {filename}        - File to write to\n";
				#	print " --reverse                  - Convert from DSStats to RRDtool instead\n";
					print " --debug                    - Enable debugging output\n";
					print " --help                    - Show this message\n";
					exit();
			}
		}
	}

	if($inputfile == "" || $outputfile == "")
	{
		print "You must specify an input and output file. See --help.\n";
		exit();
	}
	
	$map = new WeatherMap;
	
	$map->context = 'cacti';
	$map->rrdtool  = read_config_option("path_rrdtool");
	
	print "Reading config from $inputfile\n";
	
	$map->ReadConfig($inputfile);

	$map->DatasourceInit();
	$map->ProcessTargets();
	
	$allitems = array(&$map->links, &$map->nodes);
	reset($allitems);
	
	while( list($kk,) = each($allitems))
/**
 * Produce the HTML output for both the unit-tests and the CLI utility
 *
 * @global string $WEATHERMAP_VERSION
 * @param string $htmlfile
 * @param WeatherMap $map
 */
function OutputHTML($htmlfile, &$map, $refresh = 300)
{
    global $WEATHERMAP_VERSION;
    $filehandle = fopen($htmlfile, 'w');
    fwrite($filehandle, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>');
    if ($map->htmlstylesheet != '') {
        fwrite($filehandle, '<link rel="stylesheet" type="text/css" href="' . $map->htmlstylesheet . '" />');
    }
    fwrite($filehandle, '<meta http-equiv="refresh" content="' . intval($refresh) . '" /><title>' . $map->processString($map->title, $map) . '</title></head><body>');
    if ($map->htmlstyle == "overlib") {
        fwrite($filehandle, "<div id=\"overDiv\" style=\"position:absolute; visibility:hidden; z-index:1000;\"></div>\n");
        fwrite($filehandle, "<script type=\"text/javascript\" src=\"vendor/overlib.js\"><!-- overLIB (c) Erik Bosrup --></script> \n");
    }
    fwrite($filehandle, $map->makeHTML());
    fwrite($filehandle, '<hr /><span id="byline">Network Map created with <a href="http://www.network-weathermap.com/?vs=' . $WEATHERMAP_VERSION . '">PHP Network Weathermap v' . $WEATHERMAP_VERSION . '</a></span></body></html>');
    fclose($filehandle);
}
                print "-------------------------------------------------------------\n";
                print "Usage: php convert-to-dstats.php [options]\n\n";
                print " --input {filename}         - File to read from\n";
                print " --output {filename}        - File to write to\n";
                #	print " --reverse                  - Convert from DSStats to RRDtool instead\n";
                print " --debug                    - Enable debugging output\n";
                print " --help                    - Show this message\n";
                exit;
        }
    }
}
if ($inputfile == "" || $outputfile == "") {
    print "You must specify an input and output file. See --help.\n";
    exit;
}
$map = new WeatherMap();
$map->context = 'cacti';
$map->rrdtool = read_config_option("path_rrdtool");
print "Reading config from {$inputfile}\n";
$map->ReadConfig($inputfile);
$map->initialiseAllPlugins();
$map->preProcessTargets();
$allitems = array(&$map->links, &$map->nodes);
reset($allitems);
while (list($kk, ) = each($allitems)) {
    unset($objects);
    $objects =& $allitems[$kk];
    reset($objects);
    while (list($k, ) = each($objects)) {
        unset($myobj);
        $myobj =& $objects[$k];