#!/usr/bin/perl -w # # NAGIOS Plugin: check_3ware # Check the status of the 3ware raid controler with tw_cli # Author: Marius Hein # NETWAYS GmbH, www.netways.de, info@netways.de # # Additions by Ianaré Sévi : # SSH addon-on, newer style report, more keywords # # Mauled by John Jore, john@jore.no # Stripped down and changed to BBU testing. Ugly hack by someone who can't write in perl. # Will check battery status and temp, the most severe status will "win", both status descriptions are included in output. # # Feel free to fix re-post to the nagios exchange use strict; use File::Basename; use Getopt::Long; use vars qw( $opt_control $opt_help $opt_usage $progname $return $command %conf $tmp1 $tmp2 $state_out $state_out1 $state_out2 $desc_out1 $desc_out2 $exit_out $exit_out1 $exit_out2 $stat @state_ok @state_warning @state_critical ); sub print_help(); sub print_usage(); $progname = basename($0); @state_ok=("OK", "Testing"); @state_warning=("Weak Battery", "Charging"); @state_critical=("Not Present", "No Battery", "Fault", "Error", "Failed Battery"); $conf{'bin'} = "tw_cli"; $conf{'fullbin'} = "/usr/sbin/$conf{'bin'}"; $conf{'cmd_part_last_temp'} = "show temp"; $conf{'cmd_part_last_status'} = "show status"; Getopt::Long::Configure('bundling'); GetOptions ( "controller=s" => \$opt_control, "C=s" => \$opt_control, "h" => \$opt_help, "help" => \$opt_help, "usage" => \$opt_usage ) || die "try '$progname --help' for informations.\n"; if (!$opt_control) { $opt_control=0; } sub print_help() { print "\n"; print "check 3ware >>HELP<<\n"; print "\n"; print "\t --help, -h\t\t\t help screen.\n"; print "\t --usage\t\t\t little usage\n"; print "\n"; print "\t --controller, -C\t\t Controller ID\n"; print "\n"; } sub print_usage() { print "\n"; print "check 3ware >>USAGE<<\n"; print "\n"; print "\t$progname -C 0 (checks Controller 0's BBU for status)\n"; print "\t$progname --help (Displays the Helpmessage)\n"; print "\n"; } if ($opt_help) { print_help(); exit; } if ($opt_usage) { print_usage(); exit; } #Temp if ($opt_control >= 0) { #Get BBU Temp $command = "sudo ".$conf{'fullbin'}." /c$opt_control/bbu ".$conf{'cmd_part_last_temp'}; #print "$command\n"; $return = qx ( $command ); #print $return; # newer style report if ($return =~ /=/){ ($tmp1,$tmp2) = split(/= /,$return); $tmp2 =~ s/\s+$//; $stat = $tmp2; } # older style else { ($tmp1,$tmp2) = split(/\s.*?/,$return); $stat = $tmp1; } #print "tmp1: '$tmp1'\n"; #print "tmp2: '$tmp2'\n"; #print "Stat: '$stat'\n"; foreach (@state_ok) { if ($stat eq $_) { $state_out1 = "OK"; $desc_out1 = "BBU on Controller $opt_control is $stat"; $exit_out1 = 0; } } if (!$state_out1) { foreach (@state_warning) { if ($stat eq $_) { $state_out1 = "WARNING"; $desc_out1 = "BBU on Controller $opt_control is $stat"; $exit_out1 = 1; } } } if (!$state_out1) { foreach (@state_critical) { if ($stat eq $_) { $state_out1 = "CRITICAL"; $desc_out1 = "BBU on Controller $opt_control is $stat"; $exit_out1 = 2; } } } if (!$state_out1) { $state_out1 = "UNKNOWN"; $desc_out1 = "BBU on Controller $opt_control is $stat"; $exit_out1 = 3; } #print "$progname: $state_out1 ($desc_out1)\n"; # exit $exit_out1; } #Status if ($opt_control >= 0) { #Get BBU Status $command = "sudo ".$conf{'fullbin'}." /c$opt_control/bbu ".$conf{'cmd_part_last_status'}; #print "$command\n"; $return = qx ( $command ); #print $return; # newer style report if ($return =~ /=/){ ($tmp1,$tmp2) = split(/= /,$return); $tmp2 =~ s/\s+$//; $stat = $tmp2; } # older style else { ($tmp1,$tmp2) = split(/\s.*?/,$return); $stat = $tmp1; } #print "tmp1: '$tmp1'\n"; #print "tmp2: '$tmp2'\n"; #print "Stat: '$stat'\n"; foreach (@state_ok) { if ($stat eq $_) { $state_out2 = "OK"; $desc_out2 = "BBU on Controller $opt_control is $stat"; $exit_out2 = 0; } } if (!$state_out2) { foreach (@state_warning) { if ($stat eq $_) { $state_out2 = "WARNING"; $desc_out2 = "BBU on Controller $opt_control is $stat"; $exit_out2 = 1; } } } if (!$state_out2) { foreach (@state_critical) { if ($stat eq $_) { $state_out2 = "CRITICAL"; $desc_out2 = "BBU on Controller $opt_control is $stat"; $exit_out2 = 2; } } } if (!$state_out2) { $state_out2 = "UNKNOWN"; $desc_out2 = "BBU on Controller $opt_control is $stat"; $exit_out2 = 3; } #print "$progname: $state_out2 ($desc_out2)\n"; #exit $exit_out2; } else { print_help(); exit; } #Which is the most severe exit status? if ($exit_out1 > $exit_out2) { $exit_out = $exit_out1; $state_out = $state_out1; } else { $exit_out = $exit_out2; $state_out = $state_out2; } print "$state_out ($desc_out1, $desc_out2)\n"; exit $exit_out;