#!/usr/bin/perl -T # Author : Daniel McLaughlin (dan.mcl@gmail.com) # Date : 06/12/2011 # check_barracuda_temp # # Copyright (c) 2011 Daniel McLaughlin # # Permission is hereby granted, free of charge, to any person obtaining a copy of this software # and associated documentation files (the "Software"), to deal in the Software without restriction, # including without limitation the rights to use, copy, modify, merge, publish, distribute, # sublicense, and/or sell copies of the Software, and to permit persons to whom the Software # is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE # AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # # #################################################################################################### # globale variabelen: use vars qw($opt_h $opt_H $opt_c $opt_W $opt_C); use Getopt::Std; &getopts("h:H:c:W:C:")||die "ERROR: No options submitted. -help for help\n"; if ($opt_h) { &print_usage; } $ENV{'PATH'} =~ /(.*)/; $ENV{'PATH'} = $1; sub print_usage { print "check_barracuda_temp -H [ IP|HOSTNAME ] -c SNMPCOMMUNITY -W Warning CPU Temp -C Critical CPU Temp"; exit $STATE_UNKNOWN; } $PROGNAME = "check_barracuda_temp"; $STATE_CRITICAL = 2; if ($STATE_CRITICAL =~ /^([-\@\w.]+)$/) { $STATE_CRITICAL = $1; # $data now untainted } else { die "Bad data in '$STATE_CRITICAL'"; # log this somewhere } $STATE_WARNING = 1; if ($STATE_WARNING =~ /^([-\@\w.]+)$/) { $STATE_WARNING = $1; # $data now untainted } else { die "Bad data in '$STATE_WARNING'"; # log this somewhere } $STATE_UNKNOWN = 3; if ($STATE_UNKNOWN =~ /^([-\@\w.]+)$/) { $STATE_UNKNOWN = $1; # $data now untainted } else { die "Bad data in '$STATE_UNKNOWN'"; # log this somewhere } $STATE_OK = 0; if ($STATE_OK =~ /^([-\@\w.]+)$/) { $STATE_OK = $1; # $data now untainted } else { die "Bad data in '$STATE_OK'"; # log this somewhere } $COMMUNITY = $opt_c; if ($COMMUNITY =~ /^([-\@\w.]+)$/) { $COMMUNITY = $1; # $data now untainted } else { die "Bad data in '$COMMUNITY'"; # log this somewhere } $IP = $opt_H; if ($IP =~ /^([-\@\w.]+)$/) { $IP = $1; # $data now untainted } else { die "Bad data in '$IP'"; # log this somewhere } $warning = $opt_W; if ($warning =~ /^([-\@\w.]+)$/) { $warning = $1; # $data now untainted } else { die "Bad data in '$warning'"; # log this somewhere } $critical = $opt_W; if ($critical =~ /^([-\@\w.]+)$/) { $critical = $1; # $data now untainted } else { die "Bad data in '$critical'"; # log this somewhere } # CPU Temp. $cputemp=`snmpwalk -v 2c -c $COMMUNITY $IP 1.3.6.1.4.1.20632.2.16`; if ($cputemp =~ m/(.*)/) { $cputemp = $1; # $data now untainted } else { die "Bad data in '$cputemp'"; # log this somewhere } chomp $cputemp; @cputemp_arr = split(' ',$cputemp); $realcputemp = $cputemp_arr[-1]; $realcputemp =~ s/^"(.*)"$/$1/; # FILTER if ( $cputemp ) { $cputemp =~s/SNMPv2-SMI::enterprises.20632.2.16 = STRING: //g; } else { print "Unknown : No response while querying for the CPU Temp on host $IP\n"; exit $STATE_UNKNOWN; } $OUTPUT="CPU Temp: $realcputemp|CPU-Temp=$realcputemp"; if ( $realcputemp >= $critical) { print "Status is CRITICAL. $OUTPUT\n"; exit $STATE_CRITICAL; } if ( $realcputemp >= $warning) { print "Status is WARNING. $OUTPUT\n"; exit $STATE_WARNING; } else { print "Status is OK. $OUTPUT\n"; exit $STATE_OK; }