ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/client/monitors/Services__Monitor.java
Revision: 1.5
Committed: Tue May 29 17:02:34 2001 UTC (23 years ago) by tdb
Branch: MAIN
Branch point for: SERVER_PIRCBOT
Changes since 1.4: +9 -9 lines
Log Message:
Major change in the java package naming. This has been held off for some time
now, but it really needed doing. The future packaging of all i-scream products
will be;

uk.org.iscream.<product>.<subpart>.*

In the case of the central monitoring system server this will be;

uk.org.iscream.cms.server.*

The whole server has been changed to follow this structure, and tested to a
smallish extent. Further changes in other parts of the CMS will follow.

File Contents

# Content
1 //---PACKAGE DECLARATION---
2 package uk.org.iscream.cms.server.client.monitors;
3
4 //---IMPORTS---
5 import java.util.HashMap;
6 import java.util.ArrayList;
7 import java.util.Set;
8 import java.util.Iterator;
9 import java.text.NumberFormat;
10 import uk.org.iscream.cms.server.client.*;
11 import uk.org.iscream.cms.server.core.*;
12 import uk.org.iscream.cms.server.util.*;
13 import uk.org.iscream.cms.server.componentmanager.*;
14
15 /**
16 * This Monitor watches the Service checks on hosts
17 *
18 * @author $Author: tdb1 $
19 * @version $Id: Services__Monitor.java,v 1.4 2001/03/23 02:32:49 tdb1 Exp $
20 */
21 public class Services__Monitor extends MonitorSkeleton {
22
23 //---FINAL ATTRIBUTES---
24
25 /**
26 * The current CVS revision of this class
27 */
28 public final String REVISION = "$Revision: 1.4 $";
29
30 /**
31 * A description of this monitor
32 */
33 public final String DESC = "Monitors a hosts services.";
34
35 //---STATIC METHODS---
36
37 //---CONSTRUCTORS---
38
39 //---PUBLIC METHODS---
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)) {
50 _hosts.put(source, new HashMap());
51 }
52
53 HashMap serviceRegisters = (HashMap) _hosts.get(source);
54
55 // a tempory holder for all the disk attributes we find
56 ArrayList services = new ArrayList();
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(keyPrefix)) {
68 if(!services.contains(dataKey)) {
69 String serviceType = "";
70
71 // pos is after "packet.services."
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(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
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
93 // get the register for this service
94 Register reg = (Register) serviceRegisters.get(serviceType);
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 ;)
100 int newThreshold = 0;
101 try {
102 newThreshold = Integer.parseInt(status);
103 } catch (NumberFormatException e) {
104 _logger.write(this.toString(), Logger.WARNING, "Received heartbeat from "+source+" with bad service information: "+e);
105 // don't try to continue and go try the next service
106 break;
107 }
108
109 // say which service it was
110 String attributeName = serviceType + " service";
111 String displayValue = "";
112 if (newThreshold == 0) {
113 displayValue = "RUNNING";
114 } else {
115 displayValue = "FAILED";
116 }
117
118 processAlert(newThreshold, attributeName, reg, source, displayValue);
119 }
120 }
121 }
122 }
123
124 /**
125 * Overrides the {@link java.lang.Object#toString() Object.toString()}
126 * method to provide clean logging (every class should have this).
127 *
128 * This uses the uk.org.iscream.cms.server.util.NameFormat class
129 * to format the toString()
130 *
131 * @return the name of this class and its CVS revision
132 */
133 public String toString() {
134 return FormatName.getName(
135 _name,
136 getClass().getName(),
137 REVISION);
138 }
139
140 /**
141 * return the String representation of what the monitor does
142 */
143 public String getDescription(){
144 return DESC;
145 }
146
147 //---PRIVATE METHODS---
148
149 //---ACCESSOR/MUTATOR METHODS---
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 }
161
162 //---ATTRIBUTES---
163
164 /**
165 * This is the friendly identifier of the
166 * component this class is running in.
167 * eg, a Filter may be called "filter1",
168 * If this class does not have an owning
169 * component, a name from the configuration
170 * can be placed here. This name could also
171 * be changed to null for utility classes.
172 */
173 private String _name = "Services";
174
175 /**
176 * A HashMap of Registers (or groups of Registers), one
177 * for each host we're monitoring.
178 */
179 private HashMap _hosts = new HashMap();
180
181 //---STATIC ATTRIBUTES---
182
183 }