use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class SnmpGetter method get.
public List<SnmpValue> get(List<SnmpObjId> entryoids, Integer index) {
SnmpObjId instance = SnmpObjId.get(new int[] { index });
List<SnmpObjId> oids = new ArrayList<SnmpObjId>(entryoids.size());
for (SnmpObjId entryoid : entryoids) oids.add(SnmpObjId.get(entryoid, instance));
return get(oids);
}
use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class SnmpGetter method get.
public SnmpValue get(SnmpObjId entryoid, Integer index) {
SnmpObjId instance = SnmpObjId.get(new int[] { index });
List<SnmpObjId> oids = new ArrayList<SnmpObjId>(1);
oids.add(SnmpObjId.get(entryoid, instance));
List<SnmpValue> val = get(oids);
if (val == null || val.size() != 1 || val.get(0) == null || val.get(0).isError())
return null;
return val.get(0);
}
use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class TrapHandlerITCase method sendV2Trap.
public void sendV2Trap(String enterprise, int specific, LinkedHashMap<String, SnmpValue> varbinds) throws Exception {
SnmpObjId enterpriseId = SnmpObjId.get(enterprise);
boolean isGeneric = false;
SnmpObjId trapOID;
if (SnmpObjId.get(".1.3.6.1.6.3.1.1.5").isPrefixOf(enterpriseId)) {
isGeneric = true;
trapOID = enterpriseId;
} else {
trapOID = SnmpObjId.get(enterpriseId, new SnmpInstId(specific));
// XXX or should it be this
// trap OID = enterprise + ".0." + specific;
}
SnmpTrapBuilder pdu = SnmpUtils.getV2TrapBuilder();
pdu.addVarBind(SnmpObjId.get(".1.3.6.1.2.1.1.3.0"), SnmpUtils.getValueFactory().getTimeTicks(0));
pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.1.0"), SnmpUtils.getValueFactory().getObjectId(trapOID));
if (isGeneric) {
pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.3.0"), SnmpUtils.getValueFactory().getObjectId(enterpriseId));
}
for (Map.Entry<String, SnmpValue> entry : varbinds.entrySet()) {
pdu.addVarBind(SnmpObjId.get(entry.getKey()), entry.getValue());
}
pdu.send(getHostAddress(), m_trapdConfig.getSnmpTrapPort(), "public");
}
use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class TrapHandlerITCase method sendV2Trap.
public void sendV2Trap(String enterprise, int specific) throws Exception {
SnmpObjId enterpriseId = SnmpObjId.get(enterprise);
boolean isGeneric = false;
SnmpObjId trapOID;
if (SnmpObjId.get(".1.3.6.1.6.3.1.1.5").isPrefixOf(enterpriseId)) {
isGeneric = true;
trapOID = enterpriseId;
} else {
trapOID = SnmpObjId.get(enterpriseId, new SnmpInstId(specific));
// XXX or should it be this
// trap OID = enterprise + ".0." + specific;
}
SnmpTrapBuilder pdu = SnmpUtils.getV2TrapBuilder();
pdu.addVarBind(SnmpObjId.get(".1.3.6.1.2.1.1.3.0"), SnmpUtils.getValueFactory().getTimeTicks(0));
pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.1.0"), SnmpUtils.getValueFactory().getObjectId(trapOID));
if (isGeneric) {
pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.3.0"), SnmpUtils.getValueFactory().getObjectId(enterpriseId));
}
pdu.send(getHostAddress(), m_trapdConfig.getSnmpTrapPort(), "public");
}
use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class WalkCommand method doExecute.
@Override
protected Object doExecute() throws Exception {
LOG.debug("snmp:walk {} {} {}", m_location != null ? "-l " + m_location : "", m_host, m_oids);
final List<SnmpObjId> snmpObjIds = m_oids.stream().map(oid -> SnmpObjId.get(oid)).collect(Collectors.toList());
final SnmpAgentConfig agent = snmpAgentConfigFactory.getAgentConfig(InetAddress.getByName(m_host), m_location);
final CompletableFuture<List<SnmpResult>> future = locationAwareSnmpClient.walk(agent, snmpObjIds).withDescription("snmp:walk").withLocation(m_location).execute();
while (true) {
try {
future.get(1, TimeUnit.SECONDS).stream().forEach(res -> {
System.out.printf("[%s].[%s] = %s%n", res.getBase(), res.getInstance(), res.getValue());
});
break;
} catch (TimeoutException e) {
// pass
}
System.out.print(".");
}
return null;
}
Aggregations