diff options
Diffstat (limited to 'plugins-scripts/check_disk_smb.pl')
-rw-r--r--[-rwxr-xr-x] | plugins-scripts/check_disk_smb.pl | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/plugins-scripts/check_disk_smb.pl b/plugins-scripts/check_disk_smb.pl index 4e46397d..eda8dd48 100755..100644 --- a/plugins-scripts/check_disk_smb.pl +++ b/plugins-scripts/check_disk_smb.pl | |||
@@ -19,15 +19,18 @@ | |||
19 | # | 19 | # |
20 | 20 | ||
21 | require 5.004; | 21 | require 5.004; |
22 | use POSIX; | 22 | use POSIX qw(setsid); |
23 | use strict; | 23 | use strict; |
24 | use Getopt::Long; | 24 | use Getopt::Long; |
25 | use vars qw($opt_P $opt_V $opt_h $opt_H $opt_s $opt_W $opt_u $opt_p $opt_w $opt_c $opt_a $verbose); | 25 | use vars qw($opt_P $opt_V $opt_h $opt_H $opt_s $opt_W $opt_u $opt_p $opt_w $opt_c $opt_a $opt_C $opt_t $verbose); |
26 | use vars qw($PROGNAME); | 26 | use vars qw($PROGNAME); |
27 | use FindBin; | 27 | use FindBin; |
28 | use lib "$FindBin::Bin"; | 28 | use lib "$FindBin::Bin"; |
29 | use utils qw($TIMEOUT %ERRORS &print_revision &support &usage); | 29 | use utils qw($TIMEOUT %ERRORS &print_revision &support &usage); |
30 | 30 | ||
31 | # make us session leader which makes all children exit if we do | ||
32 | setsid; | ||
33 | |||
31 | sub print_help (); | 34 | sub print_help (); |
32 | sub print_usage (); | 35 | sub print_usage (); |
33 | 36 | ||
@@ -40,6 +43,7 @@ $ENV{'ENV'}=''; | |||
40 | Getopt::Long::Configure('bundling'); | 43 | Getopt::Long::Configure('bundling'); |
41 | GetOptions | 44 | GetOptions |
42 | ("v" => \$verbose, "verbose" => \$verbose, | 45 | ("v" => \$verbose, "verbose" => \$verbose, |
46 | "t=i" => \$opt_t, "timeout=i" => \$opt_t, | ||
43 | "P=s" => \$opt_P, "port=s" => \$opt_P, | 47 | "P=s" => \$opt_P, "port=s" => \$opt_P, |
44 | "V" => \$opt_V, "version" => \$opt_V, | 48 | "V" => \$opt_V, "version" => \$opt_V, |
45 | "h" => \$opt_h, "help" => \$opt_h, | 49 | "h" => \$opt_h, "help" => \$opt_h, |
@@ -50,7 +54,8 @@ GetOptions | |||
50 | "s=s" => \$opt_s, "share=s" => \$opt_s, | 54 | "s=s" => \$opt_s, "share=s" => \$opt_s, |
51 | "W=s" => \$opt_W, "workgroup=s" => \$opt_W, | 55 | "W=s" => \$opt_W, "workgroup=s" => \$opt_W, |
52 | "H=s" => \$opt_H, "hostname=s" => \$opt_H, | 56 | "H=s" => \$opt_H, "hostname=s" => \$opt_H, |
53 | "a=s" => \$opt_a, "address=s" => \$opt_a); | 57 | "a=s" => \$opt_a, "address=s" => \$opt_a, |
58 | "C=s" => \$opt_C, "configfile=s" => \$opt_C); | ||
54 | 59 | ||
55 | if ($opt_V) { | 60 | if ($opt_V) { |
56 | print_revision($PROGNAME,'@NP_VERSION@'); #' | 61 | print_revision($PROGNAME,'@NP_VERSION@'); #' |
@@ -88,6 +93,12 @@ my $warn = $1 if ($opt_w =~ /^([0-9]{1,2}\%?|100\%?|[0-9]+[kMG])$/); | |||
88 | my $crit = $1 if ($opt_c =~ /^([0-9]{1,2}\%?|100\%?|[0-9]+[kMG])$/); | 93 | my $crit = $1 if ($opt_c =~ /^([0-9]{1,2}\%?|100\%?|[0-9]+[kMG])$/); |
89 | ($crit) || usage("Invalid critical threshold: $opt_c\n"); | 94 | ($crit) || usage("Invalid critical threshold: $opt_c\n"); |
90 | 95 | ||
96 | ($opt_C) || ($opt_C = shift @ARGV) || ($opt_C = ""); | ||
97 | my $configfile = $opt_C if ($opt_C); | ||
98 | usage("Unable to read config file $configfile\n") if ($configfile) && (! -r $configfile); | ||
99 | |||
100 | if ($opt_t && $opt_t =~ /^([0-9]+)$/) { $TIMEOUT = $1; } | ||
101 | |||
91 | # Execute the given command line and return anything it writes to STDOUT and/or | 102 | # Execute the given command line and return anything it writes to STDOUT and/or |
92 | # STDERR. (This might be useful for other plugins, too, so it should possibly | 103 | # STDERR. (This might be useful for other plugins, too, so it should possibly |
93 | # be moved to utils.pm.) | 104 | # be moved to utils.pm.) |
@@ -175,6 +186,8 @@ my @lines = undef; | |||
175 | # Just in case of problems, let's not hang the monitoring system | 186 | # Just in case of problems, let's not hang the monitoring system |
176 | $SIG{'ALRM'} = sub { | 187 | $SIG{'ALRM'} = sub { |
177 | print "No Answer from Client\n"; | 188 | print "No Answer from Client\n"; |
189 | $SIG{'INT'} = 'IGNORE'; | ||
190 | kill(-2, $$); | ||
178 | exit $ERRORS{"UNKNOWN"}; | 191 | exit $ERRORS{"UNKNOWN"}; |
179 | }; | 192 | }; |
180 | alarm($TIMEOUT); | 193 | alarm($TIMEOUT); |
@@ -188,6 +201,7 @@ my @cmd = ( | |||
188 | defined($workgroup) ? ("-W", $workgroup) : (), | 201 | defined($workgroup) ? ("-W", $workgroup) : (), |
189 | defined($address) ? ("-I", $address) : (), | 202 | defined($address) ? ("-I", $address) : (), |
190 | defined($opt_P) ? ("-p", $opt_P) : (), | 203 | defined($opt_P) ? ("-p", $opt_P) : (), |
204 | defined($configfile) ? ("-s", $configfile) : (), | ||
191 | "-c", "du" | 205 | "-c", "du" |
192 | ); | 206 | ); |
193 | 207 | ||
@@ -288,7 +302,8 @@ exit $ERRORS{$state}; | |||
288 | 302 | ||
289 | sub print_usage () { | 303 | sub print_usage () { |
290 | print "Usage: $PROGNAME -H <host> -s <share> -u <user> -p <password> | 304 | print "Usage: $PROGNAME -H <host> -s <share> -u <user> -p <password> |
291 | -w <warn> -c <crit> [-W <workgroup>] [-P <port>] [-a <IP>]\n"; | 305 | -w <warn> -c <crit> [-W <workgroup>] [-P <port>] [-a <IP>] [-t timeout] |
306 | [-C <configfile>]\n"; | ||
292 | } | 307 | } |
293 | 308 | ||
294 | sub print_help () { | 309 | sub print_help () { |
@@ -314,11 +329,14 @@ Perl Check SMB Disk plugin for monitoring | |||
314 | Password to log in to server. (Defaults to an empty password) | 329 | Password to log in to server. (Defaults to an empty password) |
315 | -w, --warning=INTEGER or INTEGER[kMG] | 330 | -w, --warning=INTEGER or INTEGER[kMG] |
316 | Percent of used space at which a warning will be generated (Default: 85%) | 331 | Percent of used space at which a warning will be generated (Default: 85%) |
317 | |||
318 | -c, --critical=INTEGER or INTEGER[kMG] | 332 | -c, --critical=INTEGER or INTEGER[kMG] |
319 | Percent of used space at which a critical will be generated (Defaults: 95%) | 333 | Percent of used space at which a critical will be generated (Defaults: 95%) |
334 | -t, --timeout=INTEGER | ||
335 | Seconds before connection times out (Default: 15) | ||
320 | -P, --port=INTEGER | 336 | -P, --port=INTEGER |
321 | Port to be used to connect to. Some Windows boxes use 139, others 445 (Defaults to smbclient default) | 337 | Port to be used to connect to. Some Windows boxes use 139, others 445 (Defaults to smbclient default) |
338 | -C, --configfile=STRING | ||
339 | Path to configfile which should be used by smbclient (Defaults to smb.conf of your smb installation) | ||
322 | 340 | ||
323 | If thresholds are followed by either a k, M, or G then check to see if that | 341 | If thresholds are followed by either a k, M, or G then check to see if that |
324 | much disk space is available (kilobytes, Megabytes, Gigabytes) | 342 | much disk space is available (kilobytes, Megabytes, Gigabytes) |