55 |
|
// key prefix |
56 |
|
String keyPrefix = "packet.disk.p"; |
57 |
|
|
58 |
< |
// a tempory holder for all the disk attributes we find |
58 |
> |
// a temporary holder for all the disk attributes we find |
59 |
|
ArrayList disks = new ArrayList(); |
60 |
|
|
61 |
|
// unfortunatly we need to check the whole packet |
99 |
|
|
100 |
|
// check if we've seen this disk before on a previous run |
101 |
|
// if not, we need to create a register for it |
102 |
< |
if(!diskRegisters.containsKey(diskNumber)) { |
103 |
< |
diskRegisters.put(diskNumber, new Register(source, _name, mount)); |
102 |
> |
// nb. use the device as the key as this is unlikely to change, |
103 |
> |
// unlike diskNumber which could easily change |
104 |
> |
// (diskNumber is based on the order of df's output!) |
105 |
> |
if(!diskRegisters.containsKey(device)) { |
106 |
> |
diskRegisters.put(device, new Register(source, _name, mount)); |
107 |
|
} |
108 |
|
|
109 |
|
// get the register for this disk |
110 |
< |
Register reg = (Register) diskRegisters.get(diskNumber); |
110 |
> |
Register reg = (Register) diskRegisters.get(device); |
111 |
|
|
112 |
|
// get the packet data |
113 |
|
double diskTotal, diskAvail; |
136 |
|
|
137 |
|
// this bit determines if the disk check is a % check |
138 |
|
// or a kb check |
136 |
– |
double diskInUse; |
139 |
|
String type; |
140 |
+ |
double curValue; |
141 |
+ |
int newThreshold; |
142 |
|
if(useValue) { |
143 |
< |
// kb disk in use |
144 |
< |
diskInUse = diskTotal - diskAvail; |
143 |
> |
// kb disk available |
144 |
> |
curValue = diskAvail; |
145 |
> |
// negate check |
146 |
> |
newThreshold = checkAttributeThreshold(curValue, reg, true); |
147 |
|
type = "kb"; |
148 |
|
} else { |
149 |
|
// % disk in use |
150 |
< |
diskInUse = (1 - (diskAvail / diskTotal)) * 100; |
150 |
> |
curValue = (1 - (diskAvail / diskTotal)) * 100; |
151 |
> |
// normal check |
152 |
> |
newThreshold = checkAttributeThreshold(curValue, reg, false); |
153 |
|
type = "%"; |
154 |
|
} |
155 |
|
|
148 |
– |
|
149 |
– |
|
150 |
– |
int newThreshold = checkAttributeThreshold(diskInUse, reg); |
151 |
– |
|
156 |
|
// format the diskInUse to a String |
157 |
|
NumberFormat nf = NumberFormat.getInstance(); |
158 |
|
nf.setMaximumFractionDigits(2); |
159 |
|
nf.setMinimumFractionDigits(2); |
160 |
< |
String strDiskInUse = nf.format(diskInUse); |
160 |
> |
String strCurValue = nf.format(curValue); |
161 |
|
|
162 |
|
// say which disk had the problem |
163 |
|
String attributeName = "Disk in use " + type + " on " + mount + " (" + device + ")"; |
164 |
|
|
165 |
< |
processAlert(newThreshold, attributeName, reg, source, strDiskInUse); |
165 |
> |
processAlert(newThreshold, attributeName, reg, source, strCurValue); |
166 |
|
} |
167 |
|
} |
168 |
|
} |
197 |
|
* Checks a piece of current data, and returns the |
198 |
|
* threshold it breaches, if any. |
199 |
|
* |
200 |
< |
* @param diskInUse the amount of space in use |
200 |
> |
* The option to negate the check can be used in |
201 |
> |
* situations where being *below* the threshold |
202 |
> |
* is an 'alertable' situation. In this specific |
203 |
> |
* case, we'd do this with kb disk checks. |
204 |
> |
* |
205 |
> |
* @param value the current value |
206 |
|
* @param reg the Register for the host |
207 |
+ |
* @param negateCheck whether to negate the check |
208 |
|
* @return the threshold level breached, if any |
209 |
|
*/ |
210 |
< |
private int checkAttributeThreshold(double diskInUse, Register reg) { |
210 |
> |
private int checkAttributeThreshold(double diskInUse, Register reg, boolean negateCheck) { |
211 |
|
for(int thresholdLevel = Alert.thresholdLevels.length - 1; thresholdLevel >= 0; thresholdLevel--) { |
212 |
|
if (reg.getThreshold(thresholdLevel) != -1.0) { |
213 |
< |
if(((double) reg.getThreshold(thresholdLevel)) < diskInUse) { |
214 |
< |
return thresholdLevel; |
213 |
> |
if(!negateCheck) { |
214 |
> |
// normal check - has the value gone *over* the threshold |
215 |
> |
if(((double) reg.getThreshold(thresholdLevel)) < diskInUse) { |
216 |
> |
return thresholdLevel; |
217 |
> |
} |
218 |
> |
} |
219 |
> |
else { |
220 |
> |
// negated check - has the value gone *under* the threshold |
221 |
> |
if(((double) reg.getThreshold(thresholdLevel)) > diskInUse) { |
222 |
> |
return thresholdLevel; |
223 |
> |
} |
224 |
|
} |
225 |
|
} |
226 |
|
} |