#!/opt/vdops/bin/perl # This script queries Brocade Fibre Channel switches and produces a report, # optionally sending e-mail to interested parties # V Who When What # --------------------------------------------------------------------------- # 1.1.0 skendric 2011-02-21 Upgrade to Netops 1.4.0 # 1.0.2 skendric 2010-12-30 Add @insane to report # 1.0.1 skendric 2010-12-17 Futz with owner/owner_backup # 1.0.0 skendric 2010-05-16 First Version # # # Author: Stuart Kendrick, sbk {put at sign here} skendric {put dot here} com # # Source: http://www.skendric.com/device # # This software is available under the GNU GENERAL PUBLIC LICENSE, see # http://www.fsf.org/licenses/gpl.html # # # This script takes the following approach: # -Parses the hosts table for a list of targets (or accepts a command- # line list) # -Queries a bunch of CISCO-ENVMON-MIB specific variables # -Produces a report # # # Requirements: # -The target(s) must be pingable # # -The following MIB modules stashed in /opt/vdops/share/snmp/mibs, # or wherever it is that you store MIB modules: # CISCO-PRODUCTS-MIB.my # # -PERL modules: the WI::Netops collection # # # Assumptions: # # # Tested on: # -perl-5.12.2 # -net-snmp-5.6 # # # Instructions: # -Customize the script for your site: find the 'user-configurable # variables' section and modify as appropriate # -Try it out # # # Caveats: # # # Known Bugs: # # # To do: # -Add support for SNMPv3 # # Begin script # Load modules use strict; use warnings; use feature 'say'; use feature 'switch'; use Carp qw(carp cluck croak confess); use Data::Dumper; use English qw( -no_match_vars ); use Getopt::Std; use List::MoreUtils qw(first_index); use WI::Netops::CiscoTools 1.4.3; use WI::Netops::HostTools 1.0.4; use WI::Netops::NetopsTools 2.2.3; use WI::Netops::NetopsData 1.4.0; use WI::Netops::PingTools 1.1.7; use WI::Netops::SNMPTools 1.5.3; use WI::Netops::Utilities 1.4.4; # Declare global variables. All hashes keyed by target my %fc_fe_module_oper_status; # fcFeModuleOperStatus my %sw_oper_status; # swOperStatus my %sw_diag_result; # swDiagResult my %sw_flash_dl_oper_status; # swFlashDLOperStatus my %sw_sensor_status; # (worst of all) swSensorStatus my %sw_fc_port_op_status; # (worst of all) swFCPortOpStatus # Define global variables $program_name = 'brocade-alarm'; $usage = 'Usage: brocade-alarm -s {yes|no} [-d {integer}] [-r] [-a | -e {expr} | -f {filename} | target1 target2 target3 ...]'; $version = '1.1.0'; # Grab arguments getopts('ad:e:f:rs:', \%option); @target = @ARGV; # Set mode if ($option{r}) { $mode = 'report' } elsif (-t STDIN) { $mode = 'interactive' } else { $mode = 'batch' } ### Begin Main Program ############################################### { check_args(); # Check arguments read_config(); # Read Netops config file compile_mibs(); # Compile MIB files build_target(); # Populate @target target_check(); # Look for errors in @target basic_info(); # Gather information sanity_check(); # Check for error conditions do_the_work(); # Do it identify_alarms(); # Count devices with alarms write_alarm_log(); # Record issues print_report(); # Print report notify_staff(); # Mail report } ##### End Main Program ################################################# ######################################################################## # Query variables ######################################################################## sub do_the_work { # Debug trace trace_location('begin') if $debug; # Notify operator print_it('Querying targets...'); unless ($dome) { sleep $short; return 1; } # Loop through the list of targets for my $target (@target) { my ($val, $vb); say "Processing $target" if $debug; # Acquire fcFeModuleOperStatus.1 $val = snmpGet( {host => $target, oid => 'fcFeModuleOperStatus.1'} ); $val //= $QUERY; say " fcFeModuleOperStatus.1 = $val" if $debug; unless ($val eq 'online') { log_it("For $target, fcFeModuleOperStatus.1 = $val"); $alarm_count{$target}++; push @{$alarms{$target}}, 'module'; } $fc_fe_module_oper_status{$target} = $val; # Acquire swDiagResult.0 $val = snmpGet( {host => $target, oid => 'swDiagResult.0'} ); $val //= $QUERY; say " swDiagResult.0 = $val" if $debug; given ($val) { when ('sw-ok') { $val = 'ok' } when ('sw-faulty') { $val = 'faulty' } when ('sw-embedded-port-fault') { $val = 'port-fault' } default { $val = $val } } unless ($val eq 'ok') { log_it("For $target, swDiagResult.0 = $val"); $alarm_count{$target}++; push @{$alarms{$target}}, 'hardware status'; } $sw_diag_result{$target} = $val; # Acquire swOperStatus.0 $val = snmpGet( {host => $target, oid => 'swOperStatus.0'} ); $val //= $QUERY; say " swOperStatus.0 = $val" if $debug; unless ($val eq 'online') { log_it("For $target, swOperStatus.0 = $val"); $alarm_count{$target}++; push @{$alarms{$target}}, 'software status'; } $sw_oper_status{$target} = $val; # Acquire swFlashDLOperStatus.0 $val = snmpGet( {host => $target, oid => 'swFlashDLOperStatus.0'} ); $val //= 0; say " swFlashDLOperStatus.0 = $val" if $debug; given ($val) { when ('unknown') { $val = $val } when ('swCurrent') { $val = 'current' } when ('swFwUpgraded') { $val = 'fw-upgraded' } when ('swCfUpLoaded') { $val = 'cf-uploaded' } when ('swCfDownLoaded') { $val = 'cf-dnloaded' } when ('swFwCorrupted') { $val = 'fw-corrupt' } default { $val = $val } } if ($val eq 'fw-corrupt') { log_it("For $target, swOperStatus.0 = $val"); $alarm_count{$target}++; push @{$alarms{$target}}, 'flash'; } $sw_flash_dl_oper_status{$target} = $val; # Walk swSensorStatus $vb = snmpWalk( {host => $target, oid => 'swSensorStatus'} ); for my $varbind (@$vb) { my ($iid, $val); $iid = $varbind->{iid}; $val = $varbind->{val}; $val //= $QUERY; say " swSensorStatus.$iid = $val" if $debug; unless ($val eq 'nominal') { log_it("For $target, swSensorStatus.$iid = $val"); $alarm_count{$target}++; push @{$alarms{$target}}, 'sensor'; $sw_sensor_status{$target} = $val; } } $sw_sensor_status{$target} //= 'nominal'; # Walk swFCPortOpStatus $vb = snmpWalk( {host => $target, oid => 'swFCPortOpStatus'} ); for my $varbind (@$vb) { my ($iid, $val); $iid = $varbind->{iid}; $val = $varbind->{val}; $val //= $QUERY; say " swFCPortOpStatus.$iid = $val" if $debug; if ($val eq 'testing' or $val eq 'faulty') { log_it("For $target, swFCPortOpStatus.$iid = $val"); $alarm_count{$target}++; push @{$alarms{$target}}, 'port'; $sw_fc_port_op_status{$target} = $val; } } $sw_fc_port_op_status{$target} //= 'online'; # Entertain operator print $BANG if $mode eq 'interactive'; } # Debug info if ($debug > 2) { for my $target (@target) { if (defined $alarm_count{$target} and $alarm_count{$target} > 0) { say "alarm_count{$target} = $alarm_count{$target}"; } } } # Make things look pretty say "\n" if $mode eq 'interactive'; # Debug trace trace_location('end') if $debug; return 1; } ######################################################################## # Tell the operator what I discovered ######################################################################## sub print_report { my $handle; my $total = @target; my $now = get_now(); # If we are running in test mode, skip this routine unless ($dome) { print_it("Running in test mode, cannot print a meaningful report\n"); return 1; } # Debug trace trace_location('begin') if $debug; # Direct output to screen or to file if ($mode eq 'interactive') { $handle = *STDOUT; } else { open $handle, '>', $report_file or die "Cannot open $report_file: $!\n"; } print {$handle} <