CiscoModemsSNMP.pl - Printable Version +- Haxorware Forums (http://www.haxorware.com/forums) +-- Forum: General (http://www.haxorware.com/forums/forumdisplay.php?fid=6) +--- Forum: Modems (http://www.haxorware.com/forums/forumdisplay.php?fid=7) +--- Thread: CiscoModemsSNMP.pl (/showthread.php?tid=3653) |
CiscoModemsSNMP.pl - Canis-Major - 01-07-2015 Just thought I'd add some scipt's I have lying around, maybe they could be integrated into future firmware's Copy into txt and rename to CiscoModemsSNMP.pl #!/usr/local/bin/perl -w # This program uses SNMP to get the number of total, active and registered # modems on each upstream port. Since these are Cisco MIBs, this script # is limited to Cisco CMTS devices. # INPUT: CMTS name # OUTPUT: Modem count table # AUTHOR: Becki True becki@anv.net use Net::SNMP; use strict; my $host = $ARGV[0]; my $comm = ''; # establish SNMP session with host my ($session, $error) = Net::SNMP->session( Hostname => $host, community => $comm, version => 'snmpv2'); if(!defined($session)) { printf("Connection Error: %s.\n", $error); exit 1; } my $total = '1.3.6.1.4.1.9.9.116.1.4.1.1.3'; my $active = '1.3.6.1.4.1.9.9.116.1.4.1.1.4'; my $reg = '1.3.6.1.4.1.9.9.116.1.4.1.1.5'; my $ifDesc = '1.3.6.1.2.1.2.2.1.2'; my %desc; my $desc; my $index; my @index; my $totalmodems; my $activemodems; my $registered; # get ifDesc of upstream ports if (!defined($desc = $session->get_table($ifDesc))) { printf("Get ifDesc error: %s.\n", $session->error()); $session->close(); exit 1; } # sort by upstream name and store indexes in an array foreach my $key(sort hashValueSort(keys(%$desc))) { if($desc->{$key} =~ m/[uU]pstream/) { $index = $key; $index =~ s/$ifDesc.//; push @index, $index; } } # get total modems on each upstream port if (!defined ($totalmodems = $session->get_table($total))) { printf("Get total error: %s.\n", $session->error()); $session->close(); exit 1; } # get active modems on each upstream port if (!defined($activemodems = $session->get_table($active))) { printf("Get active error: %s.\n", $session->error()); $session->close(); exit 1; } # get registered modems on each upstream port if (!defined($registered = $session->get_table($reg))) { printf("Get registered error: %s.\n", $session->error()); $session->close(); exit 1; } # print results print "CMTS: $host\n\n"; print "Upstream port\t\tTotal\tActive\tRegistered\n"; foreach $index (@index) { my $descOID = "$ifDesc.$index"; my $totalOID = "$total.$index"; my $activeOID = "$active.$index"; my $regOID = "$reg.$index"; print "$desc->{$descOID}\t$totalmodems->{$totalOID}\t$activemodems->{$activeOID}\t$registered->{$regOID}\n"; } $session->close(); sub hashValueSort { $desc->{$a} cmp $desc->{$b}; } exit 0; ------------------------------------------- Copy into txt and rename to cat_tftp.pl #! /usr/local/bin/perl -w # This program will use SNMP to initiate a TFTP transfer # of each Cisco device's startup-configuration to the # TFTP server. This program will only work with Cisco # devices using Catalyst OS. There is a seperate program for # IOS devices (ios_tftp.pl). # This program will be run as cron job daily using OpenView's # snmpset and snmpget. It is assumed that /opt/OV/bin is in # your path. If you don't have OpenView you can download and # use the SNMP Perl module from CPAN. # reference http://www.cisco.com/warp/public/477/SNMP/move_files_images_snmp.html # INPUT: file containing names of Cisco Catalyst OS devices - one per line # OUTPUT: device startup-configuration copied to TFTP server # AUTHOR: Becki True becki@anv.net # IMPORTANT: You must provide values for $file, $server, $read, and $write #------------------------------------------------------- $file = ''; # data file containing device names open(FILE, "<$file") or die "Couldn't open $file for reading\n"; while(<FILE>) { chomp $_; push @host, $_; } close FILE; $server = ''; # tftp server IP $tftpGrp = '1.3.6.1.4.1.9.5.1.5'; # base OID $tftpHost = "$tftpGrp.1.0 octetstring $server"; $tftpModule = "$tftpGrp.3.0 integer 1"; # module number to copy config from $tftpAction = "$tftpGrp.4.0 integer 3"; # send config to tftp server $tftpResult = "$tftpGrp.5.0"; # result of the transfer foreach $host(@host) { $read = ''; # SNMP read string $write = ''; # SNMP write string $fileName = "$tftpGrp.2.0 octetstring $host.conf"; # name of file on server # copy file `/opt/OV/bin/snmpset -v 1 -c $write $host $tftpHost $fileName $tftpModule $tftpAction\n`; # wait a few seconds for the transfer - these take a little while sleep 15; # check success of file transfer $success = `/opt/OV/bin/snmpget -v 1 -c $read $host $tftpResult\n`; chomp $success; $success =~ s/.*INTEGER:\s+//; if($success !~ m/successful/) { for (1..3) { # try up to 3 more times to copy file `/opt/OV/bin/snmpset -v 1 -c $write $host $tftpHost $fileName $tftpModule $tftpAction\n`; sleep 15; # check success of file transfer $success = `/opt/OV/bin/snmpget -v 1 -c $read $host $tftpResult\n`; chomp $success; $success =~ s/.*INTEGER:\s+//; if($success =~ m/successful/) { # file copied, so exit for loop last; } } } print "$host: $success\n"; } |