index 8c275c8ce25f95409d3cd7fb0674204812e66ce2..3358f6a139d19c657b39a852cf9d5c58c7c2625e 100755 (executable)
use POSIX;
use strict;
use Getopt::Long;
-use vars qw($opt_V $opt_h $opt_H $opt_s $opt_W $opt_u $opt_p $opt_w $opt_c $verbose);
+use vars qw($opt_P $opt_V $opt_h $opt_H $opt_s $opt_W $opt_u $opt_p $opt_w $opt_c $verbose);
use vars qw($PROGNAME);
use lib utils.pm ;
use utils qw($TIMEOUT %ERRORS &print_revision &support &usage);
Getopt::Long::Configure('bundling');
GetOptions
("v" => \$verbose, "verbose" => \$verbose,
+ "P=s" => \$opt_P, "port=s" => \$opt_P,
"V" => \$opt_V, "version" => \$opt_V,
"h" => \$opt_h, "help" => \$opt_h,
"w=s" => \$opt_w, "warning=s" => \$opt_w,
if ($opt_h) {print_help(); exit $ERRORS{'OK'};}
my $smbclient= "$utils::PATH_TO_SMBCLIENT " ;
-my $smbclientoptions="";
+my $smbclientoptions= $opt_P ? "-p $opt_P " : "";
# Options checking
($opt_H) || ($opt_H = shift) || usage("Host name not specified\n");
-my $host = $1 if ($opt_H =~ /([-_.A-Za-z0-9]+\$?)/);
+my $host = $1 if ($opt_H =~ /^([-_.A-Za-z0-9]+\$?)$/);
($host) || usage("Invalid host: $opt_H\n");
($opt_s) || ($opt_s = shift) || usage("Share volume not specified\n");
-my $share = $1 if ($opt_s =~ /([-_.A-Za-z0-9]+)/);
+my $share = $1 if ($opt_s =~ /^([-_.A-Za-z0-9]+\$?)$/);
($share) || usage("Invalid share: $opt_s\n");
($opt_u) || ($opt_u = shift) || ($opt_u = "guest");
-my $user = $1 if ($opt_u =~ /([-_.A-Za-z0-9]+)/);
+my $user = $1 if ($opt_u =~ /^([-_.A-Za-z0-9\\]+)$/);
($user) || usage("Invalid user: $opt_u\n");
($opt_p) || ($opt_p = shift) || ($opt_p = "guest");
my $pass = $1 if ($opt_p =~ /(.*)/);
($opt_w) || ($opt_w = shift) || ($opt_w = 85);
-my $warn = $1 if ($opt_w =~ /([0-9]{1,2}\%?|100\%?|[0-9]+[kMG])/);
+my $warn = $1 if ($opt_w =~ /^([0-9]{1,2}\%?|100\%?|[0-9]+[kMG])$/);
($warn) || usage("Invalid warning threshold: $opt_w\n");
($opt_c) || ($opt_c = shift) || ($opt_c = 95);
-my $crit = $1 if ($opt_c =~ /([0-9]{1,2}\%?|100\%?|[0-9]+[kMG])/);
+my $crit = $1 if ($opt_c =~ /^([0-9]{1,2}\%?|100\%?|[0-9]+[kMG])$/);
($crit) || usage("Invalid critical threshold: $opt_c\n");
# check if both warning and critical are percentage or size
$answer = "Result from smbclient not suitable\n";
$state = "UNKNOWN";
foreach (@lines) {
- if (/Access denied/) {
+ if (/(Access denied|NT_STATUS_LOGON_FAILURE)/) {
$answer = "Access Denied\n";
$state = "CRITICAL";
last;
}
- if (/(Unknown host \w*)/) {
- $answer = "$1\n";_
-
+ if (/(Unknown host \w*|Connection.*failed)/) {
+ $answer = "$1\n";
$state = "CRITICAL";
last;
}
- if (/(You specified an invalid share name)/) {
+ if (/(You specified an invalid share name|NT_STATUS_BAD_NETWORK_NAME)/) {
$answer = "Invalid share name \\\\$host\\$share\n";
$state = "CRITICAL";
last;
sub print_usage () {
print "Usage: $PROGNAME -H <host> -s <share> -u <user> -p <password>
- -w <warn> -c <crit> [-W <workgroup>]\n";
+ -w <warn> -c <crit> [-W <workgroup>] [-P <port>]\n";
}
sub print_help () {
-c, --critical=INTEGER or INTEGER[kMG]
Percent of used space at which a critical will be generated (Defaults: 95%)
+-P, --port=INTEGER
+ Port to be used to connect to. Some Windows boxes use 139, others 445 (Defaults to smbclient default)
If thresholds are followed by either a k, M, or G then check to see if that
much disk space is available (kilobytes, Megabytes, Gigabytes)