mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
improved integration with mac accounting. added packets to mac accounting
git-svn-id: http://www.observium.org/svn/observer/trunk@470 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@@ -30,6 +30,7 @@ RewriteRule ^vrf/(.+)/(.+)/(.+)/ ?page=vrf&id=$1&opta=$2&optb=$3
|
||||
RewriteRule ^vrf/(.+)/(.+)/ ?page=vrf&id=$1&opta=$2
|
||||
RewriteRule ^vrf/(.+)/ ?page=vrf&id=$1
|
||||
|
||||
RewriteRule ^device/([0-9]+)/([a-z]+)/(.+)/(.+)/(.+)/(.+)/ ?page=device&id=$1§ion=$2&opta=$3&optb=$4&optc=$5&optd=$6
|
||||
RewriteRule ^device/([0-9]+)/([a-z]+)/(.+)/(.+)/(.+)/ ?page=device&id=$1§ion=$2&opta=$3&optb=$4&optc=$5
|
||||
RewriteRule ^device/([0-9]+)/([a-z]+)/(.+)/(.+)/ ?page=device&id=$1§ion=$2&opta=$3&optb=$4
|
||||
RewriteRule ^device/([0-9]+)/([a-z]+)/(.+)/ ?page=device&id=$1§ion=$2&opta=$3
|
||||
|
@@ -96,7 +96,11 @@ if($_GET['debug']) {
|
||||
case 'mac_acc_int':
|
||||
$graph = graph_mac_acc_interface ($_GET['if'], $graphfile, $from, $to, $width, $height, $title, $vertical);
|
||||
break;
|
||||
case 'mac_acc_pkts':
|
||||
$graph = graph_mac_pkts ($_GET['id'], $graphfile, $from, $to, $width, $height, $title, $vertical);
|
||||
break;
|
||||
case 'mac_acc':
|
||||
case 'mac_acc_bits':
|
||||
$graph = graph_mac_acc ($_GET['id'], $graphfile, $from, $to, $width, $height, $title, $vertical);
|
||||
break;
|
||||
case 'device_bits':
|
||||
|
@@ -42,14 +42,45 @@ $interface = mysql_fetch_array($interface_query);
|
||||
$broke = yes;
|
||||
}
|
||||
|
||||
if( !$broke)
|
||||
{ }
|
||||
|
||||
echo("<div style='clear: both;'>");
|
||||
|
||||
echo("
|
||||
<div style='margin:auto; text-align: center; margin-top: 0px; margin-bottom: 10px;'>
|
||||
<b class='rounded'>
|
||||
<b class='rounded1'><b></b></b>
|
||||
<b class='rounded2'><b></b></b>
|
||||
<b class='rounded3'></b>
|
||||
<b class='rounded4'></b>
|
||||
<b class='rounded5'></b></b>
|
||||
<div class='roundedfg' style='padding: 0px 5px;'>
|
||||
<div style='margin: auto; text-align: left; padding: 2px 5px; padding-left: 11px; clear: both; display:block; height:20px;'>
|
||||
|
||||
<a href='".$config['base_url']."/device/" . $device['device_id'] . "/interface/".$interface['interface_id']."/'>Graphs</a> |
|
||||
<a href='".$config['base_url']."/device/" . $device['device_id'] . "/interface/".$interface['interface_id']."/arp/'>ARP Table</a>");
|
||||
|
||||
if(mysql_result(mysql_query("SELECT count(*) FROM mac_accounting WHERE interface_id = '".$interface['interface_id']."'"),0)){
|
||||
|
||||
echo(" | Mac Accounting :
|
||||
<a href='".$config['base_url']."/device/" . $device['device_id'] . "/interface/".$interface['interface_id']."/macaccounting/bits/'>Bits</a>
|
||||
(<a href='".$config['base_url']."/device/" . $device['device_id'] . "/interface/".$interface['interface_id']."/macaccounting/bits/thumbs/'>Mini</a>) |
|
||||
<a href='".$config['base_url']."/device/" . $device['device_id'] . "/interface/".$interface['interface_id']."/macaccounting/pkts/'>Packets</a>
|
||||
(<a href='".$config['base_url']."/device/" . $device['device_id'] . "/interface/".$interface['interface_id']."/macaccounting/pkts/thumbs/'>Mini</a>)");
|
||||
}
|
||||
|
||||
echo("</div>
|
||||
</div>
|
||||
<b class='rounded'>
|
||||
<b class='rounded5'></b>
|
||||
<b class='rounded4'></b>
|
||||
<b class='rounded3'></b>
|
||||
<b class='rounded2'><b></b></b>
|
||||
<b class='rounded1'><b></b></b></b>
|
||||
</div>
|
||||
");
|
||||
|
||||
if($_GET['optb']) {
|
||||
|
||||
include("pages/device/".mres($_GET['optb']).".php");
|
||||
include("pages/device/port/".mres($_GET['optb']).".php");
|
||||
|
||||
} else {
|
||||
|
||||
|
@@ -1,11 +1,5 @@
|
||||
<?php
|
||||
|
||||
echo("<div style='width: 100%; text-align: right; padding-bottom: 10px; clear: both; display:block; height:20px;'>
|
||||
<a href='device/".$interface['device_id']."/interface/".$interface['interface_id']."/macaccounting/'>Full</a> |
|
||||
<a href='device/".$interface['device_id']."/interface/".$interface['interface_id']."/macaccounting/thumbs/'>Compact</a>
|
||||
</div> ");
|
||||
|
||||
|
||||
$hostname = $device['hostname'];
|
||||
$hostid = $device['interface_id'];
|
||||
$ifname = $interface['ifDescr'];
|
||||
@@ -24,20 +18,19 @@ echo("<div style='width: 100%; text-align: right; padding-bottom: 10px; clear: b
|
||||
$i = 1;
|
||||
$inf = fixifName($ifname);
|
||||
|
||||
$bg="#ffffff";
|
||||
|
||||
$query = mysql_query("SELECT *, (M.bps_in + M.bps_out) as bps FROM `mac_accounting` AS M, `interfaces` AS I, `devices` AS D WHERE M.interface_id = '".$interface['interface_id']."' AND I.interface_id = M.interface_id AND I.device_id = D.device_id ORDER BY bps DESC");
|
||||
|
||||
echo("<div style='clear: both;'>");
|
||||
|
||||
while($acc = mysql_fetch_array($query)) {
|
||||
|
||||
if(!is_integer($i/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; }
|
||||
|
||||
$addy = mysql_fetch_array(mysql_query("SELECT * FROM ipv4_mac where mac_address = '".$acc['mac']."'"));
|
||||
$name = gethostbyaddr($addy['ipv4_address']);
|
||||
|
||||
if($name == $addy['ipv4_address']) { unset ($name); }
|
||||
|
||||
if($bg == "#ffffff") { $bg = "#e5e5e5"; } else { $bg="#ffffff"; }
|
||||
if(mysql_result(mysql_query("SELECT count(*) FROM bgpPeers WHERE device_id = '".$acc['device_id']."' AND bgpPeerIdentifier = '".$addy['ipv4_address']."'"),0)) {
|
||||
|
||||
$peer_query = mysql_query("SELECT * FROM bgpPeers WHERE device_id = '".$acc['device_id']."' AND bgpPeerIdentifier = '".$addy['ipv4_address']."'");
|
||||
@@ -50,7 +43,13 @@ echo("<div style='width: 100%; text-align: right; padding-bottom: 10px; clear: b
|
||||
unset ($as); unset ($astext); unset($asn);
|
||||
}
|
||||
|
||||
if($_GET['optc'] == "thumbs") {
|
||||
if($_GET['optc']) {
|
||||
$graph_type = "mac_acc_" . $_GET['optc'];
|
||||
} else {
|
||||
$graph_type = "mac_acc_bits";
|
||||
}
|
||||
|
||||
if($_GET['optd'] == "thumbs") {
|
||||
|
||||
if(!$asn) { $asn = "No Session"; }
|
||||
|
||||
@@ -58,16 +57,16 @@ echo("<div style='width: 100%; text-align: right; padding-bottom: 10px; clear: b
|
||||
".$addy['ipv4_address']." - ".$asn."
|
||||
<a href='#' onmouseover=\"return overlib('\
|
||||
<div style=\'font-size: 16px; padding:5px; font-weight: bold; color: #555555;\'>".$name." - ".$addy['ipv4_address']." - ".$asn."</div>\
|
||||
<img src=\'graph.php?id=" . $acc['ma_id'] . "&type=mac_acc&from=-2day&to=$now&width=450&height=150\'>\
|
||||
<img src=\'graph.php?id=" . $acc['ma_id'] . "&type=$graph_type&from=-2day&to=$now&width=450&height=150\'>\
|
||||
', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 150);\" onmouseout=\"return nd();\" >
|
||||
<img src='graph.php?id=" . $acc['ma_id'] . "&type=mac_acc&from=-2day&to=$now&width=215&height=45'></a>
|
||||
<img src='graph.php?id=" . $acc['ma_id'] . "&type=$graph_type&from=-2day&to=$now&width=215&height=45'></a>
|
||||
|
||||
<span style='font-size: 10px;'>".$name."</span>
|
||||
</div>");
|
||||
|
||||
} else {
|
||||
|
||||
echo("<div style='background-color: $bg; padding: 8px;'>");
|
||||
echo("<div style='background-color: $row_colour; padding: 8px;'>");
|
||||
|
||||
echo("
|
||||
<table>
|
||||
@@ -83,9 +82,6 @@ echo("<div style='width: 100%; text-align: right; padding-bottom: 10px; clear: b
|
||||
|
||||
$peer_info['astext'];
|
||||
|
||||
|
||||
$graph_type = "mac_acc";
|
||||
|
||||
$daily_traffic = "graph.php?id=" . $acc['ma_id'] . "&type=$graph_type&from=$day&to=$now&width=210&height=100";
|
||||
$daily_url = "graph.php?id=" . $acc['ma_id'] . "&type=$graph_type&from=$day&to=$now&width=500&height=150";
|
||||
|
||||
@@ -109,7 +105,7 @@ echo("<div style='width: 100%; text-align: right; padding-bottom: 10px; clear: b
|
||||
|
||||
|
||||
echo("</div>");
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
}
|
@@ -89,16 +89,20 @@ if($_GET['optc'] == thumbs) {
|
||||
} elseif(mysql_result(mysql_query("SELECT count(*) FROM bgpPeers WHERE device_id = '".$device['device_id']."' AND bgpPeerIdentifier ='".$arp['ipv4_address']."'"),0)) {
|
||||
$peer_query = mysql_query("SELECT * FROM bgpPeers WHERE device_id = '".$device['device_id']."' AND bgpPeerIdentifier = '".$arp['ipv4_address']."'");
|
||||
$peer_info = mysql_fetch_array($peer_query);
|
||||
$remote_host = "AS".$peer_info['bgpPeerRemoteAs'];
|
||||
$remote_port = truncate($peer_info['astext'], 24);
|
||||
$remote_port = "AS".$peer_info['bgpPeerRemoteAs'];
|
||||
$remote_host = $peer_info['astext'];
|
||||
} elseif($mac_acc['interface_id'] == $interface['interface_id']) {
|
||||
$remote_host = gethostbyaddr($arp['ipv4_address']);
|
||||
if($remote_host == $arp['ipv4_address']) { unset ($remote_host); }
|
||||
$remote_port = "";
|
||||
} else {
|
||||
$remote_host = "";
|
||||
$remote_port = "";
|
||||
}
|
||||
echo("<td>$remote_host</td><td>$remote_port</td>");
|
||||
|
||||
echo("<td>".truncate($remote_host, 24, "")."</td><td>$remote_port</td>");
|
||||
if ($mac_acc['interface_id'] == $interface['interface_id']) {
|
||||
echo("<td>".formatRates($mac_acc['bps_out'])."</td><td>".formatRates($mac_acc['bps_in'])."</td>");
|
||||
$style = "onmouseover=\"return overlib('<img src=\'graph.php?id=" . $mac_acc['ma_id'] . "&type=mac_acc&from=$day&to=$now&width=500&height=150\'>', LEFT".$config['overlib_defaults'].", WIDTH, 500);\" onmouseout=\"return nd();\"";
|
||||
echo("<td><a $style>".formatRates($mac_acc['bps_out'])."</a></td><td><a $style>".formatRates($mac_acc['bps_in'])."</a></td>");
|
||||
} else {
|
||||
echo("<td></td><td></td>");
|
||||
}
|
||||
|
@@ -571,54 +571,6 @@ function graph_mac_acc ($id, $graph, $from, $to, $width, $height) {
|
||||
|
||||
}
|
||||
|
||||
function graph_mac_acc_old ($id, $graph, $from, $to, $width, $height) {
|
||||
global $config;
|
||||
$imgfile = $config['install_dir'] . "/graphs/" . "$graph";
|
||||
$query = mysql_query("SELECT * FROM `mac_accounting` AS M, `interfaces` AS I, `devices` AS D WHERE M.ma_id = '".$id."' AND I.interface_id = M.interface_id AND I.device_id = D.device_id");
|
||||
$acc = mysql_fetch_array($query);
|
||||
$database = $config['rrd_dir'] . "/" . $acc['hostname'] . "/mac-accounting/" . $acc['ifIndex'] . "-" . $acc['mac'] . ".rrd";
|
||||
$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"; }
|
||||
$period = $to - $from;
|
||||
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height ";
|
||||
if($height < "99") { $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,+";
|
||||
$options .= " CDEF:doutoctets=outoctets,-1,*";
|
||||
$options .= " CDEF:inbits=inoctets,8,*";
|
||||
$options .= " CDEF:outbits=outoctets,8,*";
|
||||
$options .= " CDEF:doutbits=doutoctets,8,*";
|
||||
$options .= " VDEF:totin=inoctets,TOTAL";
|
||||
$options .= " VDEF:totout=outoctets,TOTAL";
|
||||
$options .= " VDEF:tot=octets,TOTAL";
|
||||
$options .= " VDEF:95thin=inbits,95,PERCENT";
|
||||
$options .= " VDEF:95thout=outbits,95,PERCENT";
|
||||
$options .= " VDEF:d95thout=doutbits,5,PERCENT";
|
||||
$options .= " AREA:inbits#CDEB8B:";
|
||||
$options .= " COMMENT:BPS\ \ \ \ Current\ \ \ Average\ \ \ \ \ \ Max\ \ \ 95th\ %\\\\n";
|
||||
$options .= " LINE1.25:inbits#006600:In\ ";
|
||||
$options .= " GPRINT:inbits:LAST:%6.2lf%s";
|
||||
$options .= " GPRINT:inbits:AVERAGE:%6.2lf%s";
|
||||
$options .= " GPRINT:inbits:MAX:%6.2lf%s";
|
||||
$options .= " GPRINT:95thin:%6.2lf%s\\\\n";
|
||||
$options .= " AREA:doutbits#C3D9FF:";
|
||||
$options .= " LINE1.25:doutbits#000099:Out";
|
||||
$options .= " GPRINT:outbits:LAST:%6.2lf%s";
|
||||
$options .= " GPRINT:outbits:AVERAGE:%6.2lf%s";
|
||||
$options .= " GPRINT:outbits:MAX:%6.2lf%s";
|
||||
$options .= " GPRINT:95thout:%6.2lf%s\\\\n";
|
||||
$options .= " GPRINT:tot:Total\ %6.2lf%s";
|
||||
$options .= " GPRINT:totin:\(In\ %6.2lf%s";
|
||||
$options .= " GPRINT:totout:Out\ %6.2lf%s\)\\\\l";
|
||||
$options .= " LINE1:95thin#aa0000";
|
||||
$options .= " LINE1:d95thout#aa0000";
|
||||
$thing = shell_exec($config['rrdtool'] . " graph $imgfile $options");
|
||||
return $imgfile;
|
||||
}
|
||||
|
||||
function graph_mac_acc_interface ($interface, $graph, $from, $to, $width, $height) {
|
||||
global $config, $installdir;
|
||||
$imgfile = $config['install_dir'] . "/graphs/" . "$graph";
|
||||
@@ -762,6 +714,35 @@ function pktsgraph ($rrd, $graph, $from, $to, $width, $height) {
|
||||
return $imgfile;
|
||||
}
|
||||
|
||||
function graph_mac_pkts ($id, $graph, $from, $to, $width, $height) {
|
||||
global $config, $installdir;
|
||||
$imgfile = $config['install_dir'] . "/graphs/" . "$graph";
|
||||
$query = mysql_query("SELECT * FROM `mac_accounting` AS M, `interfaces` AS I, `devices` AS D WHERE M.ma_id = '".$id."' AND I.interface_id = M.interface_id AND I.device_id = D.device_id");
|
||||
$acc = mysql_fetch_array($query);
|
||||
$database = $config['rrd_dir'] ."/". $acc['hostname'] . "/mac-accounting/" . $acc['ifIndex'] . "-" . $acc['mac'] . "-pkts.rrd";
|
||||
$imgfile = $config['install_dir'] . "/graphs/" . "$graph";
|
||||
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height ";
|
||||
$options .= $config['rrdgraph_def_text'];
|
||||
if($height < "99") { $options .= " --only-graph"; unset ($legend); }
|
||||
if($width <= "300") { $options .= " --font LEGEND:7:".$config['mono_font']." --font AXIS:6:".$config['mono_font']." --font-render-mode normal "; }
|
||||
$options .= " DEF:in=$database:IN:AVERAGE";
|
||||
$options .= " DEF:out=$database:OUT:AVERAGE";
|
||||
$options .= " CDEF:dout=out,-1,*";
|
||||
$options .= " AREA:in#aa66aa:";
|
||||
$options .= " COMMENT:Packets\ \ \ \ Current\ \ \ \ \ Average\ \ \ \ \ \ Maximum\\\\n";
|
||||
$options .= " LINE1.25:in#330033:In\ \ ";
|
||||
$options .= " GPRINT:in:LAST:%6.2lf%spps";
|
||||
$options .= " GPRINT:in:AVERAGE:%6.2lf%spps";
|
||||
$options .= " GPRINT:in:MAX:%6.2lf%spps\\\\n";
|
||||
$options .= " AREA:dout#FFDD88:";
|
||||
$options .= " LINE1.25:dout#FF6600:Out\ ";
|
||||
$options .= " GPRINT:out:LAST:%6.2lf%spps";
|
||||
$options .= " GPRINT:out:AVERAGE:%6.2lf%spps";
|
||||
$options .= " GPRINT:out:MAX:%6.2lf%spps\\\\n";
|
||||
$thing = shell_exec($config['rrdtool'] . " graph $imgfile $options");
|
||||
return $imgfile;
|
||||
}
|
||||
|
||||
function errorgraph ($rrd, $graph, $from, $to, $width, $height) {
|
||||
global $config, $installdir;
|
||||
$database = $config['rrd_dir'] . "/" . $rrd;
|
||||
|
@@ -21,22 +21,35 @@
|
||||
$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'] .".output." . $oid;
|
||||
$snmp_cmd .= " cipMacSwitchedPkts.". $acc['ifIndex'] .".input." . $oid;
|
||||
$snmp_cmd .= " cipMacSwitchedPkts.". $acc['ifIndex'] .".output." . $oid;
|
||||
|
||||
$snmp_output = trim(shell_exec($snmp_cmd));
|
||||
|
||||
$snmp_output = preg_replace("[a-zA-Z\ ]", "", $snmp_output);
|
||||
|
||||
list($in,$out) = explode("\n", $snmp_output);
|
||||
list($in,$out,$pktin,$pktout) = explode("\n", $snmp_output);
|
||||
|
||||
$acc_rrd = $config['rrd_dir'] . "/" . $acc['hostname'] . "/mac-accounting";
|
||||
|
||||
if(!is_dir($acc_rrd)) { mkdir($acc_rrd); echo("Created directory : $acc_rrd\n"); }
|
||||
|
||||
$old_rrdfile = $acc_rrd . "/" . $acc['ifIndex'] . "-" . $acc['ip'] . ".rrd";
|
||||
$rrdfile = $acc_rrd . "/" . $acc['ifIndex'] . "-" . $acc['mac'] . ".rrd";
|
||||
|
||||
if(is_file($old_rrdfile) && !is_file($rrdfile)) { rename($old_rrdfile, $rrdfile); echo("Moved $old_rrdfile -> $rrdfile \n"); };
|
||||
$pkts_rrdfile = $acc_rrd . "/" . $acc['ifIndex'] . "-" . $acc['mac'] . "-pkts.rrd";
|
||||
|
||||
if(!is_file($pkts_rrdfile)) {
|
||||
$woo = shell_exec($config['rrdtool'] ." create $pkts_rrdfile \
|
||||
DS:IN:COUNTER:600:0:12500000000 \
|
||||
DS:OUT:COUNTER:600:0:12500000000 \
|
||||
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");
|
||||
}
|
||||
|
||||
if(!is_file($rrdfile)) {
|
||||
$woo = shell_exec($config['rrdtool'] ." create $rrdfile \
|
||||
@@ -55,10 +68,19 @@
|
||||
$woo = "N:".($in+0).":".($out+0);
|
||||
$ret = rrdtool_update("$rrdfile", $woo);
|
||||
|
||||
$rates = interface_rates ($rrdfile);
|
||||
mysql_query("UPDATE `mac_accounting` SET bps_in = '" . $rates['in'] . "', bps_out = '" . $rates['out'] . "' WHERE ma_id= '" . $acc['ma_id'] . "'");
|
||||
$woo = "N:".($pktin+0).":".($pktout+0);
|
||||
$ret = rrdtool_update("$pkts_rrdfile", $woo);
|
||||
|
||||
echo(formatRates($rates['in']) . " in " . formatRates($rates['out']) . " out \n");
|
||||
$rates = interface_rates ($rrdfile);
|
||||
|
||||
$pkt_rates = interface_rates ($pkts_rrdfile);
|
||||
|
||||
$pkt_rate['in'] = round($pkt_rate['in'] / 8);
|
||||
$pkt_rate['out'] = round($pkt_rate['out'] / 8);
|
||||
|
||||
mysql_query("UPDATE `mac_accounting` SET bps_in = '" . $rates['in'] . "', bps_out = '" . $rates['out'] . "', pps_in = '" . $pkt_rates['in'] . "', pps_out = '" . $pkt_rates['out'] . "' WHERE ma_id= '" . $acc['ma_id'] . "'");
|
||||
|
||||
echo(formatRates($rates['in']) . " (" . $pkt_rates['in'] . "pps) in " . formatRates($rates['out']) . " (" . $pkt_rates['out'] . "pps) out \n");
|
||||
|
||||
}
|
||||
?>
|
||||
|
Reference in New Issue
Block a user