diff options
Diffstat (limited to 'plugins-scripts')
-rwxr-xr-x | plugins-scripts/check_disk_smb.pl | 70 |
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])$/); | |||
87 | my $crit = $1 if ($opt_c =~ /^([0-9]{1,2}\%?|100\%?|[0-9]+[kMG])$/); | 87 | my $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 | ||
93 | my $warn_type; | ||
94 | my $crit_type; | ||
95 | |||
96 | if ($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 | } | ||
109 | if ($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 |
91 | unless( ( ($opt_w =~ /([0-9]){1,2}$/ ) && ($opt_c =~ /([0-9]){1,2}$/ ) )|| (( $opt_w =~ /[kMG]/ ) && ($opt_c =~ /[kMG]/) ) ){ | 124 | unless( ( $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 |
96 | if ( $opt_w =~ /[kMG]/) { | 131 | if ( $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); |