#!/usr/bin/perl # Copyright (c) 2002, Joshua Coombs # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer # in the documentation and/or other materials provided with the # distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # # # Script to walk through SNMP tree and add up total # active modems on a particular chassis, card or span. # # Created 4-17-01 by Joshua Coombs and Ed Howe # Based on a bash script by Dave C. # # 6-4-01 added ds0 level monitoring when looking # at the span level. # hiperget now polls the nmc for span level info. # # 6-5-01 now logs B channels that appear to be # out of service when their matching D chan is up. # # 6-10-01 now uses ma_snmp module to speed up # polling. # # 2-5-02 now handle and log timeouts for span polling. # # If using E1's vs T1s, change channels to 30 $channels = 23; # Does your TC use old or new stle snmp numbering # (does it number leaving gaps for e1s if using t1s, OLD, # or only allocate mibs for modems present, NEW) # $numscheme = 'NEW'; # Logging method, log, both, or none # (both does mail and log) $logging = 'log'; # email address to mail alerts to $notify = 'noc@network.net'; # Location of B Chan error log $usrlog = '~cricket/cricket-logs/usrflaps'; # Should not need to make any changes below here. $usage = "./hiperget hostname comminuty-string [card-number] [span-number]\n"; # Load the ma_snmp module. use ma_snmp; # Translation of B Channel states from # numric to english. @bchan_state = ('undef', 'other', 'idle', 'dialingIn', 'dialingOut', 'connectedIn', 'connectedOut', 'undef', 'undef', 'undef', 'undef', 'undef', 'undef', 'undef', 'undef', 'undef', 'undef', 'undef', 'undef', 'undef', 'undef', 'undef', 'ds0CallDisc', 'ds0lsDchan', 'ds0OutOfServ', 'ds0InMaint', 'ds0lsFchan', 'ds0LclOutOfService', 'ds0ReceivingBlock', 'ds0LoopBack', 'ds0LclOutOfServiceGWC', 'ds0LclOutOfServiceGWCNMC'); $hostname = $ARGV[0]; $community = $ARGV[1]; $card = $ARGV[2]; $span = $ARGV[3]; if ( !($hostname) || !($community) ) { die ($usage); } if ($ARGV[4] ne "") { die ("Modem level reporting not implimented yet.\n"); } # No card specified. Report stats for the whole chassis, # then exit. if ($card eq "") { $oid_chassis = "1.3.6.1.4.1.429.4.2.1.10.0"; ($inuse) = &ma_snmp::snmpget ($hostname, $community, $oid_chassis); if (@inuse) { print "$inuse\n"; } else { } print "$inuse\n"; exit(0); } # No span specified. Report stats for a card, # then exit. if ($span eq "") { $oid_spaninuse = "1.3.6.1.4.1.429.4.10.35.1.3._SPAN_"; $oid_spaninuse =~ s/_SPAN_/$card/; ($inuse) = &ma_snmp::snmpget ($hostname, $community, $oid_spaninuse); print "$inuse\n"; exit(0); } # Card and Span specified. # Calculate start position in MIB # tree. Initialize all counters used. $targetmib = 1; $dchanmib = 900 + ($card * 1000) + $span; $counterend = $targetmib + $channels; $dchanstat = 0; $inuse = 0; $avail = 0; $dialin = 0; $dialout = 0; $connin = 0; $connout = 0; $temp = 0; my @getoids; my @results; # Convert from using HiperArc to NMC. if ($hostname eq "tc1") { $hostname = "tc1nmc"; } if ($hostname eq "tc2") { $hostname = "tc2nmc"; } if ($hostname eq "tc3") { $hostname = "tc3nmc"; } if ($hostname eq "tc4") { $hostname = "tc4nmc"; } if ($hostname eq "tc5") { $hostname = "tc5nmc"; } if ($hostname eq "tc6") { $hostname = "tc6nmc"; } if ($hostname eq "tc7") { $hostname = "tc7nmc"; } if ($hostname eq "tc8") { $hostname = "tc8nmc"; } if ($hostname eq "tc9") { $hostname = "tc9nmc"; } if ($hostname eq "tc10") { $hostname = "tc10nmc"; } if ($hostname eq "tc11") { $hostname = "tc11nmc"; } if ($hostname eq "tc12") { $hostname = "tc12nmc"; } if ($hostname eq "tc13") { $hostname = "tc13nmc"; } # Report stats on a span. # # Check D Channel status first, if this # is down, don't bother with anything else. $oid_dchanstat = "1.3.6.1.4.1.429.1.27.2.1.4._DCHAN_"; $oid_dchanstat =~ s/_DCHAN_/$dchanmib/; ($temp) = &ma_snmp::snmpget ($hostname, $community, $oid_dchanstat); # See if we got a result back or a timeout/error has # occured, log it and finish. if (!($temp)) { if ($logging eq 'log' or $logging eq 'both') { `date >> $usrlog`; `echo -e $hostname card: $card span: $span Timeout durring snmp probe!\\\\n >> $usrlog`; } if ($logging eq 'both') { `tail -3 $usrlog | mail -s 'BChan Flap Alert' $notify`; } print "0\n0\n0\n0\n0\n0\n0\n"; print "Timeout! probing DChan Status.\n"; exit(1); } if ($temp eq "1") { # D appears to be up, gather stats! Each B channel # is listed as a sub mib off the dchan mib. By # incrimenting through the sub mibs we can get stats # for all channels on a given span. # # $dchanstat is set to the number of channels per # span as this is the estimated number of lines available. # Should this script come across less than this, check # your TC configuration and then call the telco. $oid_bchanstat = "1.3.6.1.4.1.429.1.28.2.1.3._DCHAN_._MIB_"; $dchanstat = $channels; for ($loop_counter = 1; $loop_counter <= $channels; $loop_counter++) { $temp = $oid_bchanstat; $temp =~ s/_DCHAN_/$dchanmib/; $temp =~ s/_MIB_/$loop_counter/; push @getoids, $temp; } @results = &ma_snmp::snmpget ($hostname, $community, @getoids); # See if we got a result back or a timeout/error has # occured, log it and finish. if (!(@results)) { if ($logging eq 'log' or $logging eq 'both') { `date >> $usrlog`; `echo -e $hostname card: $card span: $span Timeout durring snmp probe!\\\\n >> $usrlog`; } if ($logging eq 'both') { `tail -3 $usrlog | mail -s 'BChan Flap Alert' $notify`; } print "0\n0\n0\n0\n0\n0\n0\n"; print "Timeout! probing BChan status.\n"; exit(1); } while ($targetmib != $counterend) { if ($results[$targetmib - 1] eq "2") { $avail = $avail + 1; } elsif ($results[$targetmib - 1] eq "3") { $avail = $avail + 1; $dialin = $dialin +1; $inuse = $inuse + 1; `date >> $usrlog`; `echo -e $hostname card: $card span: $span channel: $temp_channel showed dialin!\\\\n >> $usrlog`; } elsif ($results[$targetmib - 1] eq "4") { $avail = $avail + 1; $dialout = $dialout +1; $inuse = $inuse + 1; `date >> $usrlog`; `echo -e $hostname card: $card span: $span channel: $temp_channel showed dialout!\\\\n >> $usrlog`; } elsif ($results[$targetmib - 1] eq "5") { $avail = $avail + 1; $connin = $connin + 1; $inuse = $inuse + 1; } elsif ($results[$targetmib - 1] eq "6") { $avail = $avail + 1; $connout = $connout + 1; $inuse = $inuse + 1; `date >> $usrlog`; `echo -e $hostname card: $card span: $span channel: $temp_channel showed connout!\\\\n >> $usrlog`; } elsif ($results[$targetmib - 1] eq "22") { $avail = $avail + 1; $inuse = $inuse + 1; } else { # If one of the B channels appears down, check # to see if and how we should log it. if ($logging eq 'log' or $logging eq 'both') { $temp_channel = $targetmib - 1; `date >> $usrlog`; `echo -e $hostname card: $card span: $span channel: $temp_channel listed as $bchan_state[$results[$temp_channel]] \\\\n >> $usrlog`; } if ($logging eq 'both') { `tail -3 $usrlog | mail -s 'BChan Flap Alert' $notify`; } } # Incriment the counter $targetmib = $targetmib + 1; } print "$inuse\n"; print "$dchanstat\n"; print "$avail\n"; print "$dialin\n"; print "$dialout\n"; print "$connin\n"; print "$connout\n"; exit (0); } # D appears down, in which case # no b channels can be active, so just # print 0's. print "0\n0\n0\n0\n0\n0\n0\n";