mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-26 08:03:51 +02:00
a million fixes. half way to 0.6.0! :D
git-svn-id: http://www.observium.org/svn/observer/trunk@407 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
+17
-12
@@ -16,6 +16,11 @@ include_once($config['install_dir'] . "/includes/cisco-entities.php");
|
||||
include_once($config['install_dir'] . "/includes/syslog.php");
|
||||
include_once($config['install_dir'] . "/includes/rewrites.php");
|
||||
|
||||
function only_alphanumeric( $string )
|
||||
{
|
||||
return preg_replace('/[^a-zA-Z0-9]/', '', $string);
|
||||
}
|
||||
|
||||
|
||||
function mres($string) { // short function wrapper because the real one is stupidly long and ugly. aestetics.
|
||||
return mysql_real_escape_string($string);
|
||||
@@ -142,9 +147,9 @@ function formatRates($rate)
|
||||
return $rate;
|
||||
}
|
||||
|
||||
function formatstorage($rate)
|
||||
function formatstorage($rate, $round = '2')
|
||||
{
|
||||
$rate = format_bi($rate) . "B";
|
||||
$rate = format_bi($rate, $round) . "B";
|
||||
return $rate;
|
||||
}
|
||||
|
||||
@@ -157,12 +162,12 @@ function format_si($rate)
|
||||
return round($rate, $round[$i]).$ext;
|
||||
}
|
||||
|
||||
function format_bi($size)
|
||||
function format_bi($size, $round = '2')
|
||||
{
|
||||
$sizes = Array('', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei');
|
||||
$sizes = Array('', 'K', 'M', 'G', 'T', 'P', 'E');
|
||||
$ext = $sizes[0];
|
||||
for ($i=1; (($i < count($sizes)) && ($size >= 1024)); $i++) { $size = $size / 1024; $ext = $sizes[$i]; }
|
||||
return round($size, 2).$ext;
|
||||
return round($size, $round).$ext;
|
||||
}
|
||||
|
||||
function arguments($argv)
|
||||
@@ -203,11 +208,11 @@ function truncate($substring, $max = 50, $rep = '...')
|
||||
if(strlen($string) > $max){ return substr_replace($string, $rep, $leave); } else { return $string; }
|
||||
}
|
||||
|
||||
function interface_rates ($interface) // Returns the last in/out value in RRD
|
||||
function interface_rates ($rrd_file) // Returns the last in/out value in RRD
|
||||
{
|
||||
global $config;
|
||||
$rrdfile = $config['rrd_dir'] . "/" . $interface['hostname'] . "/" . $interface['ifIndex'] . ".rrd";
|
||||
$cmd = $config['rrdtool']." fetch -s -600s -e now ".$rrdfile." AVERAGE | grep : | cut -d\" \" -f 2,3 | grep e";
|
||||
#$rrdfile = $config['rrd_dir'] . "/" . $interface['hostname'] . "/" . $interface['ifIndex'] . ".rrd";
|
||||
$cmd = $config['rrdtool']." fetch -s -600s -e now $rrd_file AVERAGE | grep : | cut -d\" \" -f 2,3 | grep e";
|
||||
$data = trim(`$cmd`);
|
||||
foreach( explode("\n", $data) as $entry) {
|
||||
list($in, $out) = split(" ", $entry);
|
||||
@@ -217,12 +222,12 @@ function interface_rates ($interface) // Returns the last in/out value in RRD
|
||||
return $rate;
|
||||
}
|
||||
|
||||
function interface_errors ($interface) // Returns the last in/out errors value in RRD
|
||||
function interface_errors ($rrd_file) // Returns the last in/out errors value in RRD
|
||||
{
|
||||
global $config;
|
||||
$rrdfile = $config['rrd_dir'] . "/" . $interface['hostname'] . "/" . $interface['ifIndex'] . ".rrd";
|
||||
$cmd = $config['rrdtool']." fetch -s -1d -e -300s $rrdfile AVERAGE | grep : | cut -d\" \" -f 4,5";
|
||||
$data = trim(`$cmd`);
|
||||
#$rrdfile = $config['rrd_dir'] . "/" . $interface['hostname'] . "/" . $interface['ifIndex'] . ".rrd";
|
||||
$cmd = $config['rrdtool']." fetch -s -1d -e -300s $rrd_file AVERAGE | grep : | cut -d\" \" -f 4,5";
|
||||
$data = trim(shell_exec($cmd));
|
||||
foreach( explode("\n", $data) as $entry) {
|
||||
list($in, $out) = explode(" ", $entry);
|
||||
$in_errors += ($in * 300);
|
||||
|
||||
+123
-20
@@ -4,8 +4,9 @@ include("graphing/screenos.php");
|
||||
include("graphing/fortigate.php");
|
||||
include("graphing/windows.php");
|
||||
include("graphing/unix.php");
|
||||
include("graphing/collectd.inc.php");
|
||||
|
||||
function graph_multi_bits ($interfaces, $graph, $from, $to, $width, $height, $title, $vertical, $inverse, $legend = '0') {
|
||||
function graph_multi_bits ($interfaces, $graph, $from, $to, $width, $height, $title, $vertical, $inverse, $legend = '1') {
|
||||
global $config, $installdir;
|
||||
$imgfile = $config['install_dir'] . "/graphs/" . "$graph";
|
||||
$options = "--alt-autoscale-max -E --start $from --end " . ($to - 150) . " --width $width --height $height";
|
||||
@@ -25,17 +26,19 @@ function graph_multi_bits ($interfaces, $graph, $from, $to, $width, $height, $ti
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
if($inverse) { $in = 'out'; $out = 'in'; } else { $in = 'in'; $out = 'out'; }
|
||||
|
||||
$options .= " CDEF:".$in."octets=" . $in_thing . $pluses;
|
||||
$options .= " CDEF:".$out."octets=" . $out_thing . $pluses;
|
||||
$options .= " CDEF:doutoctets=outoctets,-1,*";
|
||||
$options .= " CDEF:inbits=inoctets,8,*";
|
||||
$options .= " CDEF:outbits=outoctets,8,*";
|
||||
$options .= " CDEF:doutbits=doutoctets,8,*";
|
||||
|
||||
if($legend) {
|
||||
if($legend == "no") {
|
||||
$options .= " AREA:inbits#CDEB8B:";
|
||||
$options .= " LINE1.25:inbits#006600:";
|
||||
$options .= " AREA:doutbits#C3D9FF:";
|
||||
$options .= " LINE1.25:doutbits#000099:";
|
||||
} else {
|
||||
$options .= " AREA:inbits#CDEB8B:";
|
||||
$options .= " COMMENT:BPS\ \ \ \ Current\ \ \ Average\ \ \ \ \ \ Max\\\\n";
|
||||
$options .= " LINE1.25:inbits#006600:In\ ";
|
||||
@@ -47,11 +50,6 @@ function graph_multi_bits ($interfaces, $graph, $from, $to, $width, $height, $ti
|
||||
$options .= " GPRINT:outbits:LAST:%6.2lf%s";
|
||||
$options .= " GPRINT:outbits:AVERAGE:%6.2lf%s";
|
||||
$options .= " GPRINT:outbits:MAX:%6.2lf%s";
|
||||
} else {
|
||||
$options .= " AREA:inbits#CDEB8B:";
|
||||
$options .= " LINE1.25:inbits#006600:";
|
||||
$options .= " AREA:doutbits#C3D9FF:";
|
||||
$options .= " LINE1.25:doutbits#000099:";
|
||||
}
|
||||
if($width <= "300") { $options .= " --font LEGEND:7:".$config['mono_font']." --font AXIS:6:".$config['mono_font']." --font-render-mode normal"; }
|
||||
$thing = shell_exec($config['rrdtool'] . " graph $imgfile $options");
|
||||
@@ -94,6 +92,35 @@ function temp_graph ($temp, $graph, $from, $to, $width, $height, $title, $vertic
|
||||
return $imgfile;
|
||||
}
|
||||
|
||||
function graph_cpmCPU ($id, $graph, $from, $to, $width, $height, $title, $vertical) {
|
||||
global $config, $installdir;
|
||||
$options = "--start $from --end $to --width $width --height $height --vertical-label '$vertical' --alt-autoscale-max ";
|
||||
$options .= " -l 0 -E -b 1024 --title '$title' ";
|
||||
if($width <= "300") { $options .= " --font LEGEND:7:".$config['mono_font']." --font AXIS:6:".$config['mono_font']." --font-render-mode normal "; }
|
||||
$hostname = gethostbyid($device);
|
||||
$imgfile = $config['install_dir'] . "/graphs/" . "$graph";
|
||||
$iter = "1";
|
||||
$sql = mysql_query("SELECT * FROM `cpmCPU` AS C, `devices` AS D where C.`cpmCPU_id` = '$id' AND C.device_id = D.device_id");
|
||||
$options .= "COMMENT:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Cur\ \ \ \ Max\\\\n";
|
||||
while($proc = mysql_fetch_array($sql)) {
|
||||
if($iter=="1") {$colour="CC0000";} elseif($iter=="2") {$colour="008C00";} elseif($iter=="3") {$colour="4096EE";
|
||||
} elseif($iter=="4") {$colour="73880A";} elseif($iter=="5") {$colour="D01F3C";} elseif($iter=="6") {$colour="36393D";
|
||||
} elseif($iter=="7") {$colour="FF0084"; unset($iter); }
|
||||
$proc['descr_fixed'] = str_pad($proc['entPhysicalDescr'], 28);
|
||||
$proc['descr_fixed'] = substr($proc['descr_fixed'],0,28);
|
||||
$rrd = $config['rrd_dir'] . "/".$proc['hostname']."/cpmCPU-" . $proc['cpmCPU_oid'] . ".rrd";
|
||||
$options .= " DEF:proc" . $proc['cpmCPU_oid'] . "=$rrd:usage:AVERAGE ";
|
||||
$options .= " LINE1:proc" . $proc['cpmCPU_oid'] . "#" . $colour . ":'" . $proc['descr_fixed'] . "' ";
|
||||
$options .= " GPRINT:proc" . $proc['cpmCPU_oid'] . ":LAST:%3.0lf";
|
||||
$options .= " GPRINT:proc" . $proc['cpmCPU_oid'] . ":MAX:%3.0lf\\\l ";
|
||||
$iter++;
|
||||
}
|
||||
$thing = shell_exec($config['rrdtool'] . " graph $imgfile $options");
|
||||
return $imgfile;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function graph_device_cpmCPU ($device, $graph, $from, $to, $width, $height, $title, $vertical) {
|
||||
global $config, $installdir;
|
||||
$options = "--start $from --end $to --width $width --height $height --vertical-label '$vertical' --alt-autoscale-max ";
|
||||
@@ -121,6 +148,81 @@ function graph_device_cpmCPU ($device, $graph, $from, $to, $width, $height, $tit
|
||||
return $imgfile;
|
||||
}
|
||||
|
||||
function graph_device_cempMemPool ($device, $graph, $from, $to, $width, $height, $title, $vertical) {
|
||||
global $config, $installdir;
|
||||
$options = "--start $from --end $to --width $width --height $height --vertical-label '$vertical' --alt-autoscale-max ";
|
||||
$options .= " -l 0 -E -b 1024 --title '$title' ";
|
||||
if($width <= "300") { $options .= " --font LEGEND:7:".$config['mono_font']." --font AXIS:6:".$config['mono_font']." --font-render-mode normal "; }
|
||||
$hostname = gethostbyid($device);
|
||||
$imgfile = $config['install_dir'] . "/graphs/" . "$graph";
|
||||
$iter = "1";
|
||||
$sql = mysql_query("SELECT * FROM `cempMemPool` where `device_id` = '$device'");
|
||||
$options .= "COMMENT:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Cur\ \ \ \ Max\\\\n";
|
||||
while($mempool = mysql_fetch_array($sql)) {
|
||||
$entPhysicalName = mysql_result(mysql_query("SELECT entPhysicalName from entPhysical WHERE device_id = '".$device."'
|
||||
AND entPhysicalIndex = '".$mempool['entPhysicalIndex']."'"),0);
|
||||
if($iter=="1") {$colour="CC0000";} elseif($iter=="2") {$colour="008C00";} elseif($iter=="3") {$colour="4096EE";
|
||||
} elseif($iter=="4") {$colour="73880A";} elseif($iter=="5") {$colour="D01F3C";} elseif($iter=="6") {$colour="36393D";
|
||||
} elseif($iter=="7") {$colour="FF0084"; unset($iter); }
|
||||
$mempool['descr_fixed'] = $entPhysicalName . " " . $mempool['cempMemPoolName'];
|
||||
$mempool['descr_fixed'] = str_replace("Routing Processor", "RP", $mempool['descr_fixed']);
|
||||
$mempool['descr_fixed'] = str_replace("Switching Processor", "SP", $mempool['descr_fixed']);
|
||||
$mempool['descr_fixed'] = str_replace("Processor", "Proc", $mempool['descr_fixed']);
|
||||
$mempool['descr_fixed'] = str_pad($mempool['descr_fixed'], 28);
|
||||
$mempool['descr_fixed'] = substr($mempool['descr_fixed'],0,28);
|
||||
$oid = $mempool['entPhysicalIndex'] . "." . $mempool['Index'];
|
||||
$rrd = $config['rrd_dir'] . "/$hostname/cempMemPool-$oid.rrd";
|
||||
$id = $mempool['entPhysicalIndex'] . "-" . $mempool['Index'];
|
||||
$options .= " DEF:mempool" . $id . "free=$rrd:free:AVERAGE ";
|
||||
$options .= " DEF:mempool" . $id . "used=$rrd:used:AVERAGE ";
|
||||
$options .= " CDEF:mempool" . $id . "total=mempool" . $id . "used,mempool" . $id . "used,mempool" . $id . "free,+,/,100,* ";
|
||||
$options .= " LINE1:mempool" . $id . "total#" . $colour . ":'" . $mempool['descr_fixed'] . "' ";
|
||||
$options .= " GPRINT:mempool" . $id . "total:LAST:%3.0lf";
|
||||
$options .= " GPRINT:mempool" . $id . "total:MAX:%3.0lf\\\l ";
|
||||
$iter++;
|
||||
}
|
||||
$thing = shell_exec($config['rrdtool'] . " graph $imgfile $options");
|
||||
return $imgfile;
|
||||
}
|
||||
|
||||
function graph_cempMemPool ($id, $graph, $from, $to, $width, $height, $title, $vertical) {
|
||||
global $config, $installdir;
|
||||
$options = "--start $from --end $to --width $width --height $height --vertical-label '$vertical' --alt-autoscale-max ";
|
||||
$options .= " -l 0 -E -b 1024 --title '$title' ";
|
||||
if($width <= "300") { $options .= " --font LEGEND:7:".$config['mono_font']." --font AXIS:6:".$config['mono_font']." --font-render-mode normal "; }
|
||||
$hostname = gethostbyid($device);
|
||||
$imgfile = $config['install_dir'] . "/graphs/" . "$graph";
|
||||
$iter = "1";
|
||||
$sql = mysql_query("SELECT * FROM `cempMemPool` AS C, `devices` AS D where C.`cempMemPool_id` = '$id' AND C.device_id = D.device_id");
|
||||
$options .= "COMMENT:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Cur\ \ \ \ Max\\\\n";
|
||||
while($mempool = mysql_fetch_array($sql)) {
|
||||
$entPhysicalName = mysql_result(mysql_query("SELECT entPhysicalName from entPhysical WHERE device_id = '".$mempool['device_id']."'
|
||||
AND entPhysicalIndex = '".$mempool['entPhysicalIndex']."'"),0);
|
||||
if($iter=="1") {$colour="CC0000";} elseif($iter=="2") {$colour="008C00";} elseif($iter=="3") {$colour="4096EE";
|
||||
} elseif($iter=="4") {$colour="73880A";} elseif($iter=="5") {$colour="D01F3C";} elseif($iter=="6") {$colour="36393D";
|
||||
} elseif($iter=="7") {$colour="FF0084"; unset($iter); }
|
||||
$mempool['descr_fixed'] = $entPhysicalName . " " . $mempool['cempMemPoolName'];
|
||||
$mempool['descr_fixed'] = str_replace("Routing Processor", "RP", $mempool['descr_fixed']);
|
||||
$mempool['descr_fixed'] = str_replace("Switching Processor", "SP", $mempool['descr_fixed']);
|
||||
$mempool['descr_fixed'] = str_replace("Processor", "Proc", $mempool['descr_fixed']);
|
||||
$mempool['descr_fixed'] = str_pad($mempool['descr_fixed'], 28);
|
||||
$mempool['descr_fixed'] = substr($mempool['descr_fixed'],0,28);
|
||||
$oid = $mempool['entPhysicalIndex'] . "." . $mempool['Index'];
|
||||
$rrd = $config['rrd_dir'] . "/".$mempool['hostname']."/cempMemPool-$oid.rrd";
|
||||
$id = $mempool['entPhysicalIndex'] . "-" . $mempool['Index'];
|
||||
$options .= " DEF:mempool" . $id . "free=$rrd:free:AVERAGE ";
|
||||
$options .= " DEF:mempool" . $id . "used=$rrd:used:AVERAGE ";
|
||||
$options .= " CDEF:mempool" . $id . "total=mempool" . $id . "used,mempool" . $id . "used,mempool" . $id . "free,+,/,100,* ";
|
||||
$options .= " LINE1:mempool" . $id . "total#" . $colour . ":'" . $mempool['descr_fixed'] . "' ";
|
||||
$options .= " GPRINT:mempool" . $id . "total:LAST:%3.0lf";
|
||||
$options .= " GPRINT:mempool" . $id . "total:MAX:%3.0lf\\\l ";
|
||||
$iter++;
|
||||
}
|
||||
|
||||
$thing = shell_exec($config['rrdtool'] . " graph $imgfile $options");
|
||||
return $imgfile;
|
||||
}
|
||||
|
||||
|
||||
function temp_graph_dev ($device, $graph, $from, $to, $width, $height, $title, $vertical) {
|
||||
global $config, $installdir;
|
||||
@@ -179,6 +281,7 @@ function graph_mac_acc ($id, $graph, $from, $to, $width, $height) {
|
||||
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height ";
|
||||
if($height < "33") { $options .= " --only-graph"; }
|
||||
if($width <= "300") { $options .= " --font LEGEND:7:".$config['mono_font']." --font AXIS:6:".$config['mono_font']." --font-render-mode normal "; }
|
||||
|
||||
$options .= " DEF:inoctets=$database:IN:AVERAGE";
|
||||
$options .= " DEF:outoctets=$database:OUT:AVERAGE";
|
||||
$options .= " CDEF:octets=inoctets,outoctets,+";
|
||||
@@ -390,22 +493,22 @@ function graph_cbgp_prefixes ($rrd, $graph, $from, $to, $width, $height) {
|
||||
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height ";
|
||||
if($width <= "300") {$options .= " --font LEGEND:7:".$config['mono_font']." --font AXIS:6:".$config['mono_font']." --font-render-mode normal "; }
|
||||
$options .= " DEF:Accepted=$database:AcceptedPrefixes:AVERAGE";
|
||||
$options .= " DEF:Denied=$database:DeniedPrefixes:AVERAGE";
|
||||
$options .= " DEF:Advertised=$database:AdvertisedPrefixes:AVERAGE";
|
||||
$options .= " DEF:Suppressed=$database:SuppressedPrefixes:AVERAGE";
|
||||
$options .= " DEF:Withdrawn=$database:WithdrawnPrefixes:AVERAGE";
|
||||
$options .= " CDEF:dAdvertised=Advertised,-1,*";
|
||||
#$options .= " DEF:Denied=$database:DeniedPrefixes:AVERAGE";
|
||||
#$options .= " DEF:Advertised=$database:AdvertisedPrefixes:AVERAGE";
|
||||
#$options .= " DEF:Suppressed=$database:SuppressedPrefixes:AVERAGE";
|
||||
#$options .= " DEF:Withdrawn=$database:WithdrawnPrefixes:AVERAGE";
|
||||
#$options .= " CDEF:dAdvertised=Advertised,-1,*";
|
||||
$options .= " COMMENT:Prefixes\ \ \ \ \ \ Current\ \ Minimum\ \ Maximum\\\\n";
|
||||
$options .= " AREA:Accepted#eeaaaa:";
|
||||
$options .= " LINE2:Accepted#cc0000:Accepted\ \ ";
|
||||
$options .= " GPRINT:Accepted:LAST:%6.2lf%s";
|
||||
$options .= " GPRINT:Accepted:MIN:%6.2lf%s";
|
||||
$options .= " GPRINT:Accepted:MAX:%6.2lf%s\\\\l";
|
||||
$options .= " AREA:dAdvertised#aaeeaa:";
|
||||
$options .= " LINE2:dAdvertised#00cc00:Advertised";
|
||||
$options .= " GPRINT:Advertised:LAST:%6.2lf%s";
|
||||
$options .= " GPRINT:Advertised:MIN:%6.2lf%s";
|
||||
$options .= " GPRINT:Advertised:MAX:%6.2lf%s\\\\l";
|
||||
#$options .= " AREA:dAdvertised#aaeeaa:";
|
||||
#$options .= " LINE2:dAdvertised#00cc00:Advertised";
|
||||
#$options .= " GPRINT:Advertised:LAST:%6.2lf%s";
|
||||
#$options .= " GPRINT:Advertised:MIN:%6.2lf%s";
|
||||
#$options .= " GPRINT:Advertised:MAX:%6.2lf%s\\\\l";
|
||||
$thing = shell_exec($config['rrdtool'] . " graph $imgfile $options");
|
||||
# echo($config['rrdtool'] . " graph $imgfile $options");
|
||||
return $imgfile;
|
||||
|
||||
@@ -4,7 +4,7 @@ $query = "SELECT * FROM cpmCPU WHERE device_id = '" . $device['device_id'] . "'"
|
||||
$proc_data = mysql_query($query);
|
||||
while($processor = mysql_fetch_array($proc_data)) {
|
||||
|
||||
$proc_cmd = "snmpget -O Uqnv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " cpmCPUTotal5minRev." . $processor['cpmCPU_oid'];
|
||||
$proc_cmd = "snmpget -m CISCO-PROCESS-MIB -O Uqnv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " cpmCPUTotal5minRev." . $processor['cpmCPU_oid'];
|
||||
$proc = shell_exec($proc_cmd);
|
||||
|
||||
echo("Checking CPU " . $processor['entPhysicalDescr'] . "... ");
|
||||
@@ -27,7 +27,6 @@ while($processor = mysql_fetch_array($proc_data)) {
|
||||
echo($proc . "%\n");
|
||||
|
||||
$updatecmd = $config['rrdtool'] ." update $procrrd N:$proc";
|
||||
echo("$updatecmd");
|
||||
shell_exec($updatecmd);
|
||||
|
||||
mysql_query("UPDATE `cpmCPU` SET `cpmCPUTotal5minRev` = '$proc' WHERE `cpmCPU_id` = '".$processor['cpmCPU_id']."'");
|
||||
|
||||
@@ -107,5 +107,6 @@
|
||||
|
||||
include("includes/polling/bgpPeer.inc.php");
|
||||
include("includes/polling/cisco-processors.inc.php");
|
||||
include("includes/polling/cisco-mempool.inc.php");
|
||||
|
||||
?>
|
||||
|
||||
@@ -14,7 +14,7 @@ if($device[os] != "Snom") {
|
||||
|
||||
$rrdfile = $config['rrd_dir'] . "/" . $device['hostname'] . "/netinfo.rrd";
|
||||
|
||||
$rrd_create = "rrdtool create $rrdfile ";
|
||||
$rrd_create = $config['rrdtool'] . " create $rrdfile ";
|
||||
$rrd_create .= "RRA:AVERAGE:0.5:1:600 RRA:AVERAGE:0.5:6:700 RRA:AVERAGE:0.5:24:775 RRA:AVERAGE:0.5:288:797 RRA:MAX:0.5:1:600 \
|
||||
RRA:MAX:0.5:6:700 RRA:MAX:0.5:24:775 RRA:MAX:0.5:288:797";
|
||||
|
||||
@@ -23,8 +23,10 @@ if($device[os] != "Snom") {
|
||||
$snmpstring .= " $oid.0";
|
||||
}
|
||||
|
||||
if(!file_exists($rrdfile)) { `$rrd_create`; }
|
||||
$snmpdata_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " $snmpstring";
|
||||
if(!file_exists($rrdfile)) {
|
||||
shell_exec($rrd_create);
|
||||
}
|
||||
$snmpdata_cmd = "snmpget -m IP-MIB:SNMPv2-MIB:UDP-MIB:TCP-MIB:IP-MIB -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " $snmpstring";
|
||||
$snmpdata = trim(`$snmpdata_cmd`);
|
||||
$rrdupdate = "N";
|
||||
foreach(explode("\n", $snmpdata) as $data) {
|
||||
|
||||
@@ -48,7 +48,7 @@ while ($dr = mysql_fetch_array($dq)) {
|
||||
$hrStorageAllocationUnits = $dr['hrStorageAllocationUnits'];
|
||||
$hrStorageSize = $dr['hrStorageAllocationUnits'] * $dr['hrStorageSize'];
|
||||
$hrStorageDescr = $dr['hrStorageDescr'];
|
||||
$cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " hrStorageUsed.$hrStorageIndex";
|
||||
$cmd = "snmpget -m HOST-RESOURCES-MIB -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " hrStorageUsed.$hrStorageIndex";
|
||||
$used_units = trim(`$cmd`);
|
||||
$used = $used_units * $hrStorageAllocationUnits;
|
||||
$perc = round($used / $hrStorageSize * 100, 2);
|
||||
@@ -78,14 +78,10 @@ while ($dr = mysql_fetch_array($dq)) {
|
||||
if($dr['storage_perc'] < '40' && $perc >= '40') {
|
||||
|
||||
if($device['sysContact']) { $email = $device['sysContact']; } else { $email = $config['email_default']; }
|
||||
|
||||
$msg = "Disk Alarm: " . $device['hostname'] . " " . $dr['hrStorageDescr'] . " is " . $perc;
|
||||
$msg .= " at " . date('l dS F Y h:i:s A');
|
||||
|
||||
mail($email, "Disk Alarm: " . $device['hostname'] . " " . $dr['hrStorageDescr'], $msg, $config['email_headers']);
|
||||
|
||||
echo("Alerting for " . $device['hostname'] . " " . $dr['hrStorageDescr'] . "/n");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -104,11 +100,11 @@ $oid_ssCpuUser = ".1.3.6.1.4.1.2021.11.9.0";
|
||||
$oid_ssCpuSystem = ".1.3.6.1.4.1.2021.11.10.0";
|
||||
|
||||
|
||||
$cpu_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'];
|
||||
$cpu_cmd = $config['snmpget'] ." -m UCD-SNMP-MIB:HOST-RESOURCES-MIB -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'];
|
||||
$cpu_cmd .= " $oid_ssCpuRawUser $oid_ssCpuRawSystem $oid_ssCpuRawNice $oid_ssCpuRawIdle $oid_hrSystemProcesses";
|
||||
$cpu_cmd .= " $oid_hrSystemNumUsers $oid_ssCpuUser $oid_ssCpuSystem .1.3.6.1.4.1.2021.1.101.1";
|
||||
$cpu_cmd .= " $oid_hrSystemNumUsers $oid_ssCpuUser $oid_ssCpuSystem";
|
||||
$cpu = `$cpu_cmd`;
|
||||
list ($cpuUser, $cpuSystem, $cpuNice, $cpuIdle, $procs, $users, $UsageUser, $UsageSystem, $cputemp) = explode("\n", $cpu);
|
||||
list ($cpuUser, $cpuSystem, $cpuNice, $cpuIdle, $procs, $users, $UsageUser, $UsageSystem) = explode("\n", $cpu);
|
||||
|
||||
$cpuUsage = $UsageUser + $UsageSystem;
|
||||
|
||||
@@ -192,13 +188,14 @@ if($device[os] != "m0n0wall" && $device[os] != "Voswall" && $device[os] != "pfSe
|
||||
RRA:MAX:0.5:288:800");
|
||||
} // end create load rrd
|
||||
|
||||
$mem_get = "memTotalSwap.0 memAvailSwap.0 memTotalReal.0 memAvailReal.0 memTotalFree.0 memShared.0 memBuffer.0 memCached.0";
|
||||
$mem_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " " . $mem_get;
|
||||
$mem_raw = `$mem_cmd`;
|
||||
list($memTotalSwap, $memAvailSwap, $memTotalReal, $memAvailReal, $memTotalFree, $memShared, $memBuffer, $memCached) = explode("\n", $mem_raw);
|
||||
$mem_cmd = $config['snmpget'] . " -m UCD-SNMP-MIB -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'];
|
||||
$mem_cmd .= " memTotalSwap.0 memAvailSwap.0 memTotalReal.0 memAvailReal.0 memTotalFree.0 memShared.0 memBuffer.0 memCached.0";
|
||||
|
||||
$mem_raw = shell_exec($mem_cmd);
|
||||
list($memTotalSwap, $memAvailSwap, $memTotalReal, $memAvailReal, $memTotalFree, $memShared, $memBuffer, $memCached) = explode("\n", str_replace(" kB", "", $mem_raw));
|
||||
|
||||
$load_get = "laLoadInt.1 laLoadInt.2 laLoadInt.3";
|
||||
$load_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " " . $load_get;
|
||||
$load_cmd = "snmpget -m UCD-SNMP-MIB -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " " . $load_get;
|
||||
$load_raw = `$load_cmd`;
|
||||
list ($load1, $load5, $load10) = explode ("\n", $load_raw);
|
||||
|
||||
@@ -206,16 +203,4 @@ if($device[os] != "m0n0wall" && $device[os] != "Voswall" && $device[os] != "pfSe
|
||||
rrdtool_update($loadrrd, "N:$load1:$load5:$load10");
|
||||
rrdtool_update($memrrd, "N:$memTotalSwap:$memAvailSwap:$memTotalReal:$memAvailReal:$memTotalFree:$memShared:$memBuffer:$memCached");
|
||||
|
||||
if($device['courier']) {
|
||||
include("includes/polling/courierstats.inc.php");
|
||||
}
|
||||
|
||||
if($device['postfix']) {
|
||||
include("includes/polling/mailstats.inc.php");
|
||||
}
|
||||
|
||||
if($device['apache']) {
|
||||
include("includes/polling/apachestats.inc.php");
|
||||
}
|
||||
|
||||
} // end Non-m0n0wall
|
||||
|
||||
@@ -18,7 +18,7 @@ while ($interface = mysql_fetch_array($interface_query)) {
|
||||
|
||||
echo("Looking at " . $interface['ifDescr'] . " on " . $device['hostname'] . "\n");
|
||||
|
||||
$snmp_cmd = $config['snmpget'] . " -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'];
|
||||
$snmp_cmd = $config['snmpget'] . " -m IF-MIB -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'];
|
||||
$snmp_cmd .= " ifAdminStatus." . $interface['ifIndex'] . " ifOperStatus." . $interface['ifIndex'] . " ifAlias." . $interface['ifIndex'];
|
||||
|
||||
$snmp_output = trim(`$snmp_cmd`);
|
||||
@@ -93,8 +93,8 @@ while ($interface = mysql_fetch_array($interface_query)) {
|
||||
|
||||
if($ifOperStatus == "up") {
|
||||
|
||||
$snmp_data_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'];
|
||||
$snmp_data_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'];
|
||||
# $snmp_data_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'];
|
||||
$snmp_data_cmd = "snmpget -m IF-MIB -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'];
|
||||
$snmp_data_cmd .= " ifHCInOctets." . $interface['ifIndex'] . " ifHCOutOctets." . $interface['ifIndex'] . " ifInErrors." . $interface['ifIndex'];
|
||||
$snmp_data_cmd .= " ifOutErrors." . $interface['ifIndex'] . " ifInUcastPkts." . $interface['ifIndex'] . " ifOutUcastPkts." . $interface['ifIndex'];
|
||||
$snmp_data_cmd .= " ifInNUcastPkts." . $interface['ifIndex'] . " ifOutNUcastPkts." . $interface['ifIndex'];
|
||||
@@ -119,7 +119,7 @@ while ($interface = mysql_fetch_array($interface_query)) {
|
||||
}
|
||||
}
|
||||
|
||||
$rates = interface_rates ($interface);
|
||||
$rates = interface_rates ($rrdfile);
|
||||
mysql_query("UPDATE `interfaces` SET in_rate = '" . $rates['in'] . "', out_rate = '" . $rates['out'] . "' WHERE interface_id= '" . $interface['interface_id'] . "'");
|
||||
|
||||
}
|
||||
|
||||
@@ -19,12 +19,20 @@ $config['afi']['ipv6']['multicast'] = "IPv6 Multicast";
|
||||
|
||||
$config['version'] = "0.5.1";
|
||||
|
||||
### Connect to database
|
||||
if (!@mysql_connect($config['db_host'], $config['db_user'], $config['db_pass'])) {
|
||||
echo "<h2>MySQL Error</h2>";
|
||||
$nagios_link = mysql_connect($config['nagios_db_host'], $config['nagios_db_user'], $config['nagios_db_pass']);
|
||||
if (!$nagios_link) {
|
||||
echo "<h2>Nagios MySQL Error</h2>";
|
||||
die;
|
||||
}
|
||||
mysql_select_db($config['db_name']);
|
||||
$nagios_db = mysql_select_db($config['nagios_db_name'], $nagios_link);
|
||||
|
||||
### Connect to database
|
||||
$observer_link = mysql_connect($config['db_host'], $config['db_user'], $config['db_pass']);
|
||||
if (!$observer_link) {
|
||||
echo "<h2>Observer MySQL Error</h2>";
|
||||
die;
|
||||
}
|
||||
$observer_db = mysql_select_db($config['db_name'], $observer_link);
|
||||
|
||||
# Set some times needed by loads of scripts (it's dynamic, so we do it here!)
|
||||
|
||||
|
||||
+4
-2
@@ -15,7 +15,7 @@ function process_syslog ($entry, $update) {
|
||||
if($device_id_host) {
|
||||
$device_id = $device_id_host;
|
||||
} else {
|
||||
$device_id_ip = @mysql_result(mysql_query("SELECT D.device_id as device_id FROM ipaddr AS A, interfaces AS I, devices AS D WHERE A.addr = '" . $entry['host']."' AND I.interface_id = A.interface_id AND D.device_id = I.device_id"),0);
|
||||
$device_id_ip = @mysql_result(mysql_query("SELECT D.device_id as device_id FROM ipv4_addresses AS A, interfaces AS I, devices AS D WHERE A.ipv4_address = '" . $entry['host']."' AND I.interface_id = A.interface_id AND D.device_id = I.device_id"),0);
|
||||
if($device_id_ip) {
|
||||
$device_id = $device_id_ip;
|
||||
}
|
||||
@@ -23,8 +23,10 @@ function process_syslog ($entry, $update) {
|
||||
|
||||
if($device_id && !$delete) {
|
||||
$entry['device_id'] = $device_id;
|
||||
if(mysql_result(mysql_query("SELECT `os` FROM `devices` WHERE `device_id` = '$device_id'"),0) == "IOS") {
|
||||
$os = mysql_result(mysql_query("SELECT `os` FROM `devices` WHERE `device_id` = '$device_id'"),0);
|
||||
if($os == "IOS" || $os == "IOS XE") {
|
||||
if(strstr($entry[msg], "%")) {
|
||||
$entry['msg'] = preg_replace("/^%(.+?):\ /", "\\1||", $entry['msg']);
|
||||
list(,$entry[msg]) = split(": %", $entry['msg']);
|
||||
$entry['msg'] = "%" . $entry['msg'];
|
||||
$entry['msg'] = preg_replace("/^%(.+?):\ /", "\\1||", $entry['msg']);
|
||||
|
||||
Reference in New Issue
Block a user