Munin

Nun habe ich Munin „entdeckt“, und möchte es allen mitteilen! Munin ist eine sehr gute Komplementation zu IPS, wenn man ein LAN überwachen will - und sie ist gratis. Sie läuft auf allerlei Linux-Platformen, was ich damit gelöst habe, dass ich ArchLinux auf eine Virtual Machine im IPS-Server installiert habe. Mehr steht bei http://munin-monitoring.org/

ping1aag_lan101_120-day.png

Cool. Dann kann ich das ja bei PRTG rauswerfen und habe dort wieder Sensoren frei :slight_smile:
Hast du es auch schon in IPS eingebunden (Visu Webfront) ?
Michael

Munin produziert ein Haufen PNG-Dateien und aktualisiert sie alle 5 Minuten. Die Graphen sind defaultmässig in /data/munin gespeichert, man kann sie aber auch anderswo speichern lassen, z.B. im Webfront-Root, oder (vielleicht besser) entsprechende Symlinks setzen.

ausgehend von diesem schönen RPC-JSON-Wrapper habe ich einen Script konfektioniert, der jede beliebige Variable in Munin plottet. Es lassen sich WARNING und CRITICAL-Werte einstellen, welche bei Ueber/Unterschreitung ein Alarm auslösen.


#!/usr/bin/env php  
<?php  

/* 
* Munin check plugin for IP-Symcon 
* (www.ipsymcon.de)
* retrieves value of a given variable via id using json api (need IPS V3.1+)
* (C) Thomas Dressler 2013-2014 www.tdressler.net/ipsymcon
*  Version 2.0 2014-02-14
* modified by AAG (aag@bellariastrasse.com)
*/
//get all the environmental variables specified in directory plugin-conf.d
	//$host = getenv('H');
	//$port = getenv('P');
	$id = $ips_variable = getenv('i');
	//$user = getenv('ips_user');
	//$password =getenv('pw');
	$graph_title = getenv('graph_title'); // 
	$graph_vlabel =getenv('graph_vlabel'); // 
	$var_label = getenv('var.label');
	$var_value = getenv('var_value');
	$graph_args= getenv('graph_args');
	$graph_scale = getenv('graph_scale');
	$graph_category = getenv('graph_category');
	$var_warning = getenv('var.warning');
	$var_critical = getenv('var.critical');
	$graph_info = getenv('graph_info');


//JSON API
require ("/etc/ips_json/IPS_JSON.php");
if ( !class_exists("IPS_JSON"))
{
	print "This requires PHP JSON and IPS_JSON class
";
	exit($retcode['RC_UNKNOWN']) ;
}

//default configuration
$age=3600;
$config='/etc/munin/plugins/ips_munin.cfg';
$config_switch=false;

//read commandline options
$options=getopt("H:P:u:p:i:c:w:a:f:h");

//print_r($options);
if (isset($options['h'])) {
	usage();
	exit($retcode['RC_UNKNOWN']);
}
if (isset($options['f'])) {$config=$options['f'];}

//overwrite default configuration as above with your settings if needed 
if (file_exists($config))  {
	$config_data=file_get_contents($config);
	//echo "config_data ".$config_data;
	$res=eval($config_data);
	if ($res===false) {
		echo "UNKNOWN eval of $config failed. Hint:Use code only, no leading php tags
";
		exit($retcode['RC_UNKNOWN']);
	}
}

//commandline parameters have precedence

if (isset($options['P'])) $port=$options['P'];
if (isset($options['H'])) {$host=$options['H'];}
if (isset($options['u'])) {$user=$options['u'];}
if (isset($options['p'])) {$password=$options['p'];}
if (isset($options['i'])) {$id=$options['i'];}
if (isset($options['a'])) {$age=$options['a'];}
if (isset($options['c'])) {$critical=$options['c'];}
if (isset($options['w'])) {$warning=$options['w'];}
//echo "arg count: ".$argc."
";
if ($argc >1){
	if ($argv[1] == "config") {$config_switch=True;} // if the plugin is run with command-line option "config" 
	}


// if (empty($host) || empty($id)) {
	// echo "UNKNOWN Host or ID missed
";
	// usage();
	// exit($retcode['RC_UNKNOWN']);
// }
// if (empty($user) || empty($password)) {
	// echo "UNKNOWN API username or Password
";
	// usage();
	// exit($retcode['RC_UNKNOWN']);
// }

$url="http://".$host.":".$port."/api/";

$id=(integer)$id;
$age=(integer)$age;

//start query IPS
try {
	//new object
	$rpc = new IPS_JSON($url,$user,$password);
	//check if IPS is available
	$version=$rpc->IPS_GetKernelVersion();
	if (!$version) {
		echo "UNKNOWN IPS Request failed:".$rpc->getErrorMessage()."
";
		exit ($retcode['RC_UNKNOWN']);
	}
	//retrieve variable data
	$var=$rpc->get_var($id);	//print_r($var);
	if (!$var) {
		echo "UNKNOWN ".$rpc->getErrorMessage()."
";
		exit ($retcode['RC_UNKNOWN']);
	}

}catch (Exception $e) {
	echo "UNKNOWN IPS Call failed->".$e->getMessage()."
";
	exit ($retcode['RC_UNKNOWN']);
}


//assign result
$name=strtolower ($var["name"]);
$value=$var["value"];
$digits=$var["digits"];
$last=$var["last"];
$type=$var["type"];
$suffix=$var["suffix"];

//last updated/age check
if (is_null($last)) {
		echo "WARNING - $name:$value, but has no timestamp
";
		exit($retcode['RC_WARNING']);
	}
$diff=time()-$last;
if ($diff>$age) {
		echo "WARNING - $name:$value, but to old (actual ".$diff."s > max ". $age."s)
";
		exit ($retcode['RC_WARNING']);
}

//formatting digits from profile
if (is_integer($digits)) {
	$value=sprintf("%0.".$digits."f",$value);
}

//generate output
$perf='';
$res="$name:".$value.$suffix.", Age=".$diff."s";
#only integer and float values are qualified as performance data
if ($type == 1 ||$type==2) {
//'label'=value[UOM];[warn];[crit];[min];[max]
	$perf=" |$name=$value;;;;";
}


if ($config_switch==true)
	{

	$var_info = $name.getenv('info');

	echo "graph_title " . $graph_title . "
";
	echo "graph_vlabel " . $graph_vlabel. "
";
	//echo $name.".value " . $var_value. "
";
	echo $name.".label ".$var_label. "
";
	echo "graph_args ". $graph_args. "
";
	echo "graph_scale ".$graph_scale. "
";
	echo "graph_category " .$graph_category. "
";
	echo $name . ".warning ".$var_warning. "
";
	echo $name.".critical " . $var_critical. "
";
	echo "graph_info ". $graph_info. "
";
	echo $name.".info " . $var_info. "
";


	}

else {
	$res = "$name".".value ".$value;
	$age = $diff;
	//exit
	echo $res."
";
	exit ;
	}

?>


Die Konfiguration des Plugins sieht z.B. wie folgt aus:


[ips_var_53428]
	env.i 53428
	env.graph_title Temperature Roof
	env.graph_vlabel Celsius
	env.var_value temperature
	env.var.label temperature (Celsius)
	env.graph_args --base 1000 --upper-limit 40 --lower-limit -10 
	env.graph_scale no
	env.graph_category IPS
	env.graph_info Temperature measured in projector niche
	env.var.info Average temperature for the past five minutes
	env.var.critical 15:42