use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.
the class JoeSnmpStrategy method get.
@Override
public SnmpValue[] get(SnmpAgentConfig snmpAgentConfig, SnmpObjId[] oids) {
JoeSnmpAgentConfig agentConfig = new JoeSnmpAgentConfig(snmpAgentConfig);
SnmpSession session = null;
SnmpValue[] values = { null };
try {
SnmpPeer peer = createPeer(agentConfig);
SnmpParameters params = new SnmpParameters();
setParameters(agentConfig, params);
peer.setParameters(params);
configurePeer(peer, agentConfig);
session = new SnmpSession(peer);
SnmpObjectId[] jOids = convertOids(oids);
SnmpSyntax[] results = session.get(jOids);
values = convertSnmpSyntaxs(results);
} catch (SocketException e) {
LOG.error("Could not create JoeSNMP session using AgentConfig: {}", agentConfig);
} finally {
if (session != null) {
session.close();
}
}
return values;
}
use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.
the class V1TrapInformation method getSnmpVarBindDTO.
@Override
public SnmpVarBindDTO getSnmpVarBindDTO(int i) {
SnmpObjId name = SnmpObjId.get(getVarBindAt(i).getName().getIdentifiers());
SnmpValue value = new JoeSnmpValue(getVarBindAt(i).getValue());
return new SnmpVarBindDTO(name, value);
}
use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.
the class V2TrapInformation method getSnmpVarBindDTO.
@Override
public SnmpVarBindDTO getSnmpVarBindDTO(int i) {
if (i < 2) {
if (i == 0) {
LOG.debug("Skipping processing of varbind it is the sysuptime and the first varbind, it is not processed as a parm per RFC2089");
} else {
LOG.debug("Skipping processing of varbind it is the trap OID and the second varbind, it is not processed as a parm per RFC2089");
}
return null;
} else {
SnmpObjId name = SnmpObjId.get(getVarBindAt(i).getName().getIdentifiers());
SnmpValue value = new JoeSnmpValue(getVarBindAt(i).getValue());
return new SnmpVarBindDTO(name, value);
}
}
use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.
the class SnmpValueTest method testInetAddress.
@Test
public void testInetAddress() {
for (final SnmpValueFactory factory : m_factories) {
final InetAddress address = InetAddressUtils.addr("192.168.0.1");
final SnmpValue value = factory.getIpAddress(address);
final String className = factory.getClass().getName();
assertTrue(className + ": getInetAddress isDisplayable should be true", value.isDisplayable());
assertEquals(className + ": getInetAddress to InetAddress should return 192.168.0.1", address, value.toInetAddress());
assertEquals(className + ": getInetAddress to String should return 192.168.0.1", "192.168.0.1", value.toString());
assertEquals(className + ": getInetAddress to DisplayString should return 192.168.0.1", "192.168.0.1", value.toDisplayString());
try {
value.toInt();
fail(className + ": getInetAddress to int should throw an IllegalArgumentException");
} catch (final IllegalArgumentException e) {
/* expected */
}
try {
value.toLong();
fail(className + ": getInetAddress to long should throw an IllegalArgumentException");
} catch (final IllegalArgumentException e) {
/* expected */
}
try {
value.toBigInteger();
fail(className + ": getInetAddress to BigInteger should throw an IllegalArgumentException");
} catch (final IllegalArgumentException e) {
/* expected */
}
try {
value.toHexString();
fail(className + ": getInetAddress to HexString should throw an IllegalArgumentException");
} catch (final IllegalArgumentException e) {
/* expected */
}
try {
value.toSnmpObjId();
fail(className + ": getInetAddress to SnmpObjId should throw an IllegalArgumentException");
} catch (final IllegalArgumentException e) {
/* expected */
}
}
}
use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.
the class SnmpValueTest method testNull.
@Test
public void testNull() {
for (final SnmpValueFactory factory : m_factories) {
final SnmpValue value = factory.getNull();
final String factoryClassName = factory.getClass().getName();
assertFalse(factoryClassName + ": Null isDisplayable should be false", value.isDisplayable());
assertTrue(factoryClassName + ": Null isNull should be true", value.isNull());
assertFalse(factoryClassName + ": Null isEndOfMib should be false", value.isEndOfMib());
assertFalse(factoryClassName + ": Null isError should be false", value.isError());
}
}
Aggregations