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
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/client/monitors/Services__Monitor.java (file contents):
Revision 1.3 by ajm, Thu Mar 22 17:57:06 2001 UTC vs.
Revision 1.11 by tdb, Thu Jan 15 14:10:13 2004 UTC

# Line 1 | Line 1
1 + /*
2 + * i-scream central monitoring system
3 + * http://www.i-scream.org.uk
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.client.monitors;
22 > package uk.org.iscream.cms.server.client.monitors;
23  
24   //---IMPORTS---
25   import java.util.HashMap;
# Line 7 | Line 27 | import java.util.ArrayList;
27   import java.util.Set;
28   import java.util.Iterator;
29   import java.text.NumberFormat;
30 < import uk.org.iscream.client.*;
31 < import uk.org.iscream.core.*;
32 < import uk.org.iscream.util.*;
33 < import uk.org.iscream.componentmanager.*;
30 > import uk.org.iscream.cms.server.client.*;
31 > import uk.org.iscream.cms.server.core.*;
32 > import uk.org.iscream.cms.util.*;
33 > import uk.org.iscream.cms.server.componentmanager.*;
34  
35   /**
36   * This Monitor watches the Service checks on hosts
# Line 27 | Line 47 | public class Services__Monitor extends MonitorSkeleton
47       */
48      public final String REVISION = "$Revision$";
49      
50 +    /**
51 +     * A description of this monitor
52 +     */
53      public final String DESC = "Monitors a hosts services.";
54      
55   //---STATIC METHODS---
# Line 34 | Line 57 | public class Services__Monitor extends MonitorSkeleton
57   //---CONSTRUCTORS---
58  
59   //---PUBLIC METHODS---
60 <
60 >    
61 >    /**
62 >     * Analyse a packet of data, and generate an alert if
63 >     * necessary.
64 >     *
65 >     * @param packet the XMLPacket to analyse
66 >     */
67      public void analysePacket(XMLPacket packet) {
68          String source = packet.getParam("packet.attributes.machine_name");
69 +        if(!checkBooleanConfig("Host." + source, "Monitor." + _name + ".enable")) {
70 +            return;
71 +        }
72          if (!_hosts.containsKey(source)) {
73              _hosts.put(source, new HashMap());
74          }
# Line 45 | Line 77 | public class Services__Monitor extends MonitorSkeleton
77  
78          // a tempory holder for all the disk attributes we find
79          ArrayList services = new ArrayList();
80 <
80 >        
81 >        // the prefix for keys relating to service checks
82 >        String keyPrefix = "packet.services.";
83 >        
84          // unfortunatly we need to check the whole packet
85          // to find the disks, and then get the data attributes
86          Set packetSet = packet.getSet();
87          Iterator i = packetSet.iterator();
88          while (i.hasNext()) {
89              String dataKey = (String) i.next();
90 <            if(dataKey.startsWith("packet.services.")) {
90 >            if(dataKey.startsWith(keyPrefix)) {
91                  if(!services.contains(dataKey)) {
92                      String serviceType = "";
93 <
93 >                    
94                      // pos is after "packet.services."
95 <                    int pos = 16;
95 >                    int pos = keyPrefix.length();
96                      while (dataKey.charAt(pos) != '.') {
97                          serviceType = serviceType + dataKey.charAt(pos);
98                          pos++;
99                      }
100 <
101 <                     // add the service to our list, with the packet data                      
102 <                    services.add("packet.services." + serviceType + ".attributes.status");
103 <                    String status = packet.getParam("packet.services." + serviceType + ".attributes.status");
104 <
105 <                    services.add("packet.services." + serviceType + ".attributes.message");
106 <                    String message = packet.getParam("packet.services." + serviceType + ".attributes.message");
107 <
100 >                    
101 >                    // add the service to our list, with the packet data                      
102 >                    services.add(keyPrefix + serviceType + ".attributes.status");
103 >                    String status = packet.getParam(keyPrefix + serviceType + ".attributes.status");
104 >                    
105 >                    services.add(keyPrefix + serviceType + ".attributes.message");
106 >                    String message = packet.getParam(keyPrefix + serviceType + ".attributes.message");
107 >                    
108                      // *** now process this service ***
109 <
109 >                    
110                      // check if we've seen this service before on a previous run
111                      // if not, we need to create a register for it
112                      if(!serviceRegisters.containsKey(serviceType)) {
113                          serviceRegisters.put(serviceType, new Register(source, _name));
114                      }
115 <
115 >                    
116                      // get the register for this service
117                      Register reg = (Register) serviceRegisters.get(serviceType);
118 <
119 <
118 >                    
119 >                    
120                      // as we don't really have a threshold for services,
121                      // a temporary fix is to use the status value as a threshold.
122                      // after all, a 0 status is a NORMAL threshold ;)
# Line 93 | Line 128 | public class Services__Monitor extends MonitorSkeleton
128                          // don't try to continue and go try the next service
129                          break;
130                      }
131 <
131 >                    
132                      // say which service it was
133                      String attributeName = serviceType + " service";
134                      String displayValue = "";
# Line 102 | Line 137 | public class Services__Monitor extends MonitorSkeleton
137                      } else {
138                          displayValue = "FAILED";
139                      }
140 <
140 >                    
141                      processAlert(newThreshold, attributeName, reg, source, displayValue);
142                  }
143              }
# Line 113 | Line 148 | public class Services__Monitor extends MonitorSkeleton
148       * Overrides the {@link java.lang.Object#toString() Object.toString()}
149       * method to provide clean logging (every class should have this).
150       *
151 <     * This uses the uk.org.iscream.util.NameFormat class
151 >     * This uses the uk.org.iscream.cms.util.NameFormat class
152       * to format the toString()
153       *
154       * @return the name of this class and its CVS revision
# Line 135 | Line 170 | public class Services__Monitor extends MonitorSkeleton
170   //---PRIVATE METHODS---
171  
172   //---ACCESSOR/MUTATOR METHODS---
173 <
173 >    
174 >    /**
175 >     * Returns a reference to a specific Queue for this
176 >     * monitor. This Queue returns only the data packets
177 >     * (based on type) that we want too look at.
178 >     *
179 >     * @return a reference to a Queue
180 >     */
181      protected Queue getQueue() {
182 <        return MonitorManager.getInstance().getHeartbeatQueue();
182 >        return MonitorManager.getInstance().getOtherQueue();
183      }
184  
185   //---ATTRIBUTES---
# Line 154 | Line 196 | public class Services__Monitor extends MonitorSkeleton
196      private String _name = "Services";
197      
198      /**
199 <     * A reference to the configuration proxy in use
199 >     * A HashMap of Registers (or groups of Registers), one
200 >     * for each host we're monitoring.
201       */
159    private ConfigurationProxy _cp = ConfigurationProxy.getInstance();
160
202      private HashMap _hosts = new HashMap();
203  
204   //---STATIC ATTRIBUTES---

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines