001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.jmx.adaptor.snmp.system;
023:
024: import javax.management.ObjectName;
025:
026: import org.jboss.jmx.adaptor.snmp.agent.SnmpAgentServiceMBean;
027: import org.jboss.system.ServiceMBeanSupport;
028: import org.jboss.system.server.ServerConfigLocator;
029: import org.jboss.system.server.ServerInfoMBean;
030: import org.opennms.protocols.snmp.SnmpObjectId;
031:
032: /**
033: * An MBean service that defines the MIB-2 system group an agent
034: * is supposed to implement under the oid
035: * iso.org.dod.internet.mgmt.mib-2.system (.1.3.6.1.2.1.1)
036: * See rfc-1213
037: *
038: * @author <a href="mailto:hwr@pilhuhn.de">Heiko W. Rupp</a>
039: * @author <a href="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
040: * @version $Revision: 57210 $
041: */
042: public class MIB2SystemGroupService extends ServiceMBeanSupport
043: implements MIB2SystemGroupServiceMBean {
044: // Constants -----------------------------------------------------
045:
046: /** JBoss OID Prefix */
047: public static final String JBOSS_PREFIX = "1.3.6.1.4.1.18016";
048:
049: /** Product JBossAS */
050: public static final String PRODUCT = ".1.1";
051:
052: /** Version 4.0.x */
053: public static final String VERSION = ".2";
054:
055: // Private Data --------------------------------------------------
056:
057: private String sysDescr; // system.1
058: private SnmpObjectId sysObjectId; // system.2
059: // private long sysUpTime; // system.3
060: private String sysContact; // system.4
061: private String sysName; // system.5 usually fqdn
062: private String sysLocation; // system.6 where is the system located
063: private final int sysServices = 64; // system.7 (2^(L-1) with L=Layer 7 services)
064:
065: private ObjectName snmpAgent = SnmpAgentServiceMBean.OBJECT_NAME;
066:
067: /**
068: * CTOR
069: *
070: */
071: public MIB2SystemGroupService() {
072: // empty
073: }
074:
075: // Attributes ----------------------------------------------------
076:
077: /**
078: * @jmx:managed-attribute
079: */
080: public void setSnmpAgent(ObjectName agent) {
081: this .snmpAgent = agent;
082: }
083:
084: /**
085: * @jmx:managed-attribute
086: */
087: public ObjectName getSnmpAgent() {
088: return snmpAgent;
089: }
090:
091: /**
092: * @jmx:managed-attribute
093: */
094: public void setSysDescr(String sysDescr) {
095: this .sysDescr = sysDescr;
096: }
097:
098: /**
099: * @jmx:managed-attribute
100: */
101: public String getSysDescr() {
102: return sysDescr;
103: }
104:
105: /**
106: * @jmx:managed-attribute
107: */
108: public SnmpObjectId getSysObjectId() {
109: return sysObjectId;
110: }
111:
112: /**
113: * The system uptime in hundreth of a second (TimeTicks)
114: * @jmx:managed-attribute
115: */
116: public long getSysUpTime() {
117: if (snmpAgent != null) {
118: try {
119: Long upTime = (Long) server.getAttribute(snmpAgent,
120: "Uptime");
121: return upTime.longValue() / 10;
122: } catch (Exception e) {
123: log.debug("Can't get uptime value from agent");
124: }
125: }
126: // fallback
127: return System.currentTimeMillis() / 10;
128: }
129:
130: /**
131: * @jmx:managed-attribute
132: */
133: public void setSysContact(String sysContact) {
134: this .sysContact = sysContact;
135: }
136:
137: /**
138: * @jmx:managed-attribute
139: */
140: public String getSysContact() {
141: return sysContact;
142: }
143:
144: /**
145: * @jmx:managed-attribute
146: */
147: public void setSysName(String sysName) {
148: this .sysName = sysName;
149: }
150:
151: /**
152: * @jmx:managed-attribute
153: */
154: public String getSysName() {
155: return sysName;
156: }
157:
158: /**
159: * @jmx:managed-attribute
160: */
161: public void setSysLocation(String sysLocation) {
162: this .sysLocation = sysLocation;
163: }
164:
165: /**
166: * @jmx:managed-attribute
167: */
168: public String getSysLocation() {
169: return sysLocation;
170: }
171:
172: /**
173: * @jmx:managed-attribute
174: */
175: public int getSysServices() {
176: return sysServices;
177: }
178:
179: // Lifecycle -----------------------------------------------------
180:
181: protected void createService() throws Exception {
182: // Determine the sysName from the running server config and the host name.
183: if (this .sysName == null) {
184: String serverConfig = ServerConfigLocator.locate()
185: .getServerName();
186: String hostAddress = (String) server.getAttribute(
187: ServerInfoMBean.OBJECT_NAME, "HostAddress");
188:
189: this .sysName = serverConfig + "@" + hostAddress;
190: log.debug("Setting sysName name to " + sysName);
191: }
192: this .sysObjectId = new SnmpObjectId(JBOSS_PREFIX + PRODUCT
193: + VERSION);
194: }
195:
196: }
|