mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
mac accounting updates
git-svn-id: http://www.observium.org/svn/observer/trunk@425 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
#!/usr/bin/php
|
||||
<?
|
||||
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
ini_set('log_errors', 1);
|
||||
ini_set('error_reporting', E_ALL);
|
||||
|
||||
|
||||
include("config.php");
|
||||
include("includes/functions.php");
|
||||
include("includes/cdp.inc.php");
|
||||
|
||||
$start = utime();
|
||||
|
||||
### Observer Device Discovery
|
||||
|
||||
echo("Observer v".$config['version']." MAC Accounting Discovery\n\n");
|
||||
|
||||
mysql_query("DELETE FROM mac_accounting WHERE 1");
|
||||
|
||||
$data = trim(`cat mac-accounting.txt`);
|
||||
|
||||
foreach( explode("\n", $data) as $peer_entry) {
|
||||
list($interface_ip, $peer_ip, $peer_desc, $peer_asn, $peer_mac, $in_oid, $out_oid) = explode(",", $peer_entry);
|
||||
$interface_id = mysql_result(mysql_query("SELECT interface_id FROM ipv4_addresses WHERE ipv4_address = '$interface_ip'"),0);
|
||||
$device_id = mysql_result(mysql_query("SELECT device_id FROM interfaces WHERE interface_id = '$interface_id'"),0);
|
||||
|
||||
echo("PEER : $peer_ip AS$peer_asn ($peer_mac) int: $interface_id host: $device_id \n");
|
||||
|
||||
mysql_query("INSERT INTO `mac_accounting` (interface_id, peer_ip, peer_desc, peer_asn, peer_mac, in_oid, out_oid) VALUES ('$interface_id','$peer_ip','$peer_desc','$peer_asn','$peer_mac','$in_oid','$out_oid')");
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
@@ -1,163 +0,0 @@
|
||||
#! /usr/bin/perl
|
||||
# $Id: bgp-peers.pl,v 1.5 2001/08/06 14:45:55 lwa Exp $
|
||||
|
||||
# $Log: bgp-peers.pl,v $
|
||||
# Revision 1.5 2001/08/06 14:45:55 lwa
|
||||
# add help
|
||||
#
|
||||
# Revision 1.4 2001/08/03 19:03:22 lwa
|
||||
# display hardware mac address (in Cisco format)
|
||||
#
|
||||
#
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
bgp-peers.pl - generate MRTG configuration for BGP peering point
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
./bgp-peers.pl <your IP on the exchange point> <its snmp comunity>
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This program generates a MRTG configuration file for graphing traffic
|
||||
to and from all peers present on a Cisco NAP, using
|
||||
mac-accounting. Tested with Cisco 720x and Cisco 750x.
|
||||
|
||||
You can then use indexmaker (from mrtg distribution) to generate a cool index
|
||||
and run the whole stuff from a cronjob.
|
||||
|
||||
|
||||
=head2 CISCO CONFIGURATION
|
||||
|
||||
Enable mac-accounting on NAP interface (see the example below)
|
||||
|
||||
=over 4
|
||||
|
||||
Router# conf t
|
||||
Router(config)# interface FastEthernet2/0
|
||||
Router(config-if)# ip accounting mac-address input
|
||||
Router(config-if)# ip accounting mac-address output
|
||||
Router(config-if)#exit
|
||||
Router(config)#exit
|
||||
|
||||
=back
|
||||
|
||||
=head1 BUGS
|
||||
|
||||
The only problem I have noticed is when your are not getting any data
|
||||
from a peer (IN or OUT) the variable wont be in the SNMP tree and
|
||||
MRTG will complain. If its occurs during long time, this probably mean
|
||||
you have a problem with your peer because you are expected to make
|
||||
some traffic with it (at least, BGP traffic).
|
||||
|
||||
If the peer change its hardware address, you have to re-run
|
||||
this program to take the modification.
|
||||
|
||||
=head1 THANKS
|
||||
|
||||
Thanks to groups.google.com for the tricks : http://groups.google.com/groups?q=this_mac&hl=en&safe=off&rnum=1&ic=1&selm=91750329.28451%40news.Colorado.EDU
|
||||
|
||||
Thanks to Robert Kiessling from Easynet Germany to have irritated us.
|
||||
|
||||
=head1 AUTHORS
|
||||
|
||||
Erwan Lerale <erwan@de.clara.net>
|
||||
Arnaud le Taillanter <alt@fr.clara.net>
|
||||
Laurent Wacrenier <lwa@teaser.fr>
|
||||
|
||||
=cut
|
||||
|
||||
use SNMP_Session;
|
||||
use SNMP_util;
|
||||
use BER;
|
||||
use Socket;
|
||||
|
||||
my $hostname = shift;
|
||||
my $community = shift;
|
||||
my %interface;
|
||||
$interface{ip} = shift;
|
||||
|
||||
if ($hostname !~ /^\d+\.\d+\.\d+\.\d+$/) {
|
||||
print STDERR
|
||||
"usage: $0 router community interface_ip \n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
$community = "public" unless defined $community;
|
||||
|
||||
my %OIDS = (
|
||||
ipNetToMediaPhysAddress => "1.3.6.1.2.1.4.22.1.2",
|
||||
bgpPeerState => "1.3.6.1.2.1.15.3.1.2",
|
||||
bgpPeerRemoteAs => "1.3.6.1.2.1.15.3.1.9",
|
||||
bgpPeerRemoteAddr => "1.3.6.1.2.1.15.3.1.7",
|
||||
bgpPeerLocalAddr => "1.3.6.1.2.1.15.3.1.5",
|
||||
cipMacSwitchedBytes => "1.3.6.1.4.1.9.9.84.1.2.1.1.4",
|
||||
);
|
||||
|
||||
my %peers;
|
||||
|
||||
($interface{index}) = snmpget("$community\@$hostname",
|
||||
"ipAdEntIfIndex.$interface{ip}");
|
||||
|
||||
($interface{speed}) = snmpget("$community\@$hostname",
|
||||
"ifSpeed.$interface{index}");
|
||||
$interface{speed}/=8;
|
||||
|
||||
|
||||
my $session = SNMP_Session->open ($hostname, $community, 161)
|
||||
or die "Couldn't open SNMP session to $hostname";
|
||||
|
||||
$session->map_table([ [split /\./, $OIDS{bgpPeerRemoteAddr}],
|
||||
[split /\./, $OIDS{bgpPeerRemoteAs}],
|
||||
[split /\./, $OIDS{bgpPeerState}],
|
||||
[split /\./, $OIDS{bgpPeerLocalAddr}],
|
||||
], \&getpeers);
|
||||
|
||||
sub getpeers {
|
||||
my ($index, $RemoteAddr, $RemoteAs, $State, $LocalAddr) = @_;
|
||||
my $pLocalAddr = pretty_print($LocalAddr);
|
||||
return if $pLocalAddr ne $interface{ip};
|
||||
|
||||
my ($PhysAddress) = snmpget("$community\@$hostname",
|
||||
"ipNetToMediaPhysAddress.$interface{index}.$index");
|
||||
|
||||
$peer{$index} = {
|
||||
RemoteAs => pretty_print($RemoteAs),
|
||||
PhysAddress => join(".", unpack("C*", $PhysAddress)),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
for my $peer (sort keys %peer) {
|
||||
my $name = gethostbyaddr(inet_aton($peer), AF_INET) || $peer;
|
||||
my $mac = sprintf "%02x%02x.%02x%02x.%02x%02x",
|
||||
split(/\./, $peer{$peer}->{PhysAddress});
|
||||
|
||||
# print <<EOF;
|
||||
#Target[$peer]: $OIDS{cipMacSwitchedBytes}.$interface{index}.1.$peer{$peer}->{PhysAddress}\&$OIDS{cipMacSwitchedBytes}.$interface{index}.2.$peer{$peer}->{PhysAddress}:$community\@$interface{ip}
|
||||
#MaxBytes[$peer]: $interface{speed}
|
||||
#Options[$peer]: bits, growright
|
||||
#ShortLegend[$peer]: bps
|
||||
#Title[$peer]: MAC traffic for <tt>$name</tt> (AS$peer{$peer}->{RemoteAs})
|
||||
#PageTop[$peer]: <H1>MAC traffic for <tt>$name</tt> (AS$peer{$peer}->{RemoteAs})
|
||||
# </H1>
|
||||
# <TABLE>
|
||||
# <TR><TD>Peer Name:</TD><TD><tt>$name</tt></TD></TR>
|
||||
# <TR><TD>IP address:</TD><TD><tt>$peer</tt></TD></TR>
|
||||
# <TR><TD>Mac address:</TD><TD><tt>$mac</tt></TD></TR>
|
||||
# <TR><TD>Peer AS:</TD><TD><tt>$peer{$peer}->{RemoteAs}</tt></TD></TR>
|
||||
# </TABLE>
|
||||
#
|
||||
#EOF
|
||||
|
||||
print <<EOF;
|
||||
$interface{ip},$peer,$name,$peer{$peer}->{RemoteAs},$mac,$OIDS{cipMacSwitchedBytes}.$interface{index}.1.$peer{$peer}->{PhysAddress},$OIDS{cipMacSwitchedBytes}.$interface{index}.2.$peer{$peer}->{PhysAddress},$community
|
||||
EOF
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@@ -1,2 +0,0 @@
|
||||
./mac-accounting.pl <router> planning <interface-ip> > mac-accounting.txt
|
||||
./mac-accounting.pl <router> planning <interface-ip> >> mac-accounting.txt
|
@@ -11,9 +11,6 @@ mysql_query("DELETE FROM `syslog` WHERE `processed` = '0' AND `msg` LIKE '%PM-3-
|
||||
mysql_query("DELETE FROM `syslog` WHERE `processed` = '0' AND `msg` LIKE '%RHWatchdog%'");
|
||||
mysql_query("DELETE FROM `syslog` WHERE `processed` = '0' AND `msg` LIKE '%Hardware Monitoring%'");
|
||||
|
||||
|
||||
|
||||
|
||||
if(!$config['enable_syslog']) {
|
||||
echo("Syslog support disabled.\n");
|
||||
exit();
|
||||
|
Reference in New Issue
Block a user