From 217d4a932a71ccbe5b3d9897e3acb74d9034ed92 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Tue, 1 Oct 2013 11:12:35 +0200 Subject: [PATCH] Add simple scripts to monitor HP Smart Arrays (requires hpacucli) --- zabbix_conf/raid_hp.conf | 17 ++++++++ zabbix_scripts/check_raid_hp_sudo | 81 +++++++++++++++++++++++++++++++++++++++ zabbix_scripts/disco_raid_hp_sudo | 30 +++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 zabbix_conf/raid_hp.conf create mode 100644 zabbix_scripts/check_raid_hp_sudo create mode 100644 zabbix_scripts/disco_raid_hp_sudo diff --git a/zabbix_conf/raid_hp.conf b/zabbix_conf/raid_hp.conf new file mode 100644 index 0000000..31facb8 --- /dev/null +++ b/zabbix_conf/raid_hp.conf @@ -0,0 +1,17 @@ +# Description: HP Smart Array status +# Type: Agent or Agent (active) +# Key: raid.hp.status +# Type of Information: Character +# Show Value: As is + +# The value reported is like: +# OK +# If an error is found, the output will be: +# CRITICAL: + +# You can add a simple trigger on this check like: +# { hostname:raid.hp.status.str( OK ) }=0 +UserParameter=raid.hp.status[*],/usr/bin/sudo /var/lib/zabbix/bin/check_raid_hp_sudo --slot=$1 + +# This is a discovery rule to find which slot are used +UserParameter=raid.hp.discovery,/usr/bin/sudo /var/lib/zabbix/bin/disco_raid_hp_sudo diff --git a/zabbix_scripts/check_raid_hp_sudo b/zabbix_scripts/check_raid_hp_sudo new file mode 100644 index 0000000..a013814 --- /dev/null +++ b/zabbix_scripts/check_raid_hp_sudo @@ -0,0 +1,81 @@ +#!/usr/bin/perl -w + +use strict; +use Getopt::Long; + +my $slot = ''; +my $hpacucli = '/usr/sbin/hpacucli'; +my @validchecks = qw/controller array logicaldrive physicaldrive/; +my $check = join ',', @validchecks; + +GetOptions ('slot=s' => \$slot, + 'check=s' => \$check, + 'help' => sub { &usage() } +); + +sub usage(){ + print <<"EOF"; +$0 --slot= --check= + + * slot must be a number. You can find on which slot you have controllers with the command: + +$hpacucli controller all show status + + * check is a comma separated list of item to check. Default values (without --check option) will check everything + Valid values are: + +EOF + + print "$_\n" foreach (@validchecks); + exit(0); +} + +if ($slot !~ /^\d+$/){ + usage(); +} + +unless (-x $hpacucli){ + die "Cannot run $hpacucli\n"; +} + +my @checks = split /\s?,\s?/, $check; +foreach my $check (@checks){ + usage() unless (grep { $_ eq $check} @validchecks); +} + +foreach my $param (@checks){ + # Global controller checks + if ($param eq 'controller'){ + open HPACUCLI, "$hpacucli controller slot=$slot show status|" || + die "An error occured while running $hpacucli: $!"; + foreach my $line (){ + if ( $line =~ /Status\:\s*([\w\s]+)$/ ) { + my $res = $1; + chomp($res); + if ($res ne 'OK'){ + print "CRITICAL: $line\n"; + exit(0); + } + } + } + close HPACUCLI; + } + else{ + open HPACUCLI, "$hpacucli controller slot=$slot $param all show status|" || + die "An error occured while running $hpacucli: $!"; + foreach my $line (){ + if ( $line =~ /^\s*$param.*:\s*(\w+[\w\s]*)$/i ) { + my $res = $1; + chomp($res); + if ($res ne 'OK'){ + print "CRITICAL: $line\n"; + exit(0); + } + } + } + close HPACUCLI; + } +} + +print 'OK'; +exit(0); diff --git a/zabbix_scripts/disco_raid_hp_sudo b/zabbix_scripts/disco_raid_hp_sudo new file mode 100644 index 0000000..9335bc5 --- /dev/null +++ b/zabbix_scripts/disco_raid_hp_sudo @@ -0,0 +1,30 @@ +#!/usr/bin/perl -w + +use strict; +use JSON; + +my $json; +@{$json->{data}} = (); + +my $hpacucli = '/usr/sbin/hpacucli'; + +# the hpacucli utility is needed +unless (-x $hpacucli){ + print to_json($json); + exit(0); +} + +open( HPACUCLI, "$hpacucli controller all show status|" ) + or die "An error occured while running $hpacucli: $!"; + +foreach my $line (){ + if ( $line =~ m/Another instance of hpacucli is running! Stop it first\./i ){ + die "Another instance of hpacucli is running\n"; + } + elsif ( $line =~ m/(.*) in Slot (\d+)/i ) { + push @{$json->{data}}, {"#MODEL" => $1, "#SLOT" => $2}; + } +} +close HPACUCLI; +print to_json($json); +exit(0);