tidied up things

git-svn-id: http://www.observium.org/svn/observer/trunk@477 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2009-09-30 12:27:18 +00:00
parent 000ca589a9
commit ccf67209fd
4 changed files with 38 additions and 27 deletions
+10 -9
View File
@@ -1,16 +1,15 @@
<?php <?php
function graph_mac_acc_total ($args) { function graph_mac_acc_total ($args) {
global $config;
if($args['height'] < "99") { $options .= " --only-graph "; } include("common.inc.php");
if($args['sort'] == "in" || $args['sort'] == "out") { $sort = "bps_" . $args['sort']; } else { $sort = "bps"; } if($args['sort'] == "in" || $args['sort'] == "out") { $sort = "bps_" . $args['sort']; } else { $sort = "bps"; }
$imgfile = $config['install_dir'] . "/graphs/" . $args['graphfile'];
$options .= " --alt-autoscale-max -E --start ".$args['from']." --end " . ($args['to'] - 150) . " --width ".$args['width']." --height ".$args['height']." ";
$options .= $config['rrdgraph_def_text'];
$sql = "SELECT *, (bps_in + bps_out) AS bps FROM `mac_accounting` AS M, `interfaces` AS I, `devices` AS D WHERE M.interface_id = '".$args['port']."' $sql = "SELECT *, (bps_in + bps_out) AS bps FROM `mac_accounting` AS M, `interfaces` AS I, `devices` AS D WHERE M.interface_id = '".$args['port']."'
AND I.interface_id = M.interface_id AND I.device_id = D.device_id ORDER BY $sort DESC LIMIT 0,10"; AND I.interface_id = M.interface_id AND I.device_id = D.device_id ORDER BY $sort DESC LIMIT 0," . $args['topn'];
$query = mysql_query($sql); $query = mysql_query($sql);
if($args['width'] <= "300") { $options .= "--font LEGEND:7:".$config['mono_font']." --font AXIS:6:".$config['mono_font']." --font-render-mode normal "; } if($args['width'] <= "300") { $options .= " --font LEGEND:7:".$config['mono_font']." --font AXIS:6:".$config['mono_font']." --font-render-mode normal "; }
$pluses = ""; $iter = '0'; $pluses = ""; $iter = '0';
$options .= " COMMENT:' In\: Current Maximum Total Out\: Current Maximum Total\\\\n'"; $options .= " COMMENT:' In\: Current Maximum Total Out\: Current Maximum Total\\\\n'";
while($acc = mysql_fetch_array($query)) { while($acc = mysql_fetch_array($query)) {
@@ -57,8 +56,9 @@ function graph_mac_acc_total ($args) {
} }
} }
$options .= $optionsb; $options .= $optionsb;
$thing = shell_exec($config['rrdtool'] . " graph $imgfile $options"); # echo($config['rrdtool'] . " graph $graphfile $options");
return $imgfile; $thing = shell_exec($config['rrdtool'] . " graph $graphfile $options");
return $graphfile;
} }
$args['port'] = $_GET['port']; $args['port'] = $_GET['port'];
@@ -69,6 +69,7 @@ $args['from'] = $from;
$args['to'] = $to; $args['to'] = $to;
$args['width'] = $width; $args['width'] = $width;
$args['height'] = $height; $args['height'] = $height;
if(is_numeric($_GET['topn'])) { $args['topn'] = $_GET['topn']; } else { $args['topn'] = '10'; }
$graph = graph_mac_acc_total ($args); $graph = graph_mac_acc_total ($args);
+17 -13
View File
@@ -1,13 +1,11 @@
<?php <?php
function graph_multi_bits ($interfaces, $graph, $from, $to, $width, $height, $title, $vertical, $inverse, $legend = '1') { function graph_multi_bits ($args) {
global $config, $installdir;
$imgfile = $config['install_dir'] . "/graphs/" . "$graph"; include("common.inc.php");
$options = "--alt-autoscale-max -E --start $from --end " . ($to - 150) . " --width $width --height $height";
$options .= $config['rrdgraph_def_text'];
if($height < "99") { $options .= " --only-graph"; }
$i = 1; $i = 1;
foreach(explode(",", $interfaces) as $ifid) { foreach(explode(",", $args['interfaces']) as $ifid) {
$query = mysql_query("SELECT `ifIndex`, `hostname` FROM `interfaces` AS I, devices as D WHERE I.interface_id = '" . $ifid . "' AND I.device_id = D.device_id"); $query = mysql_query("SELECT `ifIndex`, `hostname` FROM `interfaces` AS I, devices as D WHERE I.interface_id = '" . $ifid . "' AND I.device_id = D.device_id");
$int = mysql_fetch_row($query); $int = mysql_fetch_row($query);
if(is_file($config['rrd_dir'] . "/" . $int[1] . "/" . $int[0] . ".rrd")) { if(is_file($config['rrd_dir'] . "/" . $int[1] . "/" . $int[0] . ".rrd")) {
@@ -28,7 +26,7 @@ function graph_multi_bits ($interfaces, $graph, $from, $to, $width, $height, $ti
$options .= " CDEF:inbits=inoctets,8,*"; $options .= " CDEF:inbits=inoctets,8,*";
$options .= " CDEF:outbits=outoctets,8,*"; $options .= " CDEF:outbits=outoctets,8,*";
$options .= " CDEF:doutbits=doutoctets,8,*"; $options .= " CDEF:doutbits=doutoctets,8,*";
if($legend == "no") { if($args['legend'] == '0') {
$options .= " AREA:inbits#CDEB8B:"; $options .= " AREA:inbits#CDEB8B:";
$options .= " LINE1.25:inbits#006600:"; $options .= " LINE1.25:inbits#006600:";
$options .= " AREA:doutbits#C3D9FF:"; $options .= " AREA:doutbits#C3D9FF:";
@@ -44,16 +42,22 @@ function graph_multi_bits ($interfaces, $graph, $from, $to, $width, $height, $ti
$options .= " LINE1.25:doutbits#000099:Out"; $options .= " LINE1.25:doutbits#000099:Out";
$options .= " GPRINT:outbits:LAST:%6.2lf%s"; $options .= " GPRINT:outbits:LAST:%6.2lf%s";
$options .= " GPRINT:outbits:AVERAGE:%6.2lf%s"; $options .= " GPRINT:outbits:AVERAGE:%6.2lf%s";
$options .= " GPRINT:outbits:MAX:%6.2lf%s"; $options .= " GPRINT:outbits:MAX:%6.2lf%s\\\l";
} }
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 $graphfile $options");
$thing = shell_exec($config['rrdtool'] . " graph $imgfile $options"); return $graphfile;
return $imgfile;
} }
if($_GET['if']) { $interfaces = $_GET['if']; } if($_GET['if']) { $interfaces = $_GET['if']; }
if($_GET['interfaces']) { $interfaces = $_GET['interfaces']; } if($_GET['interfaces']) { $interfaces = $_GET['interfaces']; }
$graph = graph_multi_bits ($interfaces, $graphfile, $from, $to, $width, $height, $title, $vertical, $inverse, $legend); $args['interfaces'] = $interfaces;
$args['graphfile'] = $graphfile;
$args['from'] = $from;
$args['to'] = $to;
$args['width'] = $width;
$args['height'] = $height;
$graph = graph_multi_bits ($args);
?> ?>
+2 -1
View File
@@ -72,10 +72,11 @@ while ($device = mysql_fetch_array($device_query)) {
list($a,$b,$c,$d) = explode("\n", shell_exec($snmp_cmdb)); list($a,$b,$c,$d) = explode("\n", shell_exec($snmp_cmdb));
if($b == "0") { $ciscomodel = $a; } if($b == "0") { $ciscomodel = $a; }
if($d == "0") { $ciscomodel = $c; } if($d == "0") { $ciscomodel = $c; }
$ciscomodel = str_replace("\"","",$ciscomodel);
} else { unset($ciscomodel); } } else { unset($ciscomodel); }
$snmpdata = shell_exec($snmp_cmd); $snmpdata = shell_exec($snmp_cmd);
# $snmpdata = preg_replace("/^.*IOS/","", $snmpdata); #$snmpdata = preg_replace("/^.*IOS/","", $snmpdata);
$snmpdata = trim($snmpdata); $snmpdata = trim($snmpdata);
$snmpdata = str_replace("\"", "", $snmpdata); $snmpdata = str_replace("\"", "", $snmpdata);
list($sysUptime, $sysLocation, $sysContact, $sysName) = explode("\n", $snmpdata); list($sysUptime, $sysLocation, $sysContact, $sysName) = explode("\n", $snmpdata);
+9 -4
View File
@@ -19,10 +19,15 @@
$oid .= ".".hexdec(substr($mac, 10, 2)); $oid .= ".".hexdec(substr($mac, 10, 2));
$snmp_cmd = $config['snmpget'] . " -m CISCO-IP-STAT-MIB -O Uqnv -" . $acc['snmpver'] . " -c " . $acc['community'] . " " . $acc['hostname']; $snmp_cmd = $config['snmpget'] . " -m CISCO-IP-STAT-MIB -O Uqnv -" . $acc['snmpver'] . " -c " . $acc['community'] . " " . $acc['hostname'];
$snmp_cmd .= " cipMacSwitchedBytes.". $acc['ifIndex'] .".input." . $oid; #$snmp_cmd .= " cipMacSwitchedBytes.". $acc['ifIndex'] .".input." . $oid;
$snmp_cmd .= " cipMacSwitchedBytes.". $acc['ifIndex'] .".output." . $oid; #$snmp_cmd .= " cipMacSwitchedBytes.". $acc['ifIndex'] .".output." . $oid;
$snmp_cmd .= " cipMacSwitchedPkts.". $acc['ifIndex'] .".input." . $oid; #$snmp_cmd .= " cipMacSwitchedPkts.". $acc['ifIndex'] .".input." . $oid;
$snmp_cmd .= " cipMacSwitchedPkts.". $acc['ifIndex'] .".output." . $oid; #$snmp_cmd .= " cipMacSwitchedPkts.". $acc['ifIndex'] .".output." . $oid;
$snmp_cmd .= " cipMacHCSwitchedBytes.". $acc['ifIndex'] .".input." . $oid;
$snmp_cmd .= " cipMacHCSwitchedBytes.". $acc['ifIndex'] .".output." . $oid;
$snmp_cmd .= " cipMacHCSwitchedPkts.". $acc['ifIndex'] .".input." . $oid;
$snmp_cmd .= " cipMacHCSwitchedPkts.". $acc['ifIndex'] .".output." . $oid;
$snmp_output = trim(shell_exec($snmp_cmd)); $snmp_output = trim(shell_exec($snmp_cmd));