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;
}
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();
}
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);
}
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();
}
}
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());
}
Aggregations