1 |
+ |
/* |
2 |
+ |
* i-scream central monitoring system |
3 |
+ |
* http://www.i-scream.org |
4 |
+ |
* Copyright (C) 2000-2002 i-scream |
5 |
+ |
* |
6 |
+ |
* This program is free software; you can redistribute it and/or |
7 |
+ |
* modify it under the terms of the GNU General Public License |
8 |
+ |
* as published by the Free Software Foundation; either version 2 |
9 |
+ |
* of the License, or (at your option) any later version. |
10 |
+ |
* |
11 |
+ |
* This program is distributed in the hope that it will be useful, |
12 |
+ |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
+ |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
+ |
* GNU General Public License for more details. |
15 |
+ |
* |
16 |
+ |
* You should have received a copy of the GNU General Public License |
17 |
+ |
* along with this program; if not, write to the Free Software |
18 |
+ |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 |
+ |
*/ |
20 |
+ |
|
21 |
|
//---PACKAGE DECLARATION--- |
22 |
|
package uk.org.iscream.cms.server.client; |
23 |
|
|
25 |
|
import java.util.HashMap; |
26 |
|
import uk.org.iscream.cms.server.client.*; |
27 |
|
import uk.org.iscream.cms.server.core.*; |
28 |
< |
import uk.org.iscream.cms.server.util.*; |
28 |
> |
import uk.org.iscream.cms.util.*; |
29 |
|
import uk.org.iscream.cms.server.componentmanager.*; |
30 |
|
|
31 |
|
/** |
68 |
|
public void run() { |
69 |
|
while(_running) { |
70 |
|
try { |
71 |
< |
analysePacket((XMLPacket) getQueue().get(getQueueId())); |
71 |
> |
// check if monitoring is enabled for this host |
72 |
> |
// if not - just don't bother analyse it's packets |
73 |
> |
XMLPacket packet = (XMLPacket) getQueue().get(getQueueId()); |
74 |
> |
String source = packet.getParam("packet.attributes.machine_name"); |
75 |
> |
boolean enabled = checkBooleanConfig("Host." + source, "Monitor.enable"); |
76 |
> |
if(enabled) { |
77 |
> |
analysePacket(packet); |
78 |
> |
} |
79 |
> |
else { |
80 |
> |
_logger.write(this.toString(), Logger.DEBUG, "Skipping monitoring of host: " + source); |
81 |
> |
} |
82 |
|
} catch (InvalidQueueException e) { |
83 |
|
_logger.write(this.toString(), Logger.ERROR, "Unable to get queue."); |
84 |
|
} |
158 |
|
*/ |
159 |
|
public abstract String getDescription(); |
160 |
|
|
161 |
+ |
/** |
162 |
+ |
* Checks a boolean configuration variable. |
163 |
+ |
* |
164 |
+ |
* @param source the configuration to look up |
165 |
+ |
* @param name the key to look up |
166 |
+ |
*/ |
167 |
+ |
protected boolean checkBooleanConfig(String source, String name) { |
168 |
+ |
boolean enabled = true; |
169 |
+ |
try { |
170 |
+ |
int e = Integer.parseInt(_cp.getProperty(source, name)); |
171 |
+ |
enabled = (e == 1); |
172 |
+ |
} catch (PropertyNotFoundException e) { |
173 |
+ |
enabled = false; |
174 |
+ |
} catch (NumberFormatException e) { |
175 |
+ |
enabled = false; |
176 |
+ |
} |
177 |
+ |
return enabled; |
178 |
+ |
} |
179 |
|
|
180 |
|
//---PRIVATE METHODS--- |
181 |
|
|
213 |
|
/** |
214 |
|
* Obtain the queue which contains the data |
215 |
|
* the Monitor is reading. |
216 |
< |
* eg, MonitorManager.getInstance().getHeartbeatQueue() |
216 |
> |
* eg, MonitorManager.getInstance().getDataQueue() |
217 |
|
*/ |
218 |
|
protected abstract Queue getQueue(); |
219 |
|
|
242 |
|
* all new alerts will be placed. |
243 |
|
*/ |
244 |
|
protected Queue _alerterQueue = AlerterManager.getInstance().getQueue(); |
245 |
< |
|
245 |
> |
|
246 |
> |
/** |
247 |
> |
* A reference to the configuration proxy in use |
248 |
> |
*/ |
249 |
> |
private ConfigurationProxy _cp = ConfigurationProxy.getInstance(); |
250 |
> |
|
251 |
|
/** |
252 |
|
* The ID of the queue the monitor will use. |
253 |
|
* Initially -1, but initialised on first use. |