summaryrefslogtreecommitdiffstats
path: root/web/attachments/158101-check_disk_smb.pl.PATCH
diff options
context:
space:
mode:
Diffstat (limited to 'web/attachments/158101-check_disk_smb.pl.PATCH')
-rw-r--r--web/attachments/158101-check_disk_smb.pl.PATCH148
1 files changed, 148 insertions, 0 deletions
diff --git a/web/attachments/158101-check_disk_smb.pl.PATCH b/web/attachments/158101-check_disk_smb.pl.PATCH
new file mode 100644
index 0000000..193932e
--- /dev/null
+++ b/web/attachments/158101-check_disk_smb.pl.PATCH
@@ -0,0 +1,148 @@
1--- check_disk_smb.pl.ORIG Sun Apr 17 22:22:41 2005
2+++ check_disk_smb.pl Mon Nov 28 20:11:19 2005
3@@ -1,7 +1,7 @@
4 #!/usr/bin/perl -w
5 #
6 #
7-# check_disk.pl <host> <share> <user> <pass> [warn] [critical] [port]
8+# check_disk.pl <ip> <host> <share> <user> <pass> [warn] [critical] [port]
9 #
10 # Nagios host script to get the disk usage from a SMB share
11 #
12@@ -15,6 +15,10 @@
13 # allow setting of limits in MBytes or GBytes. Percentage settings for large
14 # drives is a pain in the butt
15 # 2-May-2002 - SGhosh fix for embedded perl
16+# 11-Nov-2005 - John Relph
17+# allow specifying IP address for NetBIOS names that don't resolve
18+# correctly using DNS; specifically for *nix samba servers using
19+# virtual names
20 #
21 # $Id: check_disk_smb.pl,v 1.12 2005/04/17 22:22:41 seanius Exp $
22 #
23@@ -23,7 +27,7 @@
24 use POSIX;
25 use strict;
26 use Getopt::Long;
27-use vars qw($opt_P $opt_V $opt_h $opt_H $opt_s $opt_W $opt_u $opt_p $opt_w $opt_c $verbose);
28+use vars qw($opt_P $opt_V $opt_h $opt_H $opt_I $opt_s $opt_W $opt_u $opt_p $opt_w $opt_c $verbose);
29 use vars qw($PROGNAME);
30 use lib utils.pm ;
31 use utils qw($TIMEOUT %ERRORS &print_revision &support &usage);
32@@ -49,7 +53,9 @@
33 "u=s" => \$opt_u, "username=s" => \$opt_u,
34 "s=s" => \$opt_s, "share=s" => \$opt_s,
35 "W=s" => \$opt_W, "workgroup=s" => \$opt_W,
36- "H=s" => \$opt_H, "hostname=s" => \$opt_H);
37+ "H=s" => \$opt_H, "hostname=s" => \$opt_H,
38+ "I=s" => \$opt_I, "ipaddr=s" => \$opt_I
39+ );
40
41 if ($opt_V) {
42 print_revision($PROGNAME,'$Revision: 1.12 $'); #'
43@@ -68,8 +74,14 @@
44 my $host = $1 if ($opt_H =~ /^([-_.A-Za-z0-9]+\$?)$/);
45 ($host) || usage("Invalid host: $opt_H\n");
46
47+($opt_I) || ($opt_I = shift) || ($opt_I = '');
48+my $ipaddr = ($opt_I =~ /^([-_.A-Za-z0-9]+\$?)$/ ? $1 : '');
49+if ($opt_I) { ($ipaddr) || usage("Invalid IP address: $opt_I\n"); }
50+
51+$smbclientoptions .= "-I $ipaddr " if $ipaddr;
52+
53 ($opt_s) || ($opt_s = shift) || usage("Share volume not specified\n");
54-my $share = $1 if ($opt_s =~ /^([-_.A-Za-z0-9]+\$?)$/);
55+my $share = $1 if ($opt_s =~ /^([-_.A-Za-z0-9 ]+\$?)$/);
56 ($share) || usage("Invalid share: $opt_s\n");
57
58 ($opt_u) || ($opt_u = shift) || ($opt_u = "guest");
59@@ -120,27 +132,23 @@
60 };
61 alarm($TIMEOUT);
62
63-# Execute an "ls" on the share using smbclient program
64+# Execute a "du" on the share using smbclient program
65 # get the results into $res
66 if (defined($workgroup)) {
67- $res = qx/$smbclient \/\/$host\/$share -W $workgroup -U $user%$pass $smbclientoptions -c ls/;
68+ print "$smbclient " . "\/\/$host\/$share" ." $pass -W $workgroup -U $user $smbclientoptions -c du\n" if ($verbose);
69+ $res = qx/$smbclient "\/\/$host\/$share" -W $workgroup -U $user%$pass $smbclientoptions -c du/;
70 } else {
71- print "$smbclient " . "\/\/$host\/$share" ." $pass -U $user $smbclientoptions -c ls\n" if ($verbose);
72- $res = qx/$smbclient \/\/$host\/$share -U $user%$pass $smbclientoptions -c ls/;
73+ print "$smbclient " . "\/\/$host\/$share" ." $pass -U $user $smbclientoptions -c du\n" if ($verbose);
74+ $res = qx/$smbclient "\/\/$host\/$share" -U $user%$pass $smbclientoptions -c du/;
75 }
76 #Turn off alarm
77 alarm(0);
78
79-#Split $res into an array of lines
80-@lines = split /\n/, $res;
81-
82-#Get the last line into $_
83-$_ = $lines[$#lines];
84-#print "$_\n";
85+print "result: $res" if ($verbose);
86
87-#Process the last line to get free space.
88+#Process the output to get free space.
89 #If line does not match required regexp, return an UNKNOWN error
90-if (/\s*(\d*) blocks of size (\d*)\. (\d*) blocks available/) {
91+if ($res =~ m/\s*(\d*) blocks of size (\d*)\. (\d*) blocks available/s) {
92
93 my ($avail) = ($3*$2)/1024;
94 my ($avail_bytes) = $avail;
95@@ -189,9 +197,9 @@
96 $avail = $avail ."K";
97 }
98
99-#print ":$warn:$warn_type:\n";
100-#print ":$crit:$crit_type:\n";
101-#print ":$avail:$avail_bytes:$capper:$mountpt:\n";
102+print ":$warn:$warn_type:\n" if ($verbose);
103+print ":$crit:$crit_type:\n" if ($verbose);
104+print ":$avail:$avail_bytes:$capper:$mountpt:\n" if ($verbose);
105
106 if ((($warn_type eq "P") && (100 - $capper) < $warn) || (($warn_type eq "K") && ($avail_bytes > $warn))) {
107 $answer = "Disk ok - $avail ($capper%) free on $mountpt\n";
108@@ -205,18 +213,18 @@
109 } else {
110 $answer = "Result from smbclient not suitable\n";
111 $state = "UNKNOWN";
112- foreach (@lines) {
113- if (/(Access denied|NT_STATUS_LOGON_FAILURE)/) {
114+ foreach ($res) {
115+ if (/(Access denied|NT_STATUS_LOGON_FAILURE)/s) {
116 $answer = "Access Denied\n";
117 $state = "CRITICAL";
118 last;
119 }
120- if (/(Unknown host \w*|Connection.*failed)/) {
121+ if (/(Unknown host \w*|Connection.*failed)/s) {
122 $answer = "$1\n";
123 $state = "CRITICAL";
124 last;
125 }
126- if (/(You specified an invalid share name|NT_STATUS_BAD_NETWORK_NAME)/) {
127+ if (/(You specified an invalid share name|NT_STATUS_BAD_NETWORK_NAME)/s) {
128 $answer = "Invalid share name \\\\$host\\$share\n";
129 $state = "CRITICAL";
130 last;
131@@ -230,7 +238,7 @@
132 exit $ERRORS{$state};
133
134 sub print_usage () {
135- print "Usage: $PROGNAME -H <host> -s <share> -u <user> -p <password>
136+ print "Usage: $PROGNAME -H <host> -I <ipaddr> -s <share> -u <user> -p <password>
137 -w <warn> -c <crit> [-W <workgroup>] [-P <port>]\n";
138 }
139
140@@ -245,6 +253,8 @@
141 print "
142 -H, --hostname=HOST
143 NetBIOS name of the server
144+-I, --ipaddr=IPADDR
145+ IP address of the server
146 -s, --share=STRING
147 Share name to be tested
148 -W, --workgroup=STRING