27 |
|
*/ |
28 |
|
public final String REVISION = "$Revision$"; |
29 |
|
|
30 |
+ |
/** |
31 |
+ |
* A description of this monitor |
32 |
+ |
*/ |
33 |
|
public final String DESC = "Monitors a hosts services."; |
34 |
|
|
35 |
|
//---STATIC METHODS--- |
37 |
|
//---CONSTRUCTORS--- |
38 |
|
|
39 |
|
//---PUBLIC METHODS--- |
40 |
< |
|
40 |
> |
|
41 |
> |
/** |
42 |
> |
* Analyse a packet of data, and generate an alert if |
43 |
> |
* necessary. |
44 |
> |
* |
45 |
> |
* @param packet the XMLPacket to analyse |
46 |
> |
*/ |
47 |
|
public void analysePacket(XMLPacket packet) { |
48 |
|
String source = packet.getParam("packet.attributes.machine_name"); |
49 |
|
if (!_hosts.containsKey(source)) { |
54 |
|
|
55 |
|
// a tempory holder for all the disk attributes we find |
56 |
|
ArrayList services = new ArrayList(); |
57 |
< |
|
57 |
> |
|
58 |
> |
// the prefix for keys relating to service checks |
59 |
> |
String keyPrefix = "packet.services."; |
60 |
> |
|
61 |
|
// unfortunatly we need to check the whole packet |
62 |
|
// to find the disks, and then get the data attributes |
63 |
|
Set packetSet = packet.getSet(); |
64 |
|
Iterator i = packetSet.iterator(); |
65 |
|
while (i.hasNext()) { |
66 |
|
String dataKey = (String) i.next(); |
67 |
< |
if(dataKey.startsWith("packet.services.")) { |
67 |
> |
if(dataKey.startsWith(keyPrefix)) { |
68 |
|
if(!services.contains(dataKey)) { |
69 |
|
String serviceType = ""; |
70 |
< |
|
70 |
> |
|
71 |
|
// pos is after "packet.services." |
72 |
< |
int pos = 16; |
72 |
> |
int pos = keyPrefix.length(); |
73 |
|
while (dataKey.charAt(pos) != '.') { |
74 |
|
serviceType = serviceType + dataKey.charAt(pos); |
75 |
|
pos++; |
76 |
|
} |
77 |
< |
|
78 |
< |
// add the service to our list, with the packet data |
79 |
< |
services.add("packet.services." + serviceType + ".attributes.status"); |
80 |
< |
String status = packet.getParam("packet.services." + serviceType + ".attributes.status"); |
81 |
< |
|
82 |
< |
services.add("packet.services." + serviceType + ".attributes.message"); |
83 |
< |
String message = packet.getParam("packet.services." + serviceType + ".attributes.message"); |
84 |
< |
|
77 |
> |
|
78 |
> |
// add the service to our list, with the packet data |
79 |
> |
services.add(keyPrefix + serviceType + ".attributes.status"); |
80 |
> |
String status = packet.getParam(keyPrefix + serviceType + ".attributes.status"); |
81 |
> |
|
82 |
> |
services.add(keyPrefix + serviceType + ".attributes.message"); |
83 |
> |
String message = packet.getParam(keyPrefix + serviceType + ".attributes.message"); |
84 |
> |
|
85 |
|
// *** now process this service *** |
86 |
< |
|
86 |
> |
|
87 |
|
// check if we've seen this service before on a previous run |
88 |
|
// if not, we need to create a register for it |
89 |
|
if(!serviceRegisters.containsKey(serviceType)) { |
90 |
|
serviceRegisters.put(serviceType, new Register(source, _name)); |
91 |
|
} |
92 |
< |
|
92 |
> |
|
93 |
|
// get the register for this service |
94 |
|
Register reg = (Register) serviceRegisters.get(serviceType); |
95 |
< |
|
96 |
< |
|
95 |
> |
|
96 |
> |
|
97 |
|
// as we don't really have a threshold for services, |
98 |
|
// a temporary fix is to use the status value as a threshold. |
99 |
|
// after all, a 0 status is a NORMAL threshold ;) |
105 |
|
// don't try to continue and go try the next service |
106 |
|
break; |
107 |
|
} |
108 |
< |
|
108 |
> |
|
109 |
|
// say which service it was |
110 |
|
String attributeName = serviceType + " service"; |
111 |
|
String displayValue = ""; |
114 |
|
} else { |
115 |
|
displayValue = "FAILED"; |
116 |
|
} |
117 |
< |
|
117 |
> |
|
118 |
|
processAlert(newThreshold, attributeName, reg, source, displayValue); |
119 |
|
} |
120 |
|
} |
147 |
|
//---PRIVATE METHODS--- |
148 |
|
|
149 |
|
//---ACCESSOR/MUTATOR METHODS--- |
150 |
< |
|
150 |
> |
|
151 |
> |
/** |
152 |
> |
* Returns a reference to a specific Queue for this |
153 |
> |
* monitor. This Queue returns only the data packets |
154 |
> |
* (based on type) that we want too look at. |
155 |
> |
* |
156 |
> |
* @return a reference to a Queue |
157 |
> |
*/ |
158 |
|
protected Queue getQueue() { |
159 |
|
return MonitorManager.getInstance().getHeartbeatQueue(); |
160 |
|
} |
173 |
|
private String _name = "Services"; |
174 |
|
|
175 |
|
/** |
176 |
< |
* A reference to the configuration proxy in use |
176 |
> |
* A HashMap of Registers (or groups of Registers), one |
177 |
> |
* for each host we're monitoring. |
178 |
|
*/ |
159 |
– |
private ConfigurationProxy _cp = ConfigurationProxy.getInstance(); |
160 |
– |
|
179 |
|
private HashMap _hosts = new HashMap(); |
180 |
|
|
181 |
|
//---STATIC ATTRIBUTES--- |