Search in sources :

Example 1 with SnmpAdaptorServer

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);
        }
    }
}
Also used : SnmpAdaptorServer(com.sun.jmx.snmp.daemon.SnmpAdaptorServer) SnmpParameters(com.sun.jmx.snmp.SnmpParameters) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) ListenerNotFoundException(javax.management.ListenerNotFoundException) SnmpPeer(com.sun.jmx.snmp.SnmpPeer)

Example 2 with SnmpAdaptorServer

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);
}
Also used : SnmpAcl(com.sun.jmx.snmp.IPAcl.SnmpAcl) UnknownHostException(java.net.UnknownHostException) InetAddressAcl(com.sun.jmx.snmp.InetAddressAcl) JVM_MANAGEMENT_MIB_IMPL(sun.management.snmp.jvminstr.JVM_MANAGEMENT_MIB_IMPL) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) JvmContextFactory(sun.management.snmp.util.JvmContextFactory) SnmpAdaptorServer(com.sun.jmx.snmp.daemon.SnmpAdaptorServer) AgentConfigurationError(sun.management.AgentConfigurationError) InetAddress(java.net.InetAddress)

Aggregations

SnmpAdaptorServer (com.sun.jmx.snmp.daemon.SnmpAdaptorServer)2 SnmpAcl (com.sun.jmx.snmp.IPAcl.SnmpAcl)1 InetAddressAcl (com.sun.jmx.snmp.InetAddressAcl)1 SnmpParameters (com.sun.jmx.snmp.SnmpParameters)1 SnmpPeer (com.sun.jmx.snmp.SnmpPeer)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)1 ListenerNotFoundException (javax.management.ListenerNotFoundException)1 AgentConfigurationError (sun.management.AgentConfigurationError)1 JVM_MANAGEMENT_MIB_IMPL (sun.management.snmp.jvminstr.JVM_MANAGEMENT_MIB_IMPL)1 JvmContextFactory (sun.management.snmp.util.JvmContextFactory)1