summaryrefslogtreecommitdiffstats
path: root/plugins-scripts/check_disk_smb.pl
diff options
context:
space:
mode:
Diffstat (limited to 'plugins-scripts/check_disk_smb.pl')
-rwxr-xr-xplugins-scripts/check_disk_smb.pl30
1 files changed, 23 insertions, 7 deletions
diff --git a/plugins-scripts/check_disk_smb.pl b/plugins-scripts/check_disk_smb.pl
index 3f531ac7..985fa961 100755
--- a/plugins-scripts/check_disk_smb.pl
+++ b/plugins-scripts/check_disk_smb.pl
@@ -22,7 +22,7 @@ require 5.004;
22use POSIX; 22use POSIX;
23use strict; 23use strict;
24use Getopt::Long; 24use Getopt::Long;
25use vars qw($opt_P $opt_V $opt_h $opt_H $opt_s $opt_W $opt_u $opt_p $opt_w $opt_c $verbose); 25use 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);
26use vars qw($PROGNAME); 26use vars qw($PROGNAME);
27use lib utils.pm ; 27use lib utils.pm ;
28use utils qw($TIMEOUT %ERRORS &print_revision &support &usage); 28use utils qw($TIMEOUT %ERRORS &print_revision &support &usage);
@@ -48,7 +48,8 @@ GetOptions
48 "u=s" => \$opt_u, "username=s" => \$opt_u, 48 "u=s" => \$opt_u, "username=s" => \$opt_u,
49 "s=s" => \$opt_s, "share=s" => \$opt_s, 49 "s=s" => \$opt_s, "share=s" => \$opt_s,
50 "W=s" => \$opt_W, "workgroup=s" => \$opt_W, 50 "W=s" => \$opt_W, "workgroup=s" => \$opt_W,
51 "H=s" => \$opt_H, "hostname=s" => \$opt_H); 51 "H=s" => \$opt_H, "hostname=s" => \$opt_H,
52 "a=s" => \$opt_a, "address=s" => \$opt_a);
52 53
53if ($opt_V) { 54if ($opt_V) {
54 print_revision($PROGNAME,'@NP_VERSION@'); #' 55 print_revision($PROGNAME,'@NP_VERSION@'); #'
@@ -64,7 +65,7 @@ my $smbclientoptions= $opt_P ? "-p $opt_P " : "";
64# Options checking 65# Options checking
65 66
66($opt_H) || ($opt_H = shift) || usage("Host name not specified\n"); 67($opt_H) || ($opt_H = shift) || usage("Host name not specified\n");
67my $host = $1 if ($opt_H =~ /^([-_.A-Za-z0-9]+\$?)$/); 68my $host = $1 if ($opt_H =~ /^([-_.A-Za-z0-9 ]+\$?)$/);
68($host) || usage("Invalid host: $opt_H\n"); 69($host) || usage("Invalid host: $opt_H\n");
69 70
70($opt_s) || ($opt_s = shift) || usage("Share volume not specified\n"); 71($opt_s) || ($opt_s = shift) || usage("Share volume not specified\n");
@@ -141,6 +142,8 @@ if ( $warn_type eq "K") {
141 142
142my $workgroup = $1 if (defined($opt_W) && $opt_W =~ /(.*)/); 143my $workgroup = $1 if (defined($opt_W) && $opt_W =~ /(.*)/);
143 144
145my $address = $1 if (defined($opt_a) && $opt_a =~ /(.*)/);
146
144# end of options checking 147# end of options checking
145 148
146 149
@@ -159,10 +162,21 @@ alarm($TIMEOUT);
159# Execute an "ls" on the share using smbclient program 162# Execute an "ls" on the share using smbclient program
160# get the results into $res 163# get the results into $res
161if (defined($workgroup)) { 164if (defined($workgroup)) {
162 $res = qx/$smbclient \/\/$host\/$share -W $workgroup -U $user%$pass $smbclientoptions -c ls/; 165 if (defined($address)) {
166 print "$smbclient " . "\/\/$host\/$share" ." $pass -W $workgroup -U $user $smbclientoptions -I $address -c ls\n" if ($verbose);
167 $res = qx/$smbclient "\/\/$host\/$share" $pass -W $workgroup -U $user $smbclientoptions -I $address -c ls/;
168 } else {
169 print "$smbclient " . "\/\/$host\/$share" ." $pass -W $workgroup -U $user $smbclientoptions -c ls\n" if ($verbose);
170 $res = qx/$smbclient "\/\/$host\/$share" $pass -W $workgroup -U $user $smbclientoptions -c ls/;
171 }
163} else { 172} else {
164 print "$smbclient " . "\/\/$host\/$share" ." $pass -U $user $smbclientoptions -c ls\n" if ($verbose); 173 if (defined($address)) {
165 $res = qx/$smbclient \/\/$host\/$share -U $user%$pass $smbclientoptions -c ls/; 174 print "$smbclient " . "\/\/$host\/$share" ." $pass -U $user $smbclientoptions -I $address -c ls\n" if ($verbose);
175 $res = qx/$smbclient "\/\/$host\/$share" $pass -U $user $smbclientoptions -I $address -c ls/;
176 } else {
177 print "$smbclient " . "\/\/$host\/$share" ." $pass -U $user $smbclientoptions -c ls\n" if ($verbose);
178 $res = qx/$smbclient "\/\/$host\/$share" $pass -U $user $smbclientoptions -c ls/;
179 }
166} 180}
167#Turn off alarm 181#Turn off alarm
168alarm(0); 182alarm(0);
@@ -238,7 +252,7 @@ exit $ERRORS{$state};
238 252
239sub print_usage () { 253sub print_usage () {
240 print "Usage: $PROGNAME -H <host> -s <share> -u <user> -p <password> 254 print "Usage: $PROGNAME -H <host> -s <share> -u <user> -p <password>
241 -w <warn> -c <crit> [-W <workgroup>] [-P <port>]\n"; 255 -w <warn> -c <crit> [-W <workgroup>] [-P <port>] [-a <IP>]\n";
242} 256}
243 257
244sub print_help () { 258sub print_help () {
@@ -256,6 +270,8 @@ Perl Check SMB Disk plugin for Nagios
256 Share name to be tested 270 Share name to be tested
257-W, --workgroup=STRING 271-W, --workgroup=STRING
258 Workgroup or Domain used (Defaults to \"WORKGROUP\") 272 Workgroup or Domain used (Defaults to \"WORKGROUP\")
273-a, --address=IP
274 IP-address of HOST (only necessary if HOST is in another network)
259-u, --user=STRING 275-u, --user=STRING
260 Username to log in to server. (Defaults to \"guest\") 276 Username to log in to server. (Defaults to \"guest\")
261-p, --password=STRING 277-p, --password=STRING