39 lines
695 B
Perl
Executable file
39 lines
695 B
Perl
Executable file
#!/usr/bin/perl -w
|
|
|
|
use strict;
|
|
use Getopt::Long qw(:config no_ignore_case);
|
|
use Time::HiRes qw/ time sleep /;
|
|
|
|
sub usage() {
|
|
print "Usage: check_smb -H <host>\n"
|
|
}
|
|
|
|
my $host;
|
|
my $result = GetOptions(
|
|
"H|host=s" => \$host,
|
|
);
|
|
|
|
if (!$host) {
|
|
usage();
|
|
exit 3;
|
|
}
|
|
|
|
my ($start, $end, $time, @output, $status);
|
|
|
|
$start = time;
|
|
@output = `/usr/bin/smbclient -N -L '$host' 2>&1`;
|
|
$status = $?;
|
|
$end = time;
|
|
|
|
$time = sprintf("%.3f", $end - $start);
|
|
|
|
if ($status != 0) {
|
|
print "SMB CRITICAL: " . join(" ", @output);
|
|
exit(2);
|
|
} else {
|
|
foreach(@output) {
|
|
next unless /^Domain=.*/;
|
|
print "SMB OK: ${time} seconds response time. $_";
|
|
exit(0);
|
|
}
|
|
}
|