133 |
|
|
134 |
|
// this bit determines if the disk check is a % check |
135 |
|
// or a kb check |
136 |
– |
double diskInUse; |
136 |
|
String type; |
137 |
+ |
double curValue; |
138 |
+ |
int newThreshold; |
139 |
|
if(useValue) { |
140 |
< |
// kb disk in use |
141 |
< |
diskInUse = diskTotal - diskAvail; |
140 |
> |
// kb disk available |
141 |
> |
curValue = diskAvail; |
142 |
> |
// negate check |
143 |
> |
newThreshold = checkAttributeThreshold(curValue, reg, true); |
144 |
|
type = "kb"; |
145 |
|
} else { |
146 |
|
// % disk in use |
147 |
< |
diskInUse = (1 - (diskAvail / diskTotal)) * 100; |
147 |
> |
curValue = (1 - (diskAvail / diskTotal)) * 100; |
148 |
> |
// normal check |
149 |
> |
newThreshold = checkAttributeThreshold(curValue, reg, false); |
150 |
|
type = "%"; |
151 |
|
} |
152 |
|
|
148 |
– |
|
149 |
– |
|
150 |
– |
int newThreshold = checkAttributeThreshold(diskInUse, reg); |
151 |
– |
|
153 |
|
// format the diskInUse to a String |
154 |
|
NumberFormat nf = NumberFormat.getInstance(); |
155 |
|
nf.setMaximumFractionDigits(2); |
156 |
|
nf.setMinimumFractionDigits(2); |
157 |
< |
String strDiskInUse = nf.format(diskInUse); |
157 |
> |
String strCurValue = nf.format(curValue); |
158 |
|
|
159 |
|
// say which disk had the problem |
160 |
|
String attributeName = "Disk in use " + type + " on " + mount + " (" + device + ")"; |
161 |
|
|
162 |
< |
processAlert(newThreshold, attributeName, reg, source, strDiskInUse); |
162 |
> |
processAlert(newThreshold, attributeName, reg, source, strCurValue); |
163 |
|
} |
164 |
|
} |
165 |
|
} |
194 |
|
* Checks a piece of current data, and returns the |
195 |
|
* threshold it breaches, if any. |
196 |
|
* |
197 |
< |
* @param diskInUse the amount of space in use |
197 |
> |
* The option to negate the check can be used in |
198 |
> |
* situations where being *below* the threshold |
199 |
> |
* is an 'alertable' situation. In this specific |
200 |
> |
* case, we'd do this with kb disk checks. |
201 |
> |
* |
202 |
> |
* @param value the current value |
203 |
|
* @param reg the Register for the host |
204 |
+ |
* @param negateCheck whether to negate the check |
205 |
|
* @return the threshold level breached, if any |
206 |
|
*/ |
207 |
< |
private int checkAttributeThreshold(double diskInUse, Register reg) { |
207 |
> |
private int checkAttributeThreshold(double diskInUse, Register reg, boolean negateCheck) { |
208 |
|
for(int thresholdLevel = Alert.thresholdLevels.length - 1; thresholdLevel >= 0; thresholdLevel--) { |
209 |
|
if (reg.getThreshold(thresholdLevel) != -1.0) { |
210 |
< |
if(((double) reg.getThreshold(thresholdLevel)) < diskInUse) { |
211 |
< |
return thresholdLevel; |
210 |
> |
if(!negateCheck) { |
211 |
> |
// normal check - has the value gone *over* the threshold |
212 |
> |
if(((double) reg.getThreshold(thresholdLevel)) < diskInUse) { |
213 |
> |
return thresholdLevel; |
214 |
> |
} |
215 |
> |
} |
216 |
> |
else { |
217 |
> |
// negated check - has the value gone *under* the threshold |
218 |
> |
if(((double) reg.getThreshold(thresholdLevel)) > diskInUse) { |
219 |
> |
return thresholdLevel; |
220 |
> |
} |
221 |
|
} |
222 |
|
} |
223 |
|
} |