34 |
|
/** |
35 |
|
* Construct a Register with the hostname and monitorName |
36 |
|
* (for obtaining the threshold values). |
37 |
+ |
* This constructs a generic register for a specific monitor. |
38 |
|
* |
39 |
|
* @param hostname the hostname this register is for |
40 |
|
* @param monitorName the monitor this register is for |
40 |
– |
|
41 |
|
*/ |
42 |
|
public Register(String hostname, String monitorName) { |
43 |
+ |
this(hostname, monitorName, null); |
44 |
+ |
} |
45 |
+ |
|
46 |
+ |
/** |
47 |
+ |
* Construct a Register with the hostname and monitorName |
48 |
+ |
* (for obtaining the threshold values). |
49 |
+ |
* This constructs a register for a specific attribute check |
50 |
+ |
* by a monitor. |
51 |
+ |
* |
52 |
+ |
* @param hostname the hostname this register is for |
53 |
+ |
* @param monitorName the monitor this register is for |
54 |
+ |
* @param attributeName the specific attribute this register is for |
55 |
+ |
*/ |
56 |
+ |
public Register(String hostname, String monitorName, String attributeName) { |
57 |
|
_hostname = hostname; |
58 |
|
_monitorName = monitorName; |
59 |
+ |
_attributeName = attributeName; |
60 |
|
_lastAlertLevel = 0; |
61 |
|
_lastThresholdLevel = 0; |
62 |
|
_initialAlertTime= 0; |
67 |
|
_times[x] = 0; |
68 |
|
} |
69 |
|
} |
70 |
+ |
|
71 |
|
|
72 |
|
//---PUBLIC METHODS--- |
73 |
|
|
74 |
|
//---PRIVATE METHODS--- |
75 |
|
|
76 |
+ |
/** |
77 |
+ |
* Obtains a threshold value from the configuration for a given level. |
78 |
+ |
* The attribute name specifies which property to get. |
79 |
+ |
* eg, attributeName = idle it will look for |
80 |
+ |
* Monitor.<monitor name>.idle.threshold.<alert level> |
81 |
+ |
* eg, attributeName = null |
82 |
+ |
* Monitor.<monitor name>.threshold.<alert level> |
83 |
+ |
* |
84 |
+ |
* Note that if its null, this will get the threshold for the monitor |
85 |
+ |
* as a whole, not the specific attribute. |
86 |
+ |
* |
87 |
+ |
* @param level the alert level to get the attribute for |
88 |
+ |
* @param attributeName the attribute to get the threshold for |
89 |
+ |
* |
90 |
+ |
* @return the threshold obtained |
91 |
+ |
*/ |
92 |
+ |
private String getThresholdConfig(int level, String attributeName) throws PropertyNotFoundException { |
93 |
+ |
String temp = ""; |
94 |
+ |
if (attributeName != null) { |
95 |
+ |
temp = "." + attributeName; |
96 |
+ |
} |
97 |
+ |
return _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + temp + ".threshold." + Alert.thresholdLevels[level]); |
98 |
+ |
} |
99 |
+ |
|
100 |
|
//---ACCESSOR/MUTATOR METHODS--- |
101 |
|
|
102 |
|
/** |
142 |
|
_lastAlertLevel = level; |
143 |
|
if (level == Alert.alertOK) { |
144 |
|
_maxLevelCount = 0; |
145 |
< |
_initialAlertTime = 0; |
145 |
> |
// we won't do this, so OK's still have the initialAlertTime |
146 |
> |
// of the original alert they're OK'ing |
147 |
> |
//_initialAlertTime = 0; |
148 |
|
} |
149 |
|
if (level == Alert.alertOK + 1) { |
150 |
|
_initialAlertTime = System.currentTimeMillis(); |
185 |
|
// -1.0 means we don't use an alert level |
186 |
|
double threshold = -1.0; |
187 |
|
try { |
188 |
< |
String thresholdString = _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".threshold." + Alert.thresholdLevels[level]); |
188 |
> |
String thresholdString = ""; |
189 |
> |
try { |
190 |
> |
thresholdString = getThresholdConfig(level, _attributeName); |
191 |
> |
} catch (PropertyNotFoundException e) { |
192 |
> |
thresholdString = getThresholdConfig(level, null); |
193 |
> |
} |
194 |
|
threshold = Double.parseDouble(thresholdString); |
195 |
|
} catch (PropertyNotFoundException e) { |
196 |
|
threshold = -1.0; |
332 |
|
* The monitor this register is for |
333 |
|
*/ |
334 |
|
private String _monitorName; |
335 |
+ |
|
336 |
+ |
/** |
337 |
+ |
* The attribute name, as obtained from |
338 |
+ |
* the configuration. |
339 |
+ |
* eg, idle or /var |
340 |
+ |
*/ |
341 |
+ |
private String _attributeName; |
342 |
|
|
343 |
|
/** |
344 |
|
* An array of last alert levels for |