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.3
Committed: Thu Mar 22 17:57:06 2001 UTC (23 years, 2 months ago) by ajm
Branch: MAIN
Changes since 1.2: +74 -72 lines
Log Message:
Modified to use the new style queuing in the local client

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