summaryrefslogtreecommitdiffstats
path: root/plugins-scripts
diff options
context:
space:
mode:
authorSubhendu Ghosh <sghosh@users.sourceforge.net>2002-06-20 04:27:38 (GMT)
committerSubhendu Ghosh <sghosh@users.sourceforge.net>2002-06-20 04:27:38 (GMT)
commitbdb73692bf23ee653a686c60d98454316cede390 (patch)
treec825cb224b4fc1f307dff6b85de61264a440c860 /plugins-scripts
parentf4c6f7f09305c1c9916da6ac4f7aadcb31e319e0 (diff)
downloadmonitoring-plugins-bdb73692bf23ee653a686c60d98454316cede390.tar.gz
logic fix for disk space thresholds
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@56 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins-scripts')
-rwxr-xr-xplugins-scripts/check_disk_smb.pl69
1 files changed, 49 insertions, 20 deletions
diff --git a/plugins-scripts/check_disk_smb.pl b/plugins-scripts/check_disk_smb.pl
index bdfcf26..608f62c 100755
--- a/plugins-scripts/check_disk_smb.pl
+++ b/plugins-scripts/check_disk_smb.pl
@@ -61,6 +61,8 @@ my $smbclient= "$utils::PATH_TO_SMBCLIENT " ;
61my $smbclientoptions=""; 61my $smbclientoptions="";
62 62
63 63
64# Options checking
65
64($opt_H) || ($opt_H = shift) || usage("Host name not specified\n"); 66($opt_H) || ($opt_H = shift) || usage("Host name not specified\n");
65my $host = $1 if ($opt_H =~ /([-_.A-Za-z0-9]+)/); 67my $host = $1 if ($opt_H =~ /([-_.A-Za-z0-9]+)/);
66($host) || usage("Invalid host: $opt_H\n"); 68($host) || usage("Invalid host: $opt_H\n");
@@ -77,15 +79,34 @@ my $user = $1 if ($opt_u =~ /([-_.A-Za-z0-9]+)/);
77my $pass = $1 if ($opt_p =~ /(.*)/); 79my $pass = $1 if ($opt_p =~ /(.*)/);
78 80
79($opt_w) || ($opt_w = shift) || ($opt_w = 85); 81($opt_w) || ($opt_w = shift) || ($opt_w = 85);
80my $warn = $1 if ($opt_w =~ /([0-9]{1,2}\%?|100\%?|[0-9]+[kmKM])+/); 82my $warn = $1 if ($opt_w =~ /([0-9]{1,2}\%?|100\%?|[0-9]+[kMG])/);
81($warn) || usage("Invalid warning threshold: $opt_w\n"); 83($warn) || usage("Invalid warning threshold: $opt_w\n");
82 84
83($opt_c) || ($opt_c = shift) || ($opt_c = 95); 85($opt_c) || ($opt_c = shift) || ($opt_c = 95);
84my $crit = $1 if ($opt_c =~ /([0-9]{1,2}\%?|100\%?|[0-9]+[kmKM])/); 86my $crit = $1 if ($opt_c =~ /([0-9]{1,2}\%?|100\%?|[0-9]+[kMG])/);
85($crit) || usage("Invalid critical threshold: $opt_c\n"); 87($crit) || usage("Invalid critical threshold: $opt_c\n");
86 88
89# check if both warning and critical are percentage or size
90unless( ( ($opt_w =~ /([0-9]){1,2}$/ ) && ($opt_c =~ /([0-9]){1,2}$/ ) )|| (( $opt_w =~ /[kMG]/ ) && ($opt_c =~ /[kMG]/) ) ){
91 usage("Both warning and critical should be same type- warning: $opt_w critical: $opt_c \n");
92}
93
94# verify warning is less than critical
95if ( $opt_w =~ /[kMG]/) {
96 unless ( $warn > $crit) {
97 usage("Disk size: warning ($opt_w) should be greater than critical ($opt_c) \n");
98 }
99}else{
100 unless ( $warn < $crit) {
101 usage("Percentage: warning ($opt_w) should be less than critical ($opt_c) \n");
102 }
103}
104
87my $workgroup = $1 if (defined($opt_W) && $opt_W =~ /(.*)/); 105my $workgroup = $1 if (defined($opt_W) && $opt_W =~ /(.*)/);
88 106
107# end of options checking
108
109
89my $state = "OK"; 110my $state = "OK";
90my $answer = undef; 111my $answer = undef;
91my $res = undef; 112my $res = undef;
@@ -129,27 +150,28 @@ if (/\s*(\d*) blocks of size (\d*)\. (\d*) blocks available/) {
129 #P = Percent, K = KBytes 150 #P = Percent, K = KBytes
130 my $warn_type; 151 my $warn_type;
131 my $crit_type; 152 my $crit_type;
132 if ($warn =~ /^([0-9]+$)/) { 153
154 if ($opt_w =~ /^([0-9]+$)/) {
133 $warn_type = "P"; 155 $warn_type = "P";
134 } elsif ($warn =~ /^([0-9]+)k$/) { 156 } elsif ($opt_w =~ /^([0-9]+)k$/) {
135 my ($warn_type) = "K"; 157 $warn_type = "K";
136 $warn = $1; 158 $warn = $1;
137 } elsif ($warn =~ /^([0-9]+)M$/) { 159 } elsif ($opt_w =~ /^([0-9]+)M$/) {
138 $warn_type = "K"; 160 $warn_type = "K";
139 $warn = $1 * 1024; 161 $warn = $1 * 1024;
140 } elsif ($warn =~ /^([0-9]+)G$/) { 162 } elsif ($opt_w =~ /^([0-9]+)G$/) {
141 $warn_type = "K"; 163 $warn_type = "K";
142 $warn = $1 * 1048576; 164 $warn = $1 * 1048576;
143 } 165 }
144 if ($crit =~ /^([0-9]+$)/) { 166 if ($opt_c =~ /^([0-9]+$)/) {
145 $crit_type = "P"; 167 $crit_type = "P";
146 } elsif ($crit =~ /^([0-9]+)k$/) { 168 } elsif ($opt_c =~ /^([0-9]+)k$/) {
147 $crit_type = "K"; 169 $crit_type = "K";
148 $crit = $1; 170 $crit = $1;
149 } elsif ($crit =~ /^([0-9]+)M$/) { 171 } elsif ($opt_c =~ /^([0-9]+)M$/) {
150 $crit_type = "K"; 172 $crit_type = "K";
151 $crit = $1 * 1024; 173 $crit = $1 * 1024;
152 } elsif ($crit =~ /^([0-9]+)G$/) { 174 } elsif ($opt_c =~ /^([0-9]+)G$/) {
153 $crit_type = "K"; 175 $crit_type = "K";
154 $crit = $1 * 1048576; 176 $crit = $1 * 1048576;
155 } 177 }
@@ -158,25 +180,26 @@ if (/\s*(\d*) blocks of size (\d*)\. (\d*) blocks available/) {
158 $avail = int($avail / 1024); 180 $avail = int($avail / 1024);
159 if (int($avail /1024) > 0) { 181 if (int($avail /1024) > 0) {
160 $avail = (int(($avail / 1024)*100))/100; 182 $avail = (int(($avail / 1024)*100))/100;
161 $avail = $avail."G"; 183 $avail = $avail ."G";
162 } else { 184 } else {
163 $avail = $avail."M"; 185 $avail = $avail ."M";
164 } 186 }
165 } else { 187 } else {
166 $avail = $avail."K"; 188 $avail = $avail ."K";
167 } 189 }
168 190
169#print ":$warn:$warn_type:\n"; 191#print ":$warn:$warn_type:\n";
170#print ":$crit:$crit_type:\n"; 192#print ":$crit:$crit_type:\n";
171#print ":$avail:$avail_bytes:$capper:$mountpt:\n"; 193#print ":$avail:$avail_bytes:$capper:$mountpt:\n";
194
172 if ((($warn_type eq "P") && (100 - $capper) < $warn) || (($warn_type eq "K") && ($avail_bytes > $warn))) { 195 if ((($warn_type eq "P") && (100 - $capper) < $warn) || (($warn_type eq "K") && ($avail_bytes > $warn))) {
173 $answer = "Disk ok - $avail ($capper%) free on $mountpt\n"; 196 $answer = "Disk ok - $avail ($capper%) free on $mountpt\n";
174 } elsif ((($crit_type eq "P") && (100 - $capper) < $crit) || (($crit_type eq "K") && ($avail_bytes > $crit))) { 197 } elsif ((($crit_type eq "P") && (100 - $capper) < $crit) || (($crit_type eq "K") && ($avail_bytes > $crit))) {
175 $state = "WARNING"; 198 $state = "WARNING";
176 $answer = "Only $avail ($capper%) free on $mountpt\n"; 199 $answer = "WARNING: Only $avail ($capper%) free on $mountpt\n";
177 } else { 200 } else {
178 $state = "CRITICAL"; 201 $state = "CRITICAL";
179 $answer = "Only $avail ($capper%) free on $mountpt\n"; 202 $answer = "CRITICAL: Only $avail ($capper%) free on $mountpt\n";
180 } 203 }
181} else { 204} else {
182 $answer = "Result from smbclient not suitable\n"; 205 $answer = "Result from smbclient not suitable\n";
@@ -188,7 +211,8 @@ if (/\s*(\d*) blocks of size (\d*)\. (\d*) blocks available/) {
188 last; 211 last;
189 } 212 }
190 if (/(Unknown host \w*)/) { 213 if (/(Unknown host \w*)/) {
191 $answer = "$1\n"; 214 $answer = "$1\n";_
215
192 $state = "CRITICAL"; 216 $state = "CRITICAL";
193 last; 217 last;
194 } 218 }
@@ -229,12 +253,17 @@ Perl Check SMB Disk plugin for Nagios
229 Username to log in to server. (Defaults to \"guest\") 253 Username to log in to server. (Defaults to \"guest\")
230-p, --password=STRING 254-p, --password=STRING
231 Password to log in to server. (Defaults to \"guest\") 255 Password to log in to server. (Defaults to \"guest\")
232-w, --warning=INTEGER 256-w, --warning=INTEGER or INTEGER[kMG]
233 Percent of used space at which a warning will be generated (Default: 85%) 257 Percent of used space at which a warning will be generated (Default: 85%)
234 258
235-c, --critical=INTEGER 259-c, --critical=INTEGER or INTEGER[kMG]
236 Percent of used space at which a critical will be generated (Defaults: 95%) 260 Percent of used space at which a critical will be generated (Defaults: 95%)
237 261
262 If thresholds are followed by either a k, M, or G then check to see if that
263 much disk space is available (kilobytes, Megabytes, Gigabytes)
264
265 Warning percentage should be less than critical
266 Warning (remaining) disk space should be greater than critical.
238 267
239"; 268";
240 support(); 269 support();