use of com.sun.jmx.snmp.daemon.SnmpAdaptorServer in project jdk8u_jdk by JetBrains.
the class JVM_MANAGEMENT_MIB_IMPL method sendTrap.
private synchronized void sendTrap(SnmpOid trap, SnmpVarBindList list) {
final Iterator<NotificationTarget> iterator = notificationTargets.iterator();
final SnmpAdaptorServer adaptor = (SnmpAdaptorServer) getSnmpAdaptor();
if (adaptor == null) {
log.error("sendTrap", "Cannot send trap: adaptor is null.");
return;
}
if (!adaptor.isActive()) {
log.config("sendTrap", "Adaptor is not active: trap not sent.");
return;
}
while (iterator.hasNext()) {
NotificationTarget target = null;
try {
target = iterator.next();
SnmpPeer peer = new SnmpPeer(target.getAddress(), target.getPort());
SnmpParameters p = new SnmpParameters();
p.setRdCommunity(target.getCommunity());
peer.setParams(p);
log.debug("handleNotification", "Sending trap to " + target.getAddress() + ":" + target.getPort());
adaptor.snmpV2Trap(peer, trap, list, null);
} catch (Exception e) {
log.error("sendTrap", "Exception occurred while sending trap to [" + target + "]. Exception : " + e);
log.debug("sendTrap", e);
}
}
}
use of com.sun.jmx.snmp.daemon.SnmpAdaptorServer in project jdk8u_jdk by JetBrains.
the class AdaptorBootstrap method getAdaptorBootstrap.
private static AdaptorBootstrap getAdaptorBootstrap(int port, int trapPort, String bindAddress, boolean useAcl, String aclFileName) {
final InetAddress address;
try {
address = InetAddress.getByName(bindAddress);
} catch (UnknownHostException e) {
throw new AgentConfigurationError(UNKNOWN_SNMP_INTERFACE, e, bindAddress);
}
if (log.isDebugOn()) {
log.debug("initialize", Agent.getText("jmxremote.AdaptorBootstrap.getTargetList.starting" + "\n\t" + PropertyNames.PORT + "=" + port + "\n\t" + PropertyNames.TRAP_PORT + "=" + trapPort + "\n\t" + PropertyNames.BIND_ADDRESS + "=" + address + (useAcl ? ("\n\t" + PropertyNames.ACL_FILE_NAME + "=" + aclFileName) : "\n\tNo ACL") + ""));
}
final InetAddressAcl acl;
try {
acl = useAcl ? new SnmpAcl(System.getProperty("user.name"), aclFileName) : null;
} catch (UnknownHostException e) {
throw new AgentConfigurationError(UNKNOWN_SNMP_INTERFACE, e, e.getMessage());
}
// Create adaptor
final SnmpAdaptorServer adaptor = new SnmpAdaptorServer(acl, port, address);
adaptor.setUserDataFactory(new JvmContextFactory());
adaptor.setTrapPort(trapPort);
// Create MIB
//
final JVM_MANAGEMENT_MIB_IMPL mib = new JVM_MANAGEMENT_MIB_IMPL();
try {
mib.init();
} catch (IllegalAccessException x) {
throw new AgentConfigurationError(SNMP_MIB_INIT_FAILED, x, x.getMessage());
}
// Configure the trap destinations.
//
mib.addTargets(getTargetList(acl, trapPort));
//
try {
// Will wait until the adaptor starts or fails to start.
// If the adaptor fails to start, a CommunicationException or
// an InterruptedException is thrown.
//
adaptor.start(Long.MAX_VALUE);
} catch (Exception x) {
Throwable t = x;
if (x instanceof com.sun.jmx.snmp.daemon.CommunicationException) {
final Throwable next = t.getCause();
if (next != null)
t = next;
}
throw new AgentConfigurationError(SNMP_ADAPTOR_START_FAILED, t, address + ":" + port, "(" + t.getMessage() + ")");
}
//
if (!adaptor.isActive()) {
throw new AgentConfigurationError(SNMP_ADAPTOR_START_FAILED, address + ":" + port);
}
try {
// Add MIB to adaptor
//
adaptor.addMib(mib);
// Add Adaptor to the MIB
//
mib.setSnmpAdaptor(adaptor);
} catch (RuntimeException x) {
new AdaptorBootstrap(adaptor, mib).terminate();
throw x;
}
log.debug("initialize", Agent.getText("jmxremote.AdaptorBootstrap.getTargetList.initialize1"));
log.config("initialize", Agent.getText("jmxremote.AdaptorBootstrap.getTargetList.initialize2", address.toString(), java.lang.Integer.toString(adaptor.getPort())));
return new AdaptorBootstrap(adaptor, mib);
}
Aggregations