Search in sources :

Example 51 with SnmpAgentConfig

use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.

the class ShowConfigCommand method execute.

@Override
public Object execute() throws Exception {
    final InetAddress agentAdress = InetAddress.getByName(m_host);
    final SnmpAgentConfig agent = snmpAgentConfigFactory.getAgentConfig(agentAdress, m_location);
    System.out.println("Address: " + InetAddrUtils.str(agent.getAddress()));
    System.out.println("ProxyForAddress: " + InetAddrUtils.str(agent.getProxyFor()));
    System.out.println("Port: " + agent.getPort());
    System.out.println("Timeout: " + agent.getTimeout());
    System.out.println("Retries: " + agent.getRetries());
    System.out.println("MaxVarsPerPdu: " + agent.getMaxVarsPerPdu());
    System.out.println("MaxRepetitions: " + agent.getMaxRepetitions());
    System.out.println("MaxRequestSize: " + agent.getMaxRequestSize());
    System.out.println("Version: " + agent.getVersionAsString());
    // the credentials in this context
    if (agent.isVersion3()) {
        System.out.println("SecurityLevel: " + agent.getSecurityLevel());
        System.out.println("SecurityName: " + agent.getSecurityName());
        System.out.println("AuthPassPhrase: " + agent.getAuthPassPhrase());
        System.out.println("AuthProtocol: " + agent.getAuthProtocol());
        System.out.println("PrivPassphrase: " + agent.getPrivPassPhrase());
        System.out.println("PrivProtocol: " + agent.getPrivProtocol());
        System.out.println("ContextName: " + agent.getContextName());
        System.out.println("EngineId: " + agent.getEngineId());
        System.out.println("ContextEngineId: " + agent.getContextEngineId());
        System.out.println("EnterpriseId: " + agent.getEnterpriseId());
    } else {
        System.out.println("ReadCommunity: " + agent.getReadCommunity());
        System.out.println("WriteCommunity: " + agent.getWriteCommunity());
    }
    System.out.println();
    return null;
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) InetAddress(java.net.InetAddress)

Example 52 with SnmpAgentConfig

use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.

the class Snmp4JStrategy method registerForTraps.

@Override
public void registerForTraps(final TrapNotificationListener listener, InetAddress address, int snmpTrapPort, List<SnmpV3User> snmpUsers) throws IOException {
    final RegistrationInfo info = new RegistrationInfo(listener, address, snmpTrapPort);
    final Snmp4JTrapNotifier trapNotifier = new Snmp4JTrapNotifier(listener);
    info.setHandler(trapNotifier);
    final UdpAddress udpAddress;
    if (address == null) {
        udpAddress = new UdpAddress(snmpTrapPort);
    } else {
        udpAddress = new UdpAddress(address, snmpTrapPort);
    }
    // Set socket option SO_REUSEADDR so that we can bind to the port even if it
    // has recently been closed by passing 'true' as the second argument here.
    final DefaultUdpTransportMapping transport = new DefaultUdpTransportMapping(udpAddress, true);
    // Increase the receive buffer for the socket
    LOG.debug("Attempting to set receive buffer size to {}", Integer.MAX_VALUE);
    transport.setReceiveBufferSize(Integer.MAX_VALUE);
    LOG.debug("Actual receive buffer size is {}", transport.getReceiveBufferSize());
    info.setTransportMapping(transport);
    Snmp snmp = new Snmp(transport);
    Snmp4JStrategy.trackSession(snmp);
    snmp.addCommandResponder(trapNotifier);
    if (snmpUsers != null) {
        for (SnmpV3User user : snmpUsers) {
            SnmpAgentConfig config = new SnmpAgentConfig();
            config.setVersion(SnmpConfiguration.VERSION3);
            config.setSecurityName(user.getSecurityName());
            config.setAuthProtocol(user.getAuthProtocol());
            config.setAuthPassPhrase(user.getAuthPassPhrase());
            config.setPrivProtocol(user.getPrivProtocol());
            config.setPrivPassPhrase(user.getPrivPassPhrase());
            Snmp4JAgentConfig agentConfig = new Snmp4JAgentConfig(config);
            UsmUser usmUser = new UsmUser(agentConfig.getSecurityName(), agentConfig.getAuthProtocol(), agentConfig.getAuthPassPhrase(), agentConfig.getPrivProtocol(), agentConfig.getPrivPassPhrase());
            /* This doesn't work as expected. Basically SNMP4J is ignoring the engineId
                if (user.getEngineId() == null) {
                    snmp.getUSM().addUser(agentConfig.getSecurityName(), usmUser);
                } else {
                    snmp.getUSM().addUser(agentConfig.getSecurityName(), new OctetString(user.getEngineId()), usmUser);
                }
                */
            snmp.getUSM().addUser(agentConfig.getSecurityName(), usmUser);
        }
    }
    info.setSession(snmp);
    s_registrations.put(listener, info);
    snmp.listen();
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) UdpAddress(org.snmp4j.smi.UdpAddress) Snmp(org.snmp4j.Snmp) DefaultUdpTransportMapping(org.snmp4j.transport.DefaultUdpTransportMapping) UsmUser(org.snmp4j.security.UsmUser) SnmpV3User(org.opennms.netmgt.snmp.SnmpV3User)

Example 53 with SnmpAgentConfig

use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.

the class Snmp4JV2TrapBuilder method sendInform.

public SnmpValue[] sendInform(String destAddr, int destPort, int timeout, int retries, int securityLevel, String securityName, String authPassPhrase, String authProtocol, String privPassPhrase, String privProtocol) throws Exception {
    SnmpAgentConfig snmpAgentConfig = m_strategy.buildAgentConfig(destAddr, destPort, timeout, retries, securityLevel, securityName, authPassPhrase, authProtocol, privPassPhrase, privProtocol, m_pdu);
    Snmp4JAgentConfig agentConfig = new Snmp4JAgentConfig(snmpAgentConfig);
    return m_strategy.send(agentConfig, m_pdu, true);
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig)

Example 54 with SnmpAgentConfig

use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.

the class SnmpPeerFactory method getAgentConfig.

public SnmpAgentConfig getAgentConfig(final InetAddress agentInetAddress, String location, final int requestedSnmpVersion) {
    getReadLock().lock();
    try {
        if (getSnmpConfig() == null) {
            final SnmpAgentConfig agentConfig = new SnmpAgentConfig(agentInetAddress);
            if (requestedSnmpVersion == SnmpAgentConfig.VERSION_UNSPECIFIED) {
                agentConfig.setVersion(SnmpAgentConfig.DEFAULT_VERSION);
            } else {
                agentConfig.setVersion(requestedSnmpVersion);
            }
            return agentConfig;
        }
        final SnmpAgentConfig agentConfig = new SnmpAgentConfig(agentInetAddress);
        // Now set the defaults from the getSnmpConfig()
        setSnmpAgentConfig(agentConfig, new Definition(), requestedSnmpVersion);
        // Set the values from best matching definition
        final AddressSnmpConfigVisitor visitor = new AddressSnmpConfigVisitor(agentInetAddress, location);
        getSnmpConfig().visit(visitor);
        final Definition matchingDef = visitor.getDefinition();
        if (matchingDef != null) {
            setSnmpAgentConfig(agentConfig, matchingDef, requestedSnmpVersion);
        }
        return agentConfig;
    } finally {
        getReadLock().unlock();
    }
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) AddressSnmpConfigVisitor(org.opennms.netmgt.config.snmp.AddressSnmpConfigVisitor) Definition(org.opennms.netmgt.config.snmp.Definition)

Example 55 with SnmpAgentConfig

use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.

the class SnmpPeerFactoryTest method testGetv2cInRange.

/**
 * This tests for ranges configured for a v2 node and community string
 * @throws UnknownHostException
 */
public void testGetv2cInRange() throws UnknownHostException {
    SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr("10.7.23.100"));
    assertNotNull(agentConfig);
    assertEquals(SnmpAgentConfig.VERSION2C, agentConfig.getVersion());
    assertEquals("rangev2c", agentConfig.getReadCommunity());
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig)

Aggregations

SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)120 InetAddress (java.net.InetAddress)31 Test (org.junit.Test)31 JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)23 ArrayList (java.util.ArrayList)22 SnmpObjId (org.opennms.netmgt.snmp.SnmpObjId)21 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)21 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)16 PollStatus (org.opennms.netmgt.poller.PollStatus)14 Map (java.util.Map)11 ExecutionException (java.util.concurrent.ExecutionException)9 ParameterMap (org.opennms.core.utils.ParameterMap)9 SnmpWalker (org.opennms.netmgt.snmp.SnmpWalker)8 Date (java.util.Date)7 LldpLink (org.opennms.netmgt.model.LldpLink)7 OnmsNode (org.opennms.netmgt.model.OnmsNode)7 HashMap (java.util.HashMap)6 List (java.util.List)5 LldpLocPortGetter (org.opennms.netmgt.enlinkd.snmp.LldpLocPortGetter)4 LldpRemTableTracker (org.opennms.netmgt.enlinkd.snmp.LldpRemTableTracker)4