Cisco mac address table size

In my previous Cacti install, I wrote a script that would give me the mac address table size, could this be adapted to LibreNMS?

#!/usr/bin/perl

use Getopt::Long;

$snmpbulkwalk           = '/usr/bin/snmpbulkwalk';

# Change this to 1 for per vlan mac count or use -d on the CLI
$debug                  = 0;

check_options();

sub check_options{
        Getopt::Long::Configure ("bundling");
        GetOptions(
                'd'     => \$o_debug,           'debug'         => \$o_debug,
                'h'     => \$o_help,            'help'          => \$o_help,
                'i:s'   => \$o_ipaddress,       'ipaddress:s'   => \$o_ipaddress,
                'c:s'   => \$o_community,       'community:s'   => \$o_community,
                'C'     => \$o_cacti,           'cacti'         => \$o_cacti,
                'I'     => \$o_icinga,          'icinga'        => \$o_icinga,
                                                'warning:s'     => \$o_icinga_warning,
                                                'critical:s'    => \$o_icinga_critical
        );

        if (defined ($o_help)) {
                help();
                exit 0;
        }

        if (! defined ($o_ipaddress)) {
                print "\nError: no IP Address has been provided\n\n";
                help();
                exit -1;
        }
}

if ($o_debug) {
        $debug = 1;
}

sub help {
        print_usage();
        exit 0;
}

sub print_usage{
print <<EOT;
----------------------------------------

-d, --debug             Debug output
-h, --help              This help
-i, --ipaddress         IP Address to check
-c, --community         SNMP Community
-C, --cacti             Cacti Output
-I, --icinga            Icinga Output
----------------------------------------
For Icinga

--warning               Warning Level
--critical              Critical Level
----------------------------------------
EOT
}

@switchvlans    = `$snmpbulkwalk -v 2c -c $o_community -OXsq $o_ipaddress .1.3.6.1.4.1.9.9.46.1.3.1.1.2`;

foreach my $line (@switchvlans) {
        $line   =~ s/enterprises.9.9.46.1.3.1.1.2.1.//g;
        $line   =~ s/ 1//g;
}

my $total_mac_count = 0;

while (@switchvlans) {
        my $vlan = shift(@switchvlans);

        chomp($vlan);

        if ($vlan >= 1002 && $vlan <= 1005 ){
        } else {
                $mac_count = 0;
                $mac_count = `snmpbulkwalk -c $o_community\@$vlan -v2c -OXsq $o_ipaddress .1.3.6.1.2.1.17.4.3.1.2 | wc -l`;
                if ($debug == 1) {
                        print "Vlan $vlan: $mac_count";
                }
                $total_mac_count = $total_mac_count + $mac_count;
        }
}

if ($o_icinga){
        if ($o_icinga_warning || $o_icinga_critical) {
                if ($o_icinga_critical && $total_mac_count > $o_icinga_critical) {
                        print "MAC CRITICAL: $total_mac_count Addresses|mac=$total_mac_count;\n";
                } elsif ($o_icinga_warning && $total_mac_count > $o_icinga_warning) {
                        print "MAC WARNING: $total_mac_count Addresses|mac=$total_mac_count;\n";
                } else {
                        print "MAC OK: $total_mac_count Addresses|mac=$total_mac_count;\n";
                }
        } else {
                $o_icinga_warning = 0;
                $o_icinga_critical = 0;
                print "MAC OK: $total_mac_count Addresses|mac=$total_mac_count;\n";
        }
} elsif ($o_cacti){
        print "mac:$total_mac_count\n";
} else {
        print "Total: $total_mac_count\n";
}

exit 0

We already show the MAC entries on many devices, so right now you could go to the device, view the FDB table, and see how many entries there are. Otherwise we could do this elsewhere and just display the number of entries, I’m not sure where a good place would be, maybe on the device overview page?

Ok that’s good that the table size is there, could it be possible to graph it? In our environment MAC address graphs have been important on some aggregate switches as we sometimes get close to filling up the MAC table and we all know what happens when that table gets full… Poof, all ports flooded!

3 Likes