1 |
+ |
/* |
2 |
+ |
* i-scream central monitoring system |
3 |
+ |
* Copyright (C) 2000-2002 i-scream |
4 |
+ |
* |
5 |
+ |
* This program is free software; you can redistribute it and/or |
6 |
+ |
* modify it under the terms of the GNU General Public License |
7 |
+ |
* as published by the Free Software Foundation; either version 2 |
8 |
+ |
* of the License, or (at your option) any later version. |
9 |
+ |
* |
10 |
+ |
* This program is distributed in the hope that it will be useful, |
11 |
+ |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
+ |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
+ |
* GNU General Public License for more details. |
14 |
+ |
* |
15 |
+ |
* You should have received a copy of the GNU General Public License |
16 |
+ |
* along with this program; if not, write to the Free Software |
17 |
+ |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 |
+ |
*/ |
19 |
+ |
|
20 |
|
//---PACKAGE DECLARATION--- |
21 |
< |
package uk.org.iscream.client; |
21 |
> |
package uk.org.iscream.cms.server.client; |
22 |
|
|
23 |
|
//---IMPORTS--- |
24 |
< |
import uk.org.iscream.util.*; |
25 |
< |
import uk.org.iscream.componentmanager.*; |
24 |
> |
import uk.org.iscream.cms.server.util.*; |
25 |
> |
import uk.org.iscream.cms.server.componentmanager.*; |
26 |
|
|
27 |
|
/** |
28 |
|
* The Register class holds theshold values, |
53 |
|
/** |
54 |
|
* Construct a Register with the hostname and monitorName |
55 |
|
* (for obtaining the threshold values). |
56 |
+ |
* This constructs a generic register for a specific monitor. |
57 |
|
* |
58 |
|
* @param hostname the hostname this register is for |
59 |
|
* @param monitorName the monitor this register is for |
40 |
– |
|
60 |
|
*/ |
61 |
|
public Register(String hostname, String monitorName) { |
62 |
+ |
this(hostname, monitorName, null); |
63 |
+ |
} |
64 |
+ |
|
65 |
+ |
/** |
66 |
+ |
* Construct a Register with the hostname and monitorName |
67 |
+ |
* (for obtaining the threshold values). |
68 |
+ |
* This constructs a register for a specific attribute check |
69 |
+ |
* by a monitor. |
70 |
+ |
* |
71 |
+ |
* @param hostname the hostname this register is for |
72 |
+ |
* @param monitorName the monitor this register is for |
73 |
+ |
* @param attributeName the specific attribute this register is for |
74 |
+ |
*/ |
75 |
+ |
public Register(String hostname, String monitorName, String attributeName) { |
76 |
|
_hostname = hostname; |
77 |
|
_monitorName = monitorName; |
78 |
+ |
_attributeName = attributeName; |
79 |
|
_lastAlertLevel = 0; |
80 |
|
_lastThresholdLevel = 0; |
81 |
|
_initialAlertTime= 0; |
86 |
|
_times[x] = 0; |
87 |
|
} |
88 |
|
} |
89 |
+ |
|
90 |
|
|
91 |
|
//---PUBLIC METHODS--- |
92 |
|
|
93 |
|
//---PRIVATE METHODS--- |
94 |
|
|
95 |
+ |
/** |
96 |
+ |
* Obtains a threshold value from the configuration for a given level. |
97 |
+ |
* The attribute name specifies which property to get. |
98 |
+ |
* eg, attributeName = idle it will look for |
99 |
+ |
* Monitor.<monitor name>.idle.threshold.<alert level> |
100 |
+ |
* eg, attributeName = null |
101 |
+ |
* Monitor.<monitor name>.threshold.<alert level> |
102 |
+ |
* |
103 |
+ |
* Note that if its null, this will get the threshold for the monitor |
104 |
+ |
* as a whole, not the specific attribute. |
105 |
+ |
* |
106 |
+ |
* @param level the alert level to get the attribute for |
107 |
+ |
* @param attributeName the attribute to get the threshold for |
108 |
+ |
* |
109 |
+ |
* @return the threshold obtained |
110 |
+ |
*/ |
111 |
+ |
private String getThresholdConfig(int level, String attributeName) throws PropertyNotFoundException { |
112 |
+ |
String temp = ""; |
113 |
+ |
if (attributeName != null) { |
114 |
+ |
temp = "." + attributeName; |
115 |
+ |
} |
116 |
+ |
return _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + temp + ".threshold." + Alert.thresholdLevels[level]); |
117 |
+ |
} |
118 |
+ |
|
119 |
|
//---ACCESSOR/MUTATOR METHODS--- |
120 |
|
|
121 |
|
/** |
161 |
|
_lastAlertLevel = level; |
162 |
|
if (level == Alert.alertOK) { |
163 |
|
_maxLevelCount = 0; |
164 |
< |
_initialAlertTime = 0; |
164 |
> |
// we won't do this, so OK's still have the initialAlertTime |
165 |
> |
// of the original alert they're OK'ing |
166 |
> |
//_initialAlertTime = 0; |
167 |
|
} |
168 |
|
if (level == Alert.alertOK + 1) { |
169 |
|
_initialAlertTime = System.currentTimeMillis(); |
204 |
|
// -1.0 means we don't use an alert level |
205 |
|
double threshold = -1.0; |
206 |
|
try { |
207 |
< |
String thresholdString = _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".threshold." + Alert.thresholdLevels[level]); |
207 |
> |
String thresholdString = ""; |
208 |
> |
try { |
209 |
> |
thresholdString = getThresholdConfig(level, _attributeName); |
210 |
> |
} catch (PropertyNotFoundException e) { |
211 |
> |
thresholdString = getThresholdConfig(level, null); |
212 |
> |
} |
213 |
|
threshold = Double.parseDouble(thresholdString); |
214 |
|
} catch (PropertyNotFoundException e) { |
215 |
|
threshold = -1.0; |
225 |
|
* and is converted from the value in the config, |
226 |
|
* which should be seconds. |
227 |
|
* |
228 |
+ |
* Note that if the alert timeout for the current monitor |
229 |
+ |
* is not configured, it will try to obtain the default |
230 |
+ |
* timeout for all Monitor's. If there is no alert timeout |
231 |
+ |
* for either the monitor or a default setting this returns 0. |
232 |
+ |
* |
233 |
|
* Note that this is dependant on the threshold value |
234 |
|
* given, the timeout is obatined from the config, then |
235 |
|
* divided by the threshold value, this allows alerts to |
236 |
|
* progress faster should a higher threshold value be passed |
237 |
|
* |
167 |
– |
* If there is no alert timeout for a |
168 |
– |
* given level, this returns 0 |
169 |
– |
* |
238 |
|
* @param level the alert level |
239 |
|
* @param thresholdLevel the threshold leve we are on |
240 |
|
*/ |
242 |
|
// 0 means we don't use this value |
243 |
|
long timeout = 0; |
244 |
|
try { |
245 |
< |
String timeoutString = _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".alertTimeout." + Alert.alertLevels[level]); |
245 |
> |
String timeoutString; |
246 |
> |
try { |
247 |
> |
timeoutString = _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".alertTimeout." + Alert.alertLevels[level]); |
248 |
> |
} catch (PropertyNotFoundException e) { |
249 |
> |
// if there is no timeout for the monitor |
250 |
> |
// check for a default |
251 |
> |
timeoutString = _cp.getProperty("Host." + _hostname, "Monitor.alertTimeout." + Alert.alertLevels[level]); |
252 |
> |
} |
253 |
|
int threshold = getLastThresholdLevel(); |
254 |
|
if (threshold > 0) { |
255 |
|
timeout = (Long.parseLong(timeoutString) / threshold) * 1000; |
360 |
|
* The monitor this register is for |
361 |
|
*/ |
362 |
|
private String _monitorName; |
363 |
+ |
|
364 |
+ |
/** |
365 |
+ |
* The attribute name, as obtained from |
366 |
+ |
* the configuration. |
367 |
+ |
* eg, idle or /var |
368 |
+ |
*/ |
369 |
+ |
private String _attributeName; |
370 |
|
|
371 |
|
/** |
372 |
|
* An array of last alert levels for |