summaryrefslogtreecommitdiffstats
path: root/plugins-scripts
diff options
context:
space:
mode:
Diffstat (limited to 'plugins-scripts')
-rwxr-xr-xplugins-scripts/check_disk_smb.pl44
-rw-r--r--plugins-scripts/utils.sh.in85
2 files changed, 117 insertions, 12 deletions
diff --git a/plugins-scripts/check_disk_smb.pl b/plugins-scripts/check_disk_smb.pl
index 6783543..43841c3 100755
--- a/plugins-scripts/check_disk_smb.pl
+++ b/plugins-scripts/check_disk_smb.pl
@@ -166,6 +166,7 @@ my $address = $1 if (defined($opt_a) && $opt_a =~ /(.*)/);
166my $state = "OK"; 166my $state = "OK";
167my $answer = undef; 167my $answer = undef;
168my $res = undef; 168my $res = undef;
169my $perfdata = "";
169my @lines = undef; 170my @lines = undef;
170 171
171# Just in case of problems, let's not hang Nagios 172# Just in case of problems, let's not hang Nagios
@@ -204,11 +205,23 @@ $_ = $lines[$#lines];
204#If line does not match required regexp, return an UNKNOWN error 205#If line does not match required regexp, return an UNKNOWN error
205if (/\s*(\d*) blocks of size (\d*)\. (\d*) blocks available/) { 206if (/\s*(\d*) blocks of size (\d*)\. (\d*) blocks available/) {
206 207
207 my ($avail) = ($3*$2)/1024; 208 my ($avail_bytes) = $3 * $2;
208 my ($avail_bytes) = $avail; 209 my ($total_bytes) = $1 * $2;
210 my ($occupied_bytes) = $1 * $2 - $avail_bytes;
211 my ($avail) = $avail_bytes/1024;
209 my ($capper) = int(($3/$1)*100); 212 my ($capper) = int(($3/$1)*100);
210 my ($mountpt) = "\\\\$host\\$share"; 213 my ($mountpt) = "\\\\$host\\$share";
211 214
215 # TODO : why is the kB the standard unit for args ?
216 my ($warn_bytes) = $total_bytes - $warn * 1024;
217 if ($warn_type eq "P") {
218 $warn_bytes = $warn * $1 * $2 / 100;
219 }
220 my ($crit_bytes) = $total_bytes - $crit * 1024;
221 if ($crit_type eq "P") {
222 $crit_bytes = $crit * $1 * $2 / 100;
223 }
224
212 225
213 if (int($avail / 1024) > 0) { 226 if (int($avail / 1024) > 0) {
214 $avail = int($avail / 1024); 227 $avail = int($avail / 1024);
@@ -225,32 +238,37 @@ if (/\s*(\d*) blocks of size (\d*)\. (\d*) blocks available/) {
225#print ":$warn:$warn_type:\n"; 238#print ":$warn:$warn_type:\n";
226#print ":$crit:$crit_type:\n"; 239#print ":$crit:$crit_type:\n";
227#print ":$avail:$avail_bytes:$capper:$mountpt:\n"; 240#print ":$avail:$avail_bytes:$capper:$mountpt:\n";
241 $perfdata = "'" . $share . "'=" . $occupied_bytes . 'B;'
242 . $warn_bytes . ';'
243 . $crit_bytes . ';'
244 . '0;'
245 . $total_bytes;
228 246
229 if ((($warn_type eq "P") && (100 - $capper) < $warn) || (($warn_type eq "K") && ($avail_bytes > $warn))) { 247 if ($occupied_bytes > $crit_bytes) {
230 $answer = "Disk ok - $avail ($capper%) free on $mountpt\n"; 248 $state = "CRITICAL";
231 } elsif ((($crit_type eq "P") && (100 - $capper) < $crit) || (($crit_type eq "K") && ($avail_bytes > $crit))) { 249 $answer = "CRITICAL: Only $avail ($capper%) free on $mountpt";
250 } elsif ( $occupied_bytes > $warn_bytes ) {
232 $state = "WARNING"; 251 $state = "WARNING";
233 $answer = "WARNING: Only $avail ($capper%) free on $mountpt\n"; 252 $answer = "WARNING: Only $avail ($capper%) free on $mountpt";
234 } else { 253 } else {
235 $state = "CRITICAL"; 254 $answer = "Disk ok - $avail ($capper%) free on $mountpt";
236 $answer = "CRITICAL: Only $avail ($capper%) free on $mountpt\n";
237 } 255 }
238} else { 256} else {
239 $answer = "Result from smbclient not suitable\n"; 257 $answer = "Result from smbclient not suitable";
240 $state = "UNKNOWN"; 258 $state = "UNKNOWN";
241 foreach (@lines) { 259 foreach (@lines) {
242 if (/(Access denied|NT_STATUS_LOGON_FAILURE|NT_STATUS_ACCESS_DENIED)/) { 260 if (/(Access denied|NT_STATUS_LOGON_FAILURE|NT_STATUS_ACCESS_DENIED)/) {
243 $answer = "Access Denied\n"; 261 $answer = "Access Denied";
244 $state = "CRITICAL"; 262 $state = "CRITICAL";
245 last; 263 last;
246 } 264 }
247 if (/(Unknown host \w*|Connection.*failed)/) { 265 if (/(Unknown host \w*|Connection.*failed)/) {
248 $answer = "$1\n"; 266 $answer = "$1";
249 $state = "CRITICAL"; 267 $state = "CRITICAL";
250 last; 268 last;
251 } 269 }
252 if (/(You specified an invalid share name|NT_STATUS_BAD_NETWORK_NAME)/) { 270 if (/(You specified an invalid share name|NT_STATUS_BAD_NETWORK_NAME)/) {
253 $answer = "Invalid share name \\\\$host\\$share\n"; 271 $answer = "Invalid share name \\\\$host\\$share";
254 $state = "CRITICAL"; 272 $state = "CRITICAL";
255 last; 273 last;
256 } 274 }
@@ -259,6 +277,8 @@ if (/\s*(\d*) blocks of size (\d*)\. (\d*) blocks available/) {
259 277
260 278
261print $answer; 279print $answer;
280print " | " . $perfdata if ($perfdata);
281print "\n";
262print "$state\n" if ($verbose); 282print "$state\n" if ($verbose);
263exit $ERRORS{$state}; 283exit $ERRORS{$state};
264 284
diff --git a/plugins-scripts/utils.sh.in b/plugins-scripts/utils.sh.in
index b30b908..5fae6ad 100644
--- a/plugins-scripts/utils.sh.in
+++ b/plugins-scripts/utils.sh.in
@@ -21,3 +21,88 @@ support() {
21 $ECHO "@SUPPORT@" | sed -e 's/\n/ /g' 21 $ECHO "@SUPPORT@" | sed -e 's/\n/ /g'
22} 22}
23 23
24#
25# check_range takes a value and a range string, returning successfully if an
26# alert should be raised based on the range.
27#
28check_range() {
29 local v range yes no err decimal start end cmp match
30 v="$1"
31 range="$2"
32
33 # whether to raise an alert or not
34 yes=0
35 no=1
36 err=2
37
38 # regex to match a decimal number
39 decimal="-?([0-9]+\.?[0-9]*|[0-9]*\.[0-9]+)"
40
41 # compare numbers (including decimals), returning true/false
42 cmp() { awk "BEGIN{ if ($1) exit(0); exit(1)}"; }
43
44 # returns successfully if the string in the first argument matches the
45 # regex in the second
46 match() { echo "$1" | grep -E -q -- "$2"; }
47
48 # make sure value is valid
49 if ! match "$v" "^$decimal$"; then
50 echo "${0##*/}: check_range: invalid value" >&2
51 unset -f cmp match
52 return "$err"
53 fi
54
55 # make sure range is valid
56 if ! match "$range" "^@?(~|$decimal)(:($decimal)?)?$"; then
57 echo "${0##*/}: check_range: invalid range" >&2
58 unset -f cmp match
59 return "$err"
60 fi
61
62 # check for leading @ char, which negates the range
63 if match $range '^@'; then
64 range=${range#@}
65 yes=1
66 no=0
67 fi
68
69 # parse the range string
70 if ! match "$range" ':'; then
71 start=0
72 end="$range"
73 else
74 start="${range%%:*}"
75 end="${range#*:}"
76 fi
77
78 # do the comparison, taking positive ("") and negative infinity ("~")
79 # into account
80 if [ "$start" != "~" ] && [ "$end" != "" ]; then
81 if cmp "$start <= $v" && cmp "$v <= $end"; then
82 unset -f cmp match
83 return "$no"
84 else
85 unset -f cmp match
86 return "$yes"
87 fi
88 elif [ "$start" != "~" ] && [ "$end" = "" ]; then
89 if cmp "$start <= $v"; then
90 unset -f cmp match
91 return "$no"
92 else
93 unset -f cmp match
94 return "$yes"
95 fi
96 elif [ "$start" = "~" ] && [ "$end" != "" ]; then
97 if cmp "$v <= $end"; then
98 unset -f cmp match
99 return "$no"
100 else
101 unset -f cmp match
102 return "$yes"
103 fi
104 else
105 unset -f cmp match
106 return "$no"
107 fi
108}