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.2
Committed: Wed Mar 14 23:25:29 2001 UTC (23 years, 2 months ago) by tdb
Branch: MAIN
Changes since 1.1: +7 -7 lines
Log Message:
The whole server package structure has been changed.
Old Package: uk.ac.ukc.iscream.*
New Package: uk.org.iscream.*

File Contents

# Content
1 //---PACKAGE DECLARATION---
2 package uk.org.iscream.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.client.*;
11 import uk.org.iscream.core.*;
12 import uk.org.iscream.util.*;
13 import uk.org.iscream.componentmanager.*;
14
15 /**
16 * This Monitor watches the Service checks on hosts
17 *
18 * @author $Author: ajm4 $
19 * @version $Id: Services__Monitor.java,v 1.1 2001/03/09 03:33:23 ajm4 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.1 $";
29
30 public final String DESC = "Monitors a hosts services.";
31
32 //---STATIC METHODS---
33
34 //---CONSTRUCTORS---
35
36 //---PUBLIC METHODS---
37
38 public void analysePacket(XMLPacket packet) {
39 if (packet.getParam("packet.attributes.type").equals("heartbeat")) {
40 String source = packet.getParam("packet.attributes.machine_name");
41 if (!_hosts.containsKey(source)) {
42 _hosts.put(source, new HashMap());
43 }
44
45 HashMap serviceRegisters = (HashMap) _hosts.get(source);
46
47 // a tempory holder for all the disk attributes we find
48 ArrayList services = new ArrayList();
49
50 // unfortunatly we need to check the whole packet
51 // to find the disks, and then get the data attributes
52 Set packetSet = packet.getSet();
53 Iterator i = packetSet.iterator();
54 while (i.hasNext()) {
55 String dataKey = (String) i.next();
56 if(dataKey.startsWith("packet.services.")) {
57 if(!services.contains(dataKey)) {
58 String serviceType = "";
59
60 // pos is after "packet.services."
61 int pos = 16;
62 while (dataKey.charAt(pos) != '.') {
63 serviceType = serviceType + dataKey.charAt(pos);
64 pos++;
65 }
66
67 // add the service to our list, with the packet data
68 services.add("packet.services." + serviceType + ".attributes.status");
69 String status = packet.getParam("packet.services." + serviceType + ".attributes.status");
70
71 services.add("packet.services." + serviceType + ".attributes.message");
72 String message = packet.getParam("packet.services." + serviceType + ".attributes.message");
73
74 // *** now process this service ***
75
76 // check if we've seen this service before on a previous run
77 // if not, we need to create a register for it
78 if(!serviceRegisters.containsKey(serviceType)) {
79 serviceRegisters.put(serviceType, new Register(source, _name));
80 }
81
82 // get the register for this service
83 Register reg = (Register) serviceRegisters.get(serviceType);
84
85
86 // as we don't really have a threshold for services,
87 // a temporary fix is to use the status value as a threshold.
88 // after all, a 0 status is a NORMAL threshold ;)
89 int newThreshold = 0;
90 try {
91 newThreshold = Integer.parseInt(status);
92 } catch (NumberFormatException e) {
93 _logger.write(this.toString(), Logger.WARNING, "Received heartbeat from "+source+" with bad service information: "+e);
94 // don't try to continue and go try the next service
95 break;
96 }
97
98 // say which service it was
99 String attributeName = serviceType + " service";
100 String displayValue = "";
101 if (newThreshold == 0) {
102 displayValue = "RUNNING";
103 } else {
104 displayValue = "FAILED";
105 }
106
107 processAlert(newThreshold, attributeName, reg, source, displayValue);
108 }
109 }
110 }
111 }
112 }
113
114 /**
115 * Overrides the {@link java.lang.Object#toString() Object.toString()}
116 * method to provide clean logging (every class should have this).
117 *
118 * This uses the uk.org.iscream.util.NameFormat class
119 * to format the toString()
120 *
121 * @return the name of this class and its CVS revision
122 */
123 public String toString() {
124 return FormatName.getName(
125 _name,
126 getClass().getName(),
127 REVISION);
128 }
129
130 /**
131 * return the String representation of what the monitor does
132 */
133 public String getDescription(){
134 return DESC;
135 }
136
137 //---PRIVATE METHODS---
138
139 //---ACCESSOR/MUTATOR METHODS---
140
141 //---ATTRIBUTES---
142
143 /**
144 * This is the friendly identifier of the
145 * component this class is running in.
146 * eg, a Filter may be called "filter1",
147 * If this class does not have an owning
148 * component, a name from the configuration
149 * can be placed here. This name could also
150 * be changed to null for utility classes.
151 */
152 private String _name = "Services";
153
154 /**
155 * A reference to the configuration proxy in use
156 */
157 private ConfigurationProxy _cp = ConfigurationProxy.getInstance();
158
159 private HashMap _hosts = new HashMap();
160
161 //---STATIC ATTRIBUTES---
162
163 }