aboutsummaryrefslogtreecommitdiff
path: root/plugins-scripts/check_disk_smb.pl
diff options
context:
space:
mode:
authorGravatar M. Sean Finney <seanius@users.sourceforge.net> 2005-10-13 10:14:33 +0000
committerGravatar M. Sean Finney <seanius@users.sourceforge.net> 2005-10-13 10:14:33 +0000
commita0a6dd410c4de1b96d191a3988dd3709e5a934d3 (patch)
tree8e7b85cf04f808ca7ec87bac2162ffaa66e7224c /plugins-scripts/check_disk_smb.pl
parent321075cd563ddbba92a6ebb8e59abefb9da1e8c2 (diff)
downloadmonitoring-plugins-a0a6dd410c4de1b96d191a3988dd3709e5a934d3.tar.gz
debian bts #300701:
- check_smb fix for freespace threshold parsing from the cmdline options. git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1247 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins-scripts/check_disk_smb.pl')
-rwxr-xr-xplugins-scripts/check_disk_smb.pl70
1 files changed, 39 insertions, 31 deletions
diff --git a/plugins-scripts/check_disk_smb.pl b/plugins-scripts/check_disk_smb.pl
index 5a78dab6..4f8a9a73 100755
--- a/plugins-scripts/check_disk_smb.pl
+++ b/plugins-scripts/check_disk_smb.pl
@@ -87,18 +87,55 @@ my $warn = $1 if ($opt_w =~ /^([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");
+# split the type from the unit value
+#Check $warn and $crit for type (%/M/G) and set up for tests
+#P = Percent, K = KBytes
+my $warn_type;
+my $crit_type;
+
+if ($opt_w =~ /^([0-9]+)\%?$/) {
+ $warn = "$1";
+ $warn_type = "P";
+} elsif ($opt_w =~ /^([0-9]+)k$/) {
+ $warn_type = "K";
+ $warn = $1;
+} elsif ($opt_w =~ /^([0-9]+)M$/) {
+ $warn_type = "K";
+ $warn = $1 * 1024;
+} elsif ($opt_w =~ /^([0-9]+)G$/) {
+ $warn_type = "K";
+ $warn = $1 * 1048576;
+}
+if ($opt_c =~ /^([0-9]+)\%?$/) {
+ $crit = "$1";
+ $crit_type = "P";
+} elsif ($opt_c =~ /^([0-9]+)k$/) {
+ $crit_type = "K";
+ $crit = $1;
+} elsif ($opt_c =~ /^([0-9]+)M$/) {
+ $crit_type = "K";
+ $crit = $1 * 1024;
+} elsif ($opt_c =~ /^([0-9]+)G$/) {
+ $crit_type = "K";
+ $crit = $1 * 1048576;
+}
+
# check if both warning and critical are percentage or size
-unless( ( ($opt_w =~ /([0-9]){1,2}$/ ) && ($opt_c =~ /([0-9]){1,2}$/ ) )|| (( $opt_w =~ /[kMG]/ ) && ($opt_c =~ /[kMG]/) ) ){
+unless( ( $warn_type eq "P" && $crit_type eq "P" ) || ( $warn_type ne "P" && $crit_type ne "P" ) ){
+ $opt_w =~ s/\%/\%\%/g;
+ $opt_c =~ s/\%/\%\%/g;
usage("Both warning and critical should be same type- warning: $opt_w critical: $opt_c \n");
}
# verify warning is less than critical
-if ( $opt_w =~ /[kMG]/) {
+if ( $warn_type eq "K") {
unless ( $warn > $crit) {
usage("Disk size: warning ($opt_w) should be greater than critical ($opt_c) \n");
}
}else{
unless ( $warn < $crit) {
+ $opt_w =~ s/\%/\%\%/g;
+ $opt_c =~ s/\%/\%\%/g;
usage("Percentage: warning ($opt_w) should be less than critical ($opt_c) \n");
}
}
@@ -147,35 +184,6 @@ if (/\s*(\d*) blocks of size (\d*)\. (\d*) blocks available/) {
my ($capper) = int(($3/$1)*100);
my ($mountpt) = "\\\\$host\\$share";
- #Check $warn and $crit for type (%/M/G) and set up for tests
- #P = Percent, K = KBytes
- my $warn_type;
- my $crit_type;
-
- if ($opt_w =~ /^([0-9]+$)/) {
- $warn_type = "P";
- } elsif ($opt_w =~ /^([0-9]+)k$/) {
- $warn_type = "K";
- $warn = $1;
- } elsif ($opt_w =~ /^([0-9]+)M$/) {
- $warn_type = "K";
- $warn = $1 * 1024;
- } elsif ($opt_w =~ /^([0-9]+)G$/) {
- $warn_type = "K";
- $warn = $1 * 1048576;
- }
- if ($opt_c =~ /^([0-9]+$)/) {
- $crit_type = "P";
- } elsif ($opt_c =~ /^([0-9]+)k$/) {
- $crit_type = "K";
- $crit = $1;
- } elsif ($opt_c =~ /^([0-9]+)M$/) {
- $crit_type = "K";
- $crit = $1 * 1024;
- } elsif ($opt_c =~ /^([0-9]+)G$/) {
- $crit_type = "K";
- $crit = $1 * 1048576;
- }
if (int($avail / 1024) > 0) {
$avail = int($avail / 1024);