1 22 package org.jboss.jmx.adaptor.snmp.system; 23 24 import javax.management.ObjectName ; 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 42 public class MIB2SystemGroupService extends ServiceMBeanSupport 43 implements MIB2SystemGroupServiceMBean 44 { 45 47 48 public static final String JBOSS_PREFIX = "1.3.6.1.4.1.18016"; 49 50 51 public static final String PRODUCT = ".1.1"; 52 53 54 public static final String VERSION = ".2"; 55 56 58 private String sysDescr; private SnmpObjectId sysObjectId; private String sysContact; private String sysName; private String sysLocation; private final int sysServices = 64; 66 private ObjectName snmpAgent = SnmpAgentServiceMBean.OBJECT_NAME; 67 68 72 public MIB2SystemGroupService() 73 { 74 } 76 77 79 82 public void setSnmpAgent(ObjectName agent) 83 { 84 this.snmpAgent = agent; 85 } 86 87 90 public ObjectName getSnmpAgent() 91 { 92 return snmpAgent; 93 } 94 95 98 public void setSysDescr(String sysDescr) 99 { 100 this.sysDescr = sysDescr; 101 } 102 103 106 public String getSysDescr() 107 { 108 return sysDescr; 109 } 110 111 114 public SnmpObjectId getSysObjectId() 115 { 116 return sysObjectId; 117 } 118 119 123 public long getSysUpTime() 124 { 125 if (snmpAgent !=null) 126 { 127 try 128 { 129 Long upTime = (Long )server.getAttribute(snmpAgent, "Uptime"); 130 return upTime.longValue() / 10; 131 } 132 catch (Exception e) 133 { 134 log.debug("Can't get uptime value from agent"); 135 } 136 } 137 return System.currentTimeMillis() / 10; 139 } 140 141 144 public void setSysContact(String sysContact) 145 { 146 this.sysContact = sysContact; 147 } 148 149 152 public String getSysContact() 153 { 154 return sysContact; 155 } 156 157 160 public void setSysName(String sysName) 161 { 162 this.sysName = sysName; 163 } 164 165 168 public String getSysName() 169 { 170 return sysName; 171 } 172 173 176 public void setSysLocation(String sysLocation) 177 { 178 this.sysLocation = sysLocation; 179 } 180 181 184 public String getSysLocation() 185 { 186 return sysLocation; 187 } 188 189 192 public int getSysServices() 193 { 194 return sysServices; 195 } 196 197 199 protected void createService() throws Exception 200 { 201 if (this.sysName == null) 203 { 204 String serverConfig = ServerConfigLocator.locate().getServerName(); 205 ObjectName name = new ObjectName (ServerInfoMBean.OBJECT_NAME_STR); 206 String hostAddress = (String )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 |