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.2 by tdb, Wed Mar 14 23:25:29 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 <        if (packet.getParam("packet.attributes.type").equals("heartbeat")) {
69 <            String source = packet.getParam("packet.attributes.machine_name");
70 <            if (!_hosts.containsKey(source)) {
71 <                _hosts.put(source, new HashMap());
72 <            }
73 <                        
74 <            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 <                        }
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 >        }
75  
76 <                        // get the register for this service
77 <                        Register reg = (Register) serviceRegisters.get(serviceType);
78 <                        
79 <                        
80 <                        // as we don't really have a threshold for services,
81 <                        // a temporary fix is to use the status value as a threshold.
82 <                        // after all, a 0 status is a NORMAL threshold ;)
83 <                        int newThreshold = 0;
84 <                        try {
85 <                            newThreshold = Integer.parseInt(status);
86 <                        } catch (NumberFormatException e) {
87 <                            _logger.write(this.toString(), Logger.WARNING, "Received heartbeat from "+source+" with bad service information: "+e);
88 <                            // don't try to continue and go try the next service
89 <                            break;
90 <                        }
91 <                                      
92 <                        // say which service it was
93 <                        String attributeName = serviceType + " service";
94 <                        String displayValue = "";
95 <                        if (newThreshold == 0) {
96 <                            displayValue = "RUNNING";
97 <                        } else {
98 <                            displayValue = "FAILED";
105 <                        }
106 <                                                
107 <                        processAlert(newThreshold, attributeName, reg, source, displayValue);
76 >        HashMap serviceRegisters = (HashMap) _hosts.get(source);
77 >
78 >        // a tempory holder for all the disk attributes we find
79 >        ArrayList services = new ArrayList();
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(keyPrefix)) {
91 >                if(!services.contains(dataKey)) {
92 >                    String serviceType = "";
93 >                    
94 >                    // pos is after "packet.services."
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(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 +                    
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 +                    
116 +                    // get the register for this service
117 +                    Register reg = (Register) serviceRegisters.get(serviceType);
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 ;)
123 +                    int newThreshold = 0;
124 +                    try {
125 +                        newThreshold = Integer.parseInt(status);
126 +                    } catch (NumberFormatException e) {
127 +                        _logger.write(this.toString(), Logger.WARNING, "Received heartbeat from "+source+" with bad service information: "+e);
128 +                        // don't try to continue and go try the next service
129 +                        break;
130 +                    }
131 +                    
132 +                    // say which service it was
133 +                    String attributeName = serviceType + " service";
134 +                    String displayValue = "";
135 +                    if (newThreshold == 0) {
136 +                        displayValue = "RUNNING";
137 +                    } else {
138 +                        displayValue = "FAILED";
139 +                    }
140 +                    
141 +                    processAlert(newThreshold, attributeName, reg, source, displayValue);
142                  }
143              }
144          }
# Line 115 | 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 137 | Line 170 | public class Services__Monitor extends MonitorSkeleton
170   //---PRIVATE METHODS---
171  
172   //---ACCESSOR/MUTATOR METHODS---
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().getOtherQueue();
183 +    }
184  
185   //---ATTRIBUTES---
186  
# Line 152 | 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       */
157    private ConfigurationProxy _cp = ConfigurationProxy.getInstance();
158
202      private HashMap _hosts = new HashMap();
203  
204   //---STATIC ATTRIBUTES---

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines