KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > jmx > adaptor > snmp > system > MIB2SystemGroupService


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.jmx.adaptor.snmp.system;
23
24 import javax.management.ObjectName JavaDoc;
25
26 import org.jboss.jmx.adaptor.snmp.agent.SnmpAgentServiceMBean;
27 import org.jboss.system.ServiceMBeanSupport;
28 import org.jboss.system.server.ServerConfigLocator;
29 import org.jboss.system.server.ServerInfoMBean;
30 import org.opennms.protocols.snmp.SnmpObjectId;
31
32 /**
33  * An MBean service that defines the MIB-2 system group an agent
34  * is supposed to implement under the oid
35  * iso.org.dod.internet.mgmt.mib-2.system (.1.3.6.1.2.1.1)
36  * See rfc-1213
37  *
38  * @author <a HREF="mailto:hwr@pilhuhn.de">Heiko W. Rupp</a>
39  * @author <a HREF="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
40  * @version $Revision: 57108 $
41  */

42 public class MIB2SystemGroupService extends ServiceMBeanSupport
43    implements MIB2SystemGroupServiceMBean
44 {
45    // Constants -----------------------------------------------------
46

47    /** JBoss OID Prefix */
48    public static final String JavaDoc JBOSS_PREFIX = "1.3.6.1.4.1.18016";
49    
50    /** Product JBossAS */
51     public static final String JavaDoc PRODUCT = ".1.1";
52    
53    /** Version 4.0.x */
54     public static final String JavaDoc VERSION = ".2";
55    
56    // Private Data --------------------------------------------------
57

58     private String JavaDoc sysDescr; // system.1
59
private SnmpObjectId sysObjectId; // system.2
60
// private long sysUpTime; // system.3
61
private String JavaDoc sysContact; // system.4
62
private String JavaDoc sysName; // system.5 usually fqdn
63
private String JavaDoc sysLocation; // system.6 where is the system located
64
private final int sysServices = 64; // system.7 (2^(L-1) with L=Layer 7 services)
65

66     private ObjectName JavaDoc snmpAgent = SnmpAgentServiceMBean.OBJECT_NAME;
67     
68     /**
69     * CTOR
70      *
71      */

72     public MIB2SystemGroupService()
73    {
74       // empty
75
}
76    
77    // Attributes ----------------------------------------------------
78

79    /**
80     * @jmx:managed-attribute
81     */

82     public void setSnmpAgent(ObjectName JavaDoc agent)
83    {
84       this.snmpAgent = agent;
85    }
86    
87    /**
88     * @jmx:managed-attribute
89     */

90    public ObjectName JavaDoc getSnmpAgent()
91    {
92       return snmpAgent;
93    }
94    
95    /**
96     * @jmx:managed-attribute
97     */

98    public void setSysDescr(String JavaDoc sysDescr)
99    {
100       this.sysDescr = sysDescr;
101    }
102    
103    /**
104     * @jmx:managed-attribute
105     */

106    public String JavaDoc getSysDescr()
107    {
108       return sysDescr;
109    }
110    
111    /**
112     * @jmx:managed-attribute
113     */

114    public SnmpObjectId getSysObjectId()
115    {
116       return sysObjectId;
117    }
118
119    /**
120     * The system uptime in hundreth of a second (TimeTicks)
121     * @jmx:managed-attribute
122     */

123    public long getSysUpTime()
124    {
125       if (snmpAgent !=null)
126       {
127          try
128          {
129             Long JavaDoc upTime = (Long JavaDoc)server.getAttribute(snmpAgent, "Uptime");
130             return upTime.longValue() / 10;
131          }
132          catch (Exception JavaDoc e)
133          {
134             log.debug("Can't get uptime value from agent");
135          }
136       }
137       // fallback
138
return System.currentTimeMillis() / 10;
139    }
140    
141    /**
142     * @jmx:managed-attribute
143     */

144    public void setSysContact(String JavaDoc sysContact)
145    {
146       this.sysContact = sysContact;
147    }
148    
149    /**
150     * @jmx:managed-attribute
151     */

152    public String JavaDoc getSysContact()
153    {
154       return sysContact;
155    }
156   
157    /**
158     * @jmx:managed-attribute
159     */

160    public void setSysName(String JavaDoc sysName)
161    {
162       this.sysName = sysName;
163    }
164    
165    /**
166     * @jmx:managed-attribute
167     */

168    public String JavaDoc getSysName()
169    {
170       return sysName;
171    }
172    
173    /**
174     * @jmx:managed-attribute
175     */

176    public void setSysLocation(String JavaDoc sysLocation)
177    {
178       this.sysLocation = sysLocation;
179    }
180    
181    /**
182     * @jmx:managed-attribute
183     */

184    public String JavaDoc getSysLocation()
185    {
186       return sysLocation;
187    }
188    
189    /**
190     * @jmx:managed-attribute
191     */

192    public int getSysServices()
193    {
194       return sysServices;
195    }
196
197    // Lifecycle -----------------------------------------------------
198

199    protected void createService() throws Exception JavaDoc
200    {
201       // Determine the sysName from the running server config and the host name.
202
if (this.sysName == null)
203       {
204          String JavaDoc serverConfig = ServerConfigLocator.locate().getServerName();
205          ObjectName JavaDoc name = new ObjectName JavaDoc(ServerInfoMBean.OBJECT_NAME_STR);
206          String JavaDoc hostAddress = (String JavaDoc)server.getAttribute(name, "HostAddress");
207
208          this.sysName = serverConfig + "@" + hostAddress;
209          log.debug("Setting sysName name to " + sysName);
210       }
211       this.sysObjectId = new SnmpObjectId(JBOSS_PREFIX + PRODUCT + VERSION);
212    }
213    
214 }
215
Popular Tags