8 |
|
/** |
9 |
|
* The Register class holds theshold values, |
10 |
|
* the last level of alert for each attribute for a monitor |
11 |
< |
* and the time of last alert sent for each alert level for |
12 |
< |
* each attribute in this register. |
11 |
> |
* and the time of last alert sent for each alert level. |
12 |
|
* |
13 |
|
* This class is used by monitor classes so they can determine |
14 |
|
* how often they should send alerts when breaching alert levels. |
33 |
|
|
34 |
|
/** |
35 |
|
* Construct a Register with the hostname and monitorName |
36 |
< |
* (for obtaining the threshold values), and the number of |
38 |
< |
* attributes we are keeping track of. |
36 |
> |
* (for obtaining the threshold values). |
37 |
|
* |
38 |
|
* @param hostname the hostname this register is for |
39 |
|
* @param monitorName the monitor this register is for |
40 |
< |
* @param numAttributes the number of attributes to track |
40 |
> |
|
41 |
|
*/ |
42 |
< |
public Register(String hostname, String monitorName, int numAttributes) { |
42 |
> |
public Register(String hostname, String monitorName) { |
43 |
|
_hostname = hostname; |
44 |
|
_monitorName = monitorName; |
45 |
< |
_lastAlertLevels = new int[numAttributes]; |
46 |
< |
_lastThresholdLevels = new int[numAttributes]; |
47 |
< |
_initialAlertTime = new long[numAttributes]; |
48 |
< |
_lastAlertTimeout = new long[numAttributes]; |
49 |
< |
_times = new long[numAttributes][Alert.alertLevels.length]; |
45 |
> |
_lastAlertLevel = 0; |
46 |
> |
_lastThresholdLevel = 0; |
47 |
> |
_initialAlertTime= 0; |
48 |
> |
_lastAlertTimeout = 0; |
49 |
> |
_times = new long[Alert.alertLevels.length]; |
50 |
|
// initialise the arrays to 0 |
51 |
< |
for (int x = 0; x < _lastAlertLevels.length; x++) { |
52 |
< |
_lastAlertLevels[x] = 0; |
55 |
< |
_initialAlertTime[x] = 0; |
56 |
< |
_lastThresholdLevels[x] = 0; |
57 |
< |
_lastAlertTimeout[x] = 0; |
58 |
< |
for(int y = 0; y < Alert.alertLevels.length; y++) { |
59 |
< |
_times[x][y] = 0; |
60 |
< |
} |
51 |
> |
for(int x = 0; x < Alert.alertLevels.length; x++) { |
52 |
> |
_times[x] = 0; |
53 |
|
} |
54 |
|
} |
55 |
|
|
60 |
|
//---ACCESSOR/MUTATOR METHODS--- |
61 |
|
|
62 |
|
/** |
63 |
< |
* Gets the last alert level for the |
72 |
< |
* given attribute. |
63 |
> |
* Gets the last alert level |
64 |
|
* |
74 |
– |
* @param attributeNum the attribute to get |
75 |
– |
* |
65 |
|
* @return the last alert level |
66 |
|
*/ |
67 |
< |
public int getLastAlertLevel(int attributeNum) { |
68 |
< |
return _lastAlertLevels[attributeNum]; |
67 |
> |
public int getLastAlertLevel() { |
68 |
> |
return _lastAlertLevel; |
69 |
|
} |
70 |
|
|
71 |
|
/** |
72 |
< |
* Sets the last threshold level for the |
84 |
< |
* given attribute. |
72 |
> |
* Sets the last threshold level |
73 |
|
* |
86 |
– |
* @param attributeNum the attribute to set |
74 |
|
* @param level the new last threshold level |
75 |
|
*/ |
76 |
< |
public void setLastThresholdLevel(int attributeNum, int level) { |
77 |
< |
_lastThresholdLevels[attributeNum] = level; |
76 |
> |
public void setLastThresholdLevel(int level) { |
77 |
> |
_lastThresholdLevel = level; |
78 |
|
} |
79 |
|
|
80 |
< |
/** |
81 |
< |
* Gets the last threshold level for the |
95 |
< |
* given attribute. |
80 |
> |
/** |
81 |
> |
* Gets the last threshold level |
82 |
|
* |
97 |
– |
* @param attributeNum the attribute to get |
98 |
– |
* |
83 |
|
* @return the last threshold level |
84 |
|
*/ |
85 |
< |
public int getLastThresholdLevel(int attributeNum) { |
86 |
< |
return _lastThresholdLevels[attributeNum]; |
85 |
> |
public int getLastThresholdLevel() { |
86 |
> |
return _lastThresholdLevel; |
87 |
|
} |
88 |
|
|
89 |
|
/** |
90 |
< |
* Sets the last alert level for the |
107 |
< |
* given attribute. |
90 |
> |
* Sets the last alert level |
91 |
|
* |
92 |
|
* Note that if this is setting to an OK |
93 |
|
* level alert, it resets _maxLevelCount. |
96 |
|
* if the next alert after OK is set. |
97 |
|
* And resets it to 0 if it IS an OK. |
98 |
|
* |
116 |
– |
* @param attributeNum the attribute to set |
99 |
|
* @param level the new last alert level |
100 |
|
*/ |
101 |
< |
public void setLastAlertLevel(int attributeNum, int level) { |
102 |
< |
_lastAlertLevels[attributeNum] = level; |
101 |
> |
public void setLastAlertLevel(int level) { |
102 |
> |
_lastAlertLevel = level; |
103 |
|
if (level == Alert.alertOK) { |
104 |
|
_maxLevelCount = 0; |
105 |
< |
_initialAlertTime[attributeNum] = 0; |
105 |
> |
_initialAlertTime = 0; |
106 |
|
} |
107 |
|
if (level == Alert.alertOK + 1) { |
108 |
< |
_initialAlertTime[attributeNum] = System.currentTimeMillis(); |
108 |
> |
_initialAlertTime = System.currentTimeMillis(); |
109 |
|
} |
110 |
|
} |
111 |
|
|
112 |
|
/** |
113 |
< |
* Gets the time an alert was sent for the |
132 |
< |
* given attribute at the given level. |
113 |
> |
* Gets the time an alert was sent at the given level. |
114 |
|
* |
134 |
– |
* @param attributeNum the attribute to get |
115 |
|
* @param level the alert level to get |
116 |
|
* |
117 |
|
* @return the time last sent |
118 |
|
*/ |
119 |
< |
public long getTimeLastSent(int attributeNum) { |
120 |
< |
return _times[attributeNum][getLastAlertLevel(attributeNum)]; |
119 |
> |
public long getTimeLastSent() { |
120 |
> |
return _times[getLastAlertLevel()]; |
121 |
|
} |
122 |
|
|
123 |
|
/** |
124 |
< |
* Gets the time an alert was sent for the |
145 |
< |
* given attribute at the given level. |
124 |
> |
* Gets the time an alert was sent at the given level. |
125 |
|
* |
147 |
– |
* @param attributeNum the attribute to get |
126 |
|
* @param level the alert level to get |
127 |
|
* @param value the new time |
128 |
|
*/ |
129 |
< |
public void setTimeLastSent(int attributeNum, long value) { |
130 |
< |
_times[attributeNum][getLastAlertLevel(attributeNum)] = value; |
129 |
> |
public void setTimeLastSent(long value) { |
130 |
> |
_times[getLastAlertLevel()] = value; |
131 |
|
} |
132 |
|
|
133 |
|
/** |
170 |
|
* @param level the alert level |
171 |
|
* @param thresholdLevel the threshold leve we are on |
172 |
|
*/ |
173 |
< |
public long getAlertTimeout(int level, int attributeNum) { |
173 |
> |
public long getAlertTimeout(int level) { |
174 |
|
// 0 means we don't use this value |
175 |
|
long timeout = 0; |
176 |
|
try { |
177 |
|
String timeoutString = _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".alertTimeout." + Alert.alertLevels[level]); |
178 |
< |
int threshold = getLastThresholdLevel(attributeNum); |
178 |
> |
int threshold = getLastThresholdLevel(); |
179 |
|
if (threshold > 0) { |
180 |
|
timeout = (Long.parseLong(timeoutString) / threshold) * 1000; |
181 |
|
} |
196 |
|
* in the list, this is assumed to be FINAL, and special |
197 |
|
* logic is in place to handle that. |
198 |
|
* |
221 |
– |
* @param attributeNum the attribute to get next alert for |
199 |
|
*/ |
200 |
< |
public int getNextAlertLevel(int attributeNum) { |
201 |
< |
if((getLastAlertLevel(attributeNum) + 1) > (Alert.alertLevels.length - 2)) { |
202 |
< |
return getLastAlertLevel(attributeNum); |
200 |
> |
public int getNextAlertLevel() { |
201 |
> |
if((getLastAlertLevel() + 1) > (Alert.alertLevels.length - 2)) { |
202 |
> |
return getLastAlertLevel(); |
203 |
|
} |
204 |
< |
return getLastAlertLevel(attributeNum) + 1; |
204 |
> |
return getLastAlertLevel() + 1; |
205 |
|
} |
206 |
|
|
207 |
|
/** |
208 |
|
* Gets the timeout value of the last alert |
209 |
|
* sent |
210 |
|
* |
234 |
– |
* @param attrubuteNum the attribute to get the last timeout for |
211 |
|
* @return the last timeout value |
212 |
|
*/ |
213 |
< |
public long getLastAlertTimeout(int attributeNum) { |
214 |
< |
return _lastAlertTimeout[attributeNum]; |
213 |
> |
public long getLastAlertTimeout() { |
214 |
> |
return _lastAlertTimeout; |
215 |
|
} |
216 |
|
|
217 |
|
/** |
218 |
|
* Sets the timeout value of the last alert |
219 |
|
* sent |
220 |
|
* |
245 |
– |
* @param attrubuteNum the attribute to get the last timeout for |
221 |
|
* @param timeout the new value |
222 |
|
*/ |
223 |
< |
public void setLastAlertTimeout(int attributeNum, long timeout) { |
224 |
< |
_lastAlertTimeout[attributeNum] = timeout; |
223 |
> |
public void setLastAlertTimeout(long timeout) { |
224 |
> |
_lastAlertTimeout = timeout; |
225 |
|
} |
226 |
|
|
227 |
|
/** |
228 |
|
* Returns the time that the first alert was sent |
229 |
|
* for an attribute that has passed a threshold value |
230 |
|
* |
256 |
– |
* @param attrubuteNum the attribute to get the first alert time for |
231 |
|
*/ |
232 |
< |
public long getInitialAlertTime(int attributeNum) { |
233 |
< |
return _initialAlertTime[attributeNum]; |
232 |
> |
public long getInitialAlertTime() { |
233 |
> |
return _initialAlertTime; |
234 |
|
} |
235 |
|
|
236 |
|
/** |
252 |
|
* is mis-read or is not configured. It will NEVER reach |
253 |
|
* a FINAL. |
254 |
|
* |
281 |
– |
* @param attributeNum the attribute to advance the alert for |
255 |
|
*/ |
256 |
< |
public void escalateAlert(int attributeNum) { |
256 |
> |
public void escalateAlert() { |
257 |
|
// don't escalate if we're already on the last alert |
258 |
< |
if(getLastAlertLevel(attributeNum) != Alert.alertLevels.length -1) { |
259 |
< |
setLastAlertLevel(attributeNum, getNextAlertLevel(attributeNum)); |
258 |
> |
if(getLastAlertLevel() != Alert.alertLevels.length -1) { |
259 |
> |
setLastAlertLevel(getNextAlertLevel()); |
260 |
|
} |
261 |
|
try { |
262 |
|
// note if we fail to get this value, we won't process the res of this |
263 |
|
int reachFINALcount = Integer.parseInt(_cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".reachFINALcount")); |
264 |
< |
if (getLastAlertLevel(attributeNum) == Alert.alertLevels.length - 2) { |
264 |
> |
if (getLastAlertLevel() == Alert.alertLevels.length - 2) { |
265 |
|
_maxLevelCount++; |
266 |
< |
if(_maxLevelCount >= reachFINALcount) { |
267 |
< |
setLastAlertLevel(attributeNum, Alert.alertFINAL); |
266 |
> |
if(_maxLevelCount > reachFINALcount) { |
267 |
> |
setLastAlertLevel(Alert.alertFINAL); |
268 |
|
} |
269 |
|
} |
270 |
|
} catch (PropertyNotFoundException e) { |
291 |
|
* each attribute this register is looking |
292 |
|
* after. |
293 |
|
*/ |
294 |
< |
private int[] _lastAlertLevels; |
294 |
> |
private int _lastAlertLevel; |
295 |
|
|
296 |
|
/** |
297 |
|
* An array of last threshold levels for |
298 |
|
* each attribute this register is looking |
299 |
|
* after. |
300 |
|
*/ |
301 |
< |
private int[] _lastThresholdLevels; |
301 |
> |
private int _lastThresholdLevel; |
302 |
|
|
303 |
|
/** |
304 |
|
* An array of last alert timeout levels for |
305 |
|
* each attribute this register is looking |
306 |
|
* after. |
307 |
|
*/ |
308 |
< |
private long[] _lastAlertTimeout; |
308 |
> |
private long _lastAlertTimeout; |
309 |
|
|
310 |
|
/** |
311 |
|
* An array of arrays containing |
312 |
|
* time an alert of each level |
313 |
|
* was last sent for each attribute. |
314 |
|
*/ |
315 |
< |
private long[][] _times; |
315 |
> |
private long[] _times; |
316 |
|
|
317 |
|
/** |
318 |
|
* Initial times that an alert was first |
319 |
|
* raised. |
320 |
|
*/ |
321 |
< |
private long[] _initialAlertTime; |
321 |
> |
private long _initialAlertTime; |
322 |
|
|
323 |
|
/** |
324 |
|
* A reference to the configuration proxy in use |