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/Register.java
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/client/Register.java (file contents):
Revision 1.11 by ajm, Fri Mar 9 03:30:54 2001 UTC vs.
Revision 1.20 by tdb, Wed Feb 5 16:43:45 2003 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.ac.ukc.iscream.client;
22 > package uk.org.iscream.cms.server.client;
23  
24   //---IMPORTS---
25 < import uk.ac.ukc.iscream.util.*;
26 < import uk.ac.ukc.iscream.componentmanager.*;
25 > import uk.org.iscream.cms.util.*;
26 > import uk.org.iscream.cms.server.componentmanager.*;
27  
28   /**
29   * The Register class holds theshold values,
# Line 34 | Line 54 | public class Register {
54      /**
55       * Construct a Register with the hostname and monitorName
56       * (for obtaining the threshold values).
57 +     * This constructs a generic register for a specific monitor.
58       *
59       * @param hostname the hostname this register is for
60       * @param monitorName the monitor this register is for
40
61       */
62      public Register(String hostname, String monitorName) {
63 +        this(hostname, monitorName, null);    
64 +    }
65 +
66 +    /**
67 +     * Construct a Register with the hostname and monitorName
68 +     * (for obtaining the threshold values).
69 +     * This constructs a register for a specific attribute check
70 +     * by a monitor.
71 +     *
72 +     * @param hostname the hostname this register is for
73 +     * @param monitorName the monitor this register is for
74 +     * @param attributeName the specific attribute this register is for
75 +     */
76 +    public Register(String hostname, String monitorName, String attributeName) {
77          _hostname = hostname;
78          _monitorName = monitorName;
79 +        _attributeName = attributeName;
80          _lastAlertLevel = 0;
81          _lastThresholdLevel = 0;
82          _initialAlertTime= 0;
# Line 52 | Line 87 | public class Register {
87              _times[x] = 0;
88          }
89      }
90 +        
91  
92   //---PUBLIC METHODS---
93  
94   //---PRIVATE METHODS---
95  
96 +    /**
97 +     * Obtains a threshold value from the configuration for a given level.
98 +     * The attribute name specifies which property to get.
99 +     * eg, attributeName = idle it will look for
100 +     *     Monitor.<monitor name>.idle.threshold.<alert level>
101 +     * eg, attributeName = null
102 +     *     Monitor.<monitor name>.threshold.<alert level>
103 +     *
104 +     * Note that if its null, this will get the threshold for the monitor
105 +     * as a whole, not the specific attribute.
106 +     *
107 +     * @param level the alert level to get the attribute for
108 +     * @param attributeName the attribute to get the threshold for
109 +     *
110 +     * @return the threshold obtained
111 +     */    
112 +    private String getThresholdConfig(int level, String attributeName) throws PropertyNotFoundException {
113 +        String temp = "";
114 +        if (attributeName != null) {
115 +            temp = "." + attributeName;
116 +        }
117 +        return _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + temp + ".threshold." + Alert.thresholdLevels[level]);
118 +    }
119 +
120   //---ACCESSOR/MUTATOR METHODS---
121      
122      /**
# Line 102 | Line 162 | public class Register {
162          _lastAlertLevel = level;
163          if (level == Alert.alertOK) {
164              _maxLevelCount = 0;
165 <            _initialAlertTime = 0;
165 >            // we won't do this, so OK's still have the initialAlertTime
166 >            // of the original alert they're OK'ing
167 >            //_initialAlertTime = 0;
168          }
169          if (level == Alert.alertOK + 1) {
170              _initialAlertTime = System.currentTimeMillis();
# Line 143 | Line 205 | public class Register {
205          // -1.0 means we don't use an alert level
206          double threshold = -1.0;
207          try {
208 <            String thresholdString = _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".threshold." + Alert.thresholdLevels[level]);
208 >            String thresholdString = "";
209 >            try {
210 >                thresholdString = getThresholdConfig(level, _attributeName);
211 >            } catch (PropertyNotFoundException e) {
212 >                thresholdString = getThresholdConfig(level, null);
213 >            }
214              threshold = Double.parseDouble(thresholdString);
215          } catch (PropertyNotFoundException e) {
216              threshold = -1.0;
# Line 159 | Line 226 | public class Register {
226       * and is converted from the value in the config,
227       * which should be seconds.
228       *
229 +     * Note that if the alert timeout for the current monitor
230 +     * is not configured, it will try to obtain the default
231 +     * timeout for all Monitor's.  If there is no alert timeout
232 +     * for either the monitor or a default setting this returns 0.
233 +     *
234       * Note that this is dependant on the threshold value
235       * given, the timeout is obatined from the config, then
236       * divided by the threshold value, this allows alerts to
237       * progress faster should a higher threshold value be passed
238       *
167     * If there is no alert timeout for a
168     * given level, this returns 0
169     *
239       * @param level the alert level
240       * @param thresholdLevel the threshold leve we are on
241       */
# Line 174 | Line 243 | public class Register {
243          // 0 means we don't use this value
244          long timeout = 0;
245          try {
246 <            String timeoutString = _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".alertTimeout." + Alert.alertLevels[level]);
246 >            String timeoutString;
247 >            try {
248 >                timeoutString = _cp.getProperty("Host." + _hostname, "Monitor." + _monitorName + ".alertTimeout." + Alert.alertLevels[level]);
249 >            } catch (PropertyNotFoundException e) {
250 >                // if there is no timeout for the monitor
251 >                // check for a default
252 >                timeoutString = _cp.getProperty("Host." + _hostname, "Monitor.alertTimeout." + Alert.alertLevels[level]);
253 >            }    
254              int threshold = getLastThresholdLevel();
255              if (threshold > 0) {
256                  timeout = (Long.parseLong(timeoutString) / threshold) * 1000;
# Line 285 | Line 361 | public class Register {
361       * The monitor this register is for
362       */
363      private String _monitorName;
364 +    
365 +    /**
366 +     * The attribute name, as obtained from
367 +     * the configuration.
368 +     * eg, idle or /var
369 +     */
370 +    private String _attributeName;
371  
372      /**
373       * An array of last alert levels for

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines