summaryrefslogtreecommitdiffstats
path: root/plugins-scripts/check_disk_smb.pl
diff options
context:
space:
mode:
authorM. Sean Finney <seanius@users.sourceforge.net>2005-10-13 10:14:33 (GMT)
committerM. Sean Finney <seanius@users.sourceforge.net>2005-10-13 10:14:33 (GMT)
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 5a78dab..4f8a9a7 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])$/);
87my $crit = $1 if ($opt_c =~ /^([0-9]{1,2}\%?|100\%?|[0-9]+[kMG])$/); 87my $crit = $1 if ($opt_c =~ /^([0-9]{1,2}\%?|100\%?|[0-9]+[kMG])$/);
88($crit) || usage("Invalid critical threshold: $opt_c\n"); 88($crit) || usage("Invalid critical threshold: $opt_c\n");
89 89
90# split the type from the unit value
91#Check $warn and $crit for type (%/M/G) and set up for tests
92#P = Percent, K = KBytes
93my $warn_type;
94my $crit_type;
95
96if ($opt_w =~ /^([0-9]+)\%?$/) {
97 $warn = "$1";
98 $warn_type = "P";
99} elsif ($opt_w =~ /^([0-9]+)k$/) {
100 $warn_type = "K";
101 $warn = $1;
102} elsif ($opt_w =~ /^([0-9]+)M$/) {
103 $warn_type = "K";
104 $warn = $1 * 1024;
105} elsif ($opt_w =~ /^([0-9]+)G$/) {
106 $warn_type = "K";
107 $warn = $1 * 1048576;
108}
109if ($opt_c =~ /^([0-9]+)\%?$/) {
110 $crit = "$1";
111 $crit_type = "P";
112} elsif ($opt_c =~ /^([0-9]+)k$/) {
113 $crit_type = "K";
114 $crit = $1;
115} elsif ($opt_c =~ /^([0-9]+)M$/) {
116 $crit_type = "K";
117 $crit = $1 * 1024;
118} elsif ($opt_c =~ /^([0-9]+)G$/) {
119 $crit_type = "K";
120 $crit = $1 * 1048576;
121}
122
90# check if both warning and critical are percentage or size 123# check if both warning and critical are percentage or size
91unless( ( ($opt_w =~ /([0-9]){1,2}$/ ) && ($opt_c =~ /([0-9]){1,2}$/ ) )|| (( $opt_w =~ /[kMG]/ ) && ($opt_c =~ /[kMG]/) ) ){ 124unless( ( $warn_type eq "P" && $crit_type eq "P" ) || ( $warn_type ne "P" && $crit_type ne "P" ) ){
125 $opt_w =~ s/\%/\%\%/g;
126 $opt_c =~ s/\%/\%\%/g;
92 usage("Both warning and critical should be same type- warning: $opt_w critical: $opt_c \n"); 127 usage("Both warning and critical should be same type- warning: $opt_w critical: $opt_c \n");
93} 128}
94 129
95# verify warning is less than critical 130# verify warning is less than critical
96if ( $opt_w =~ /[kMG]/) { 131if ( $warn_type eq "K") {
97 unless ( $warn > $crit) { 132 unless ( $warn > $crit) {
98 usage("Disk size: warning ($opt_w) should be greater than critical ($opt_c) \n"); 133 usage("Disk size: warning ($opt_w) should be greater than critical ($opt_c) \n");
99 } 134 }
100}else{ 135}else{
101 unless ( $warn < $crit) { 136 unless ( $warn < $crit) {
137 $opt_w =~ s/\%/\%\%/g;
138 $opt_c =~ s/\%/\%\%/g;
102 usage("Percentage: warning ($opt_w) should be less than critical ($opt_c) \n"); 139 usage("Percentage: warning ($opt_w) should be less than critical ($opt_c) \n");
103 } 140 }
104} 141}
@@ -147,35 +184,6 @@ if (/\s*(\d*) blocks of size (\d*)\. (\d*) blocks available/) {
147 my ($capper) = int(($3/$1)*100); 184 my ($capper) = int(($3/$1)*100);
148 my ($mountpt) = "\\\\$host\\$share"; 185 my ($mountpt) = "\\\\$host\\$share";
149 186
150 #Check $warn and $crit for type (%/M/G) and set up for tests
151 #P = Percent, K = KBytes
152 my $warn_type;
153 my $crit_type;
154
155 if ($opt_w =~ /^([0-9]+$)/) {
156 $warn_type = "P";
157 } elsif ($opt_w =~ /^([0-9]+)k$/) {
158 $warn_type = "K";
159 $warn = $1;
160 } elsif ($opt_w =~ /^([0-9]+)M$/) {
161 $warn_type = "K";
162 $warn = $1 * 1024;
163 } elsif ($opt_w =~ /^([0-9]+)G$/) {
164 $warn_type = "K";
165 $warn = $1 * 1048576;
166 }
167 if ($opt_c =~ /^([0-9]+$)/) {
168 $crit_type = "P";
169 } elsif ($opt_c =~ /^([0-9]+)k$/) {
170 $crit_type = "K";
171 $crit = $1;
172 } elsif ($opt_c =~ /^([0-9]+)M$/) {
173 $crit_type = "K";
174 $crit = $1 * 1024;
175 } elsif ($opt_c =~ /^([0-9]+)G$/) {
176 $crit_type = "K";
177 $crit = $1 * 1048576;
178 }
179 187
180 if (int($avail / 1024) > 0) { 188 if (int($avail / 1024) > 0) {
181 $avail = int($avail / 1024); 189 $avail = int($avail / 1024);