#!/opt/vdops/bin/perl # This script queries Liebert MIBs and produces a report, notfiying operators # of any alarms # 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-02-01 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 2009-02-06 Convert $report_recipient into a list # 1.0.3 skendric 2008-01-02 Count only lgpConditionsPresent.0 as alarms # 1.0.0 skendric 2008-04-11 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 Liebert 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: # LIEBERT-GP-REGISTRATION-MIB, LIEBERT-GP-ENVIRONMENTAL-MIB, # LIEBERT-GP-SYSTEM-MIB, LIEBERT-GP-CONDITIONS-MIB # # -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::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 %conditions; # Number of alarm conditions my %cooling_state; # State of cooling my %dehumidifying_state; # State of dehumidifying my %econo_state; # State of econo cycle my %heating_state; # State of heating my %humidity_lockout; # State of HumLockout my %humidifying_state; # State of humidifying my %reheat_lockout; # State of ReheatLockout my %system_state; # State of system my @silent; # Targets which did not answer pings my @unresponsive; # Targets which did not answer SNMP GETs # Define global variables $program_name = 'liebert-alarm'; $usage = 'Usage: liebert-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 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 { my %arg; # 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 ($num, $val); say "Processing $target" if $debug; # System state $val = snmpGet( {host => $target, oid => 'lgpEnvStateSystem.0'} ); $val //= $QUERY; log_it("$target lgEnvStateSystem is $val"); $system_state{$target} = $val; # Cooling state say 'Getting lgpEnvStateCooling.0' if $debug > 3; $val = snmpGet( {host => $target, oid => 'lgpEnvStateCooling.0'} ); $val //= $QUERY; log_it("$target lgEnvStateCooling is $val"); $cooling_state{$target} = $val; # Heating state say 'Getting lgpEnvStateHeating.0' if $debug > 3; $val = snmpGet( {host => $target, oid => 'lgpEnvStateHeating.0'} ); log_it("$target lgEnvStateHeating is $val"); $heating_state{$target} = $val; # Humidifying state $val = snmpGet( {host => $target, oid => 'lgpEnvStateHumidifying.0'} ); $val //= $QUERY; log_it("$target lgEnvStateHumidifying is $val"); $humidifying_state{$target} = $val; # Dehumidifying state $val = snmpGet( {host => $target, oid => 'lgpEnvStateHumidifying.0'} ); $val //= $QUERY; log_it("$target lgEnvStateDehumidifying is $val"); $dehumidifying_state{$target} = $val; # Econo state $val = snmpGet( {host => $target, oid => 'lgpEnvStateEconoCycle.0'} ); $val //= $QUERY; log_it("$target lgpEnvStateEconoCycle is $val"); $econo_state{$target} = $val; # Reheat Lockout $val = snmpGet( {host => $target, oid => 'lgpEnvConfigReheatLockout.0'} ); $val //= $QUERY; given ($val) { when ('lockedOut') { $val = 'locked' } when ('notLockedOut') { $val = 'open' } } log_it("$target lgEnvConfigReheatLockout is $val"); $reheat_lockout{$target} = $val; # Humdifier Lockout $val = snmpGet( {host => $target, oid => 'lgpEnvConfigHumLockout.0'} ); $val //= $QUERY; given ($val) { when ('lockedOut') { $val = 'locked' } when ('notLockedOut') { $val = 'open' } } log_it("$target lgEnvConfigHumLockout is $val"); $humidity_lockout{$target} = $val; # Number of conditions $val = snmpGet( {host => $target, oid => 'lgpConditionsPresent.0'} ); $val //= $QUERY; $conditions{$target} = $val; log_it("$target lgpConditionsPresent is $conditions{$target}"); $alarm_count{$target}++ unless $conditions{$target} == 0; # Description of alarms if ($conditions{$target} > 0) { # Walk lgpConditionsTable and figure what is broken } # 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} <