use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.
the class ShowConfigCommand method doExecute.
@Override
protected Object doExecute() 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.getTimeout());
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 MockSnmpStrategyTest method testSetMultipleBadAgent.
@Test
public void testSetMultipleBadAgent() throws Exception {
final SnmpAgentConfig sac = getAgentConfig();
sac.setAddress(InetAddressUtils.addr("1.2.3.4"));
final SnmpObjId[] oids = new SnmpObjId[] { SnmpObjId.get(".1.3.5.1.1.3.0"), SnmpObjId.get(".1.3.5.1.1.4.0") };
final SnmpValue[] values = new SnmpValue[] { m_strategy.getValueFactory().getInt32(4), m_strategy.getValueFactory().getGauge32(5) };
m_strategy.set(sac, oids, values);
final SnmpValue[] results = m_strategy.get(sac, oids);
assertNotNull(results);
assertEquals(2, results.length);
assertNull(results[0]);
assertNull(results[1]);
}
use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.
the class MockSnmpStrategyTest method testSetBadAgent.
@Test
public void testSetBadAgent() throws Exception {
final SnmpAgentConfig sac = getAgentConfig();
sac.setAddress(InetAddressUtils.addr("1.2.3.4"));
m_strategy.set(sac, SnmpObjId.get(".1.3.5.1.1.3.0"), m_strategy.getValueFactory().getInt32(4));
final SnmpValue result = m_strategy.get(sac, SnmpObjId.get(".1.3.5.1.1.3.0"));
assertNull(result);
}
use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.
the class MockSnmpStrategyTest method testTrackerTimeout.
@Test
public void testTrackerTimeout() throws Exception {
final CountingColumnTracker ct = new CountingColumnTracker(SnmpObjId.get(".1.3.5.1.1"));
final SnmpAgentConfig sac = getAgentConfig();
sac.setPort(12345);
try (final SnmpWalker walker = SnmpUtils.createWalker(sac, "test", ct)) {
assertNotNull(walker);
walker.start();
walker.waitFor();
}
assertEquals("it should match no columns (timeout)", Long.valueOf(0).longValue(), ct.getCount());
}
use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.
the class SnmpRequestDTOTest method getSnmpWalkRequest.
private static SnmpRequestDTO getSnmpWalkRequest() throws UnknownHostException {
final SnmpAgentConfig agent = new SnmpAgentConfig();
agent.setAddress(InetAddress.getByName("192.168.0.2"));
final SnmpWalkRequestDTO walkRequest = new SnmpWalkRequestDTO();
walkRequest.setCorrelationId("42");
walkRequest.setMaxRepetitions(4);
walkRequest.setOids(Lists.newArrayList(SnmpObjId.get(SnmpObjId.get(".1.3.6.1.2.1.4.34.1"), "3"), SnmpObjId.get(SnmpObjId.get(".1.3.6.1.2.1.4.34.1"), "5"), SnmpObjId.get(SnmpObjId.get(".1.3.6.1.2.1.4.34.1"), "4")));
SnmpWalkRequestDTO singleInstanceWalkRequest = new SnmpWalkRequestDTO();
singleInstanceWalkRequest.setCorrelationId("43");
singleInstanceWalkRequest.setInstance(SnmpInstId.INST_ZERO);
singleInstanceWalkRequest.setOids(Lists.newArrayList(SnmpObjId.get(".1.3.6.1.2.1.3.1.3")));
final SnmpGetRequestDTO getRequest = new SnmpGetRequestDTO();
getRequest.setCorrelationId("44");
getRequest.setOids(Lists.newArrayList(SnmpObjId.get(SnmpObjId.get(".1.3.6.1.2.1.3.1.3"), "0")));
final SnmpRequestDTO snmpRequest = new SnmpRequestDTO();
snmpRequest.setDescription("some random oids");
snmpRequest.setLocation("dc2");
snmpRequest.setAgent(agent);
snmpRequest.setWalkRequests(Lists.newArrayList(walkRequest, singleInstanceWalkRequest));
snmpRequest.setGetRequests(Lists.newArrayList(getRequest));
return snmpRequest;
}
Aggregations