#!/opt/vdops/bin/perl # This script queries status variables in BLUEARC-SERVER-MIB and # produces a report identifying salient issues. # V Who When What # --------------------------------------------------------------------------- # 1.2.0 skendric 2011-02-21 Upgrade to Netops 1.4.0 # 1.1.2 skendric 2010-12-30 Add @insane to report # 1.1.1 skendric 2010-12-17 Futz with owner/owner_backup # 1.1.0 skendric 2010-01-10 Upgrade to perl 5.10.1 # 1.0.6 skendric 2009-04-19 Distinguish between silent and unresponsive # 1.0.5 skendric 2009-03-20 Add @down_for_maintenance # 1.0.4 skendric 2007-12-07 Add owner # 1.0.3 skendric 2007-06-07 Add clusterQuorumDeviceStatus # 1.0.2 skendric 2007-03-21 Stylistic mods # 1.0.1 skendric 2007-02-09 Add logging, separate storage into components # 1.0.0 skendric 2007-01-23 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 BlueArc-specific variables # -Produces a report # # # Requirements: # -The target(s) must be pingable # # -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 # -Type "bluearc-alarm" to see the command-line options # -Try it out # # # # Caveats: # # # Known Bugs: # # # To do: # # 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(uniq); 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 my %nic; # ifOperStatus my %temperature; # temperatureSensorStatus my %fan; # fanFittedStatus + fanSpeedStatus my %power; # psuStatus my %clusterQuorum; # clusterQuorumDeviceStatus my %clusterVNode; # clusterVNodeStatus my %sysDrive; # sysDriveStatus my %volume; # volumeStatus # Define global variables $program_name = 'bluearc-alarm'; $usage = 'Usage: bluearc-alarm -s {yes|no} [-d {integer}] [-r] [-a | -e {expr} | -f {filename} | target1 target2 target3 ...]'; $version = '1.2.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 major errors do_the_work(); # Do the work identify_alarms(); # Count devices with alarms write_alarm_log(); # Record issues print_report(); # Print report notify_staff(); # Mail report } ##### End Main Program ############################################### ######################################################################## # Do the work ######################################################################## sub do_the_work { my $answer; my $val; # Result of snmpGet/Walk # Debug trace trace_location('begin') if $debug; # Notify operator print_it('Querying targets...'); unless ($dome) { sleep $short; return 1; } # Loop through targets TARGET: for my $target (@target) { my ($iid, $val); # Walk ifOperStatus $val = snmpWalk( {host => $target, oid => 'ifOperStatus'} ); $answer = 'ok'; for my $varbind (@$val) { $iid = $varbind->{iid}; $val = $varbind->{val}; $answer = 'bad' unless $val eq 'up'; } unless ($answer eq 'ok') { log_it("$target ifOperStatus.$iid = $val"); $alarm_count{$target}++; push @{$alarms{$target}}, 'NIC'; } $nic{$target} = $answer; # Walk temperatureSensorStatus $val = snmpWalk( {host => $target, oid => 'temperatureSensorStatus'} ); $answer = 'ok'; for my $varbind (@$val) { $iid = $varbind->{iid}; $val = $varbind->{val}; $answer = 'bad' unless $val eq 'ok'; } unless ($answer eq 'ok') { log_it("$target temperatureSensorStatus.$iid = $val"); $alarm_count{$target}++; push @{$alarms{$target}}, 'temp'; } $temperature{$target} = $answer; # Walk fanFittedStatus $val = snmpWalk( {host => $target, oid => 'fanFittedStatus'} ); $answer = 'ok'; for my $varbind (@$val) { $iid = $varbind->{iid}; $val = $varbind->{val}; $answer = 'bad' unless $val eq 'ok'; } unless ($answer eq 'ok') { log_it("$target fanFittedStatus.$iid = $val"); $alarm_count{$target}++; push @{$alarms{$target}}, 'fan'; } $fan{$target} = $answer; # Walk fanSpeedStatus unless ($fan{$target} eq 'bad') { $val = snmpWalk( {host => $target, oid => 'fanSpeedStatus'} ); $answer = 'ok'; for my $varbind (@$val) { $iid = $varbind->{iid}; $val = $varbind->{val}; $answer = 'bad' unless $val eq 'ok'; } unless ($answer eq 'ok') { log_it("$target fanSpeedStatus.$iid = $val"); $alarm_count{$target}++; push @{$alarms{$target}}, 'fan'; } $fan{$target} = $answer; } # Walk psuStatus $val = snmpWalk( {host => $target, oid => 'psuStatus'} ); $answer = 'ok'; for my $varbind (@$val) { $iid = $varbind->{iid}; $val = $varbind->{val}; $answer = 'bad' unless $val eq 'ok'; } unless ($answer eq 'ok') { log_it("$target psuStatus.$iid = $val"); $alarm_count{$target}++; push @{$alarms{$target}}, 'PS'; } $power{$target} = $answer; # Walk clusterVNodeStatus $val = snmpWalk( {host => $target, oid => 'clusterVNodeStatus'} ); $answer = 'ok'; for my $varbind (@$val) { $iid = $varbind->{iid}; $val = $varbind->{val}; $answer = 'bad' unless $val eq 'onLine'; } unless ($answer eq 'ok') { log_it("$target clusterVNodeStatus.$iid = $val"); $alarm_count{$target}++; push @{$alarms{$target}}, 'VNode status'; } $clusterVNode{$target} = $answer; # Get clusterQuorumDeviceStatus $val = snmpGet( {host => $target, oid => 'clusterQuorumDeviceStatus.0'} ); given ($val) { when ('owned') { $answer = 'ok' } default { $answer = 'bad' } } unless ($answer eq 'ok') { log_it("$target clusterQuorumDeviceStatus.$iid = $val"); $alarm_count{$target}++; push @{$alarms{$target}}, 'Quorum status'; } $clusterQuorum{$target} = $answer; # Walk sysDriveStatus $val = snmpWalk( {host => $target, oid => 'sysDriveStatus'} ); $answer = 'ok'; for my $varbind (@$val) { $iid = $varbind->{iid}; $val = $varbind->{val}; $answer = 'bad' unless $val eq 'online'; } unless ($answer eq 'ok') { log_it("$target sysDriveStatus.$iid = $val"); $alarm_count{$target}++; push @{$alarms{$target}}, 'Quorum status'; } $sysDrive{$target} = $answer; # Walk volumeStatus $val = snmpWalk( {host => $target, oid => 'volumeStatus'} ); $answer = 'ok'; for my $varbind (@$val) { $iid = $varbind->{iid}; $val = $varbind->{val}; $answer = 'bad' unless $val eq 'mounted'; } unless ($answer eq 'ok') { log_it("$target volumeStatus.$iid = $val"); $alarm_count{$target}++; push @{$alarms{$target}}, 'Volume status'; } $volume{$target} = $answer; # Entertain operator print $BANG if $mode eq 'interactive'; } # Debug info if ($debug > 2) { for my $target (@target) { if ($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} <