From 871d2987f9c877a776cd8fff9513c37d601ca2d1 Mon Sep 17 00:00:00 2001 From: hadaq Date: Wed, 12 May 2010 15:36:15 +0000 Subject: [PATCH] New script for hard disks checks. Sergey. --- plugins/check_hdisks.pl | 354 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 354 insertions(+) create mode 100755 plugins/check_hdisks.pl diff --git a/plugins/check_hdisks.pl b/plugins/check_hdisks.pl new file mode 100755 index 0000000..71140a5 --- /dev/null +++ b/plugins/check_hdisks.pl @@ -0,0 +1,354 @@ +#!/usr/bin/perl -w + +use strict; + +###################################################################### +# # +# Nagios plugin to check hard disks and raid arrays. # +# To be able to run smartctl under normal user account # +# you should open permissions under root account: # +# chmod u+s /usr/sbin/smartctl # +# # +# Long self-tests should be executed in crontab: # +# 0 23 * * 0 /usr/sbin/smartctl -t long /dev/sda > /dev/null # +# # +# Sergey Yurevich # +# # +###################################################################### + +use threads; +use threads::shared; +use IO::Socket; +use IO::Select; + +use Data::Dumper; +use FileHandle; +use Getopt::Long; + +our $server_port = '50999'; +our $protocol = 'tcp'; + +my $opt_help = 0; +my $opt_verb = 0; +my $opt_daemon = 0; +my $opt_smart = 1; # Check disks with smartctl tool +my $opt_raid = 1; # Check RAID Arrays +my $opt_sleep = 3600; # 1 hour + +GetOptions ('p|port=i' => \$server_port, + 'd|daemon' => \$opt_daemon, + 's|smart=i' => \$opt_smart, + 'r|raid=i' => \$opt_raid, + 'v|verb' => \$opt_verb, + 'l|sleep=i' => \$opt_sleep, + 'h|help' => \$opt_help); + +if($opt_help){ + &help(); + exit(0); +} + +my $status : shared = "OK"; + +my @disks; # array with the hard disks +my $disks_aref = \@disks; +my %status_hash; # hash with status info for each hard disk +my $status_href = \%status_hash; +my @md_list; # array with RAIDs problematic info + +#my $MDSTAT = "/home/icinga/nagios/plugins/mdstat"; +my $MDSTAT = "/proc/mdstat"; +my $SMARTCTL = "/usr/sbin/smartctl"; + +#- Daemonize +if($opt_daemon){ + open(STDIN, '>/dev/null'); + open(STDOUT, '>/dev/null'); + open(STDERR, '>/dev/null'); +} + +threads->new(\&statusServer); + +&main(); + +exit(0); + +####################### END OF MAIN ###################### + +sub help() +{ + print "\n"; + print << 'EOF'; +check_hdisks.pl + + This script checks RAID status in $MDSTAT. It also checks disks + using smartctl tool. Smart checks must be of course supported + on the given PC. Long smart tests should run as cron jobs: + 0 23 * * 0 /usr/sbin/smartctl -t long /dev/sda > /dev/null + +Usage: + + Command line: check_hdisks.pl + [h|help] : Show this help. + [p|port ] : Port for the Status Server (default: 50999). + [d|daemon] : Run as a daemon. + [s|smart <1|0>] : Enable|disable smart checks (default: 1). + [r|raid <1|0>] : Enable|disable RAID checks (default: 1). + [v|verb] : More verbouse. + [l|sleep