use of org.snmp4j.smi.VariableBinding in project opennms by OpenNMS.
the class PropertiesBackedManagedObject method commit.
/**
* {@inheritDoc}
*/
@Override
public void commit(final SubRequest request) {
final VariableBinding vb = request.getVariableBinding();
final Variable v = vb.getVariable();
m_vars.put(vb.getOid(), v);
final RequestStatus status = request.getStatus();
status.setPhaseComplete(true);
}
use of org.snmp4j.smi.VariableBinding in project opennms by OpenNMS.
the class PropertiesBackedManagedObject method prepare.
/**
* {@inheritDoc}
*/
@Override
public void prepare(final SubRequest request) {
// store the old value, in case we undo it
final VariableBinding vb = request.getVariableBinding();
m_oldValue = m_vars.get(vb.getOid());
final RequestStatus status = request.getStatus();
status.setErrorStatus(SnmpConstants.SNMP_ERROR_SUCCESS);
status.setPhaseComplete(true);
}
use of org.snmp4j.smi.VariableBinding in project LogHub by fbacchella.
the class TestTrap method testbig.
// @Test
// public void testone() throws InterruptedException, IOException {
// BlockingQueue<Event> receiver = new ArrayBlockingQueue<>(1);
// SnmpTrap r = new SnmpTrap(receiver, new Pipeline(Collections.emptyList(), "testone", null));
// r.setPort(0);
// Assert.assertTrue("Failed to configure trap receiver", r.configure(new Properties(Collections.emptyMap())));;
// List<String> content = r.smartPrint(new OID("1.0.8802.1.1.2.1.1.2.5"));
// Assert.assertEquals(1, content.size());
// Assert.assertEquals("lldpMessageTxHoldMultiplier", content.get(0));
// r.close();
// }
@Ignore
@Test
public void testbig() throws InterruptedException, IOException {
BlockingQueue<Event> receiver = new ArrayBlockingQueue<>(2);
SnmpTrap r = new SnmpTrap(receiver, new Pipeline(Collections.emptyList(), "testbig", null));
r.setPort(0);
Map<String, Object> props = new HashMap<>();
props.put("mibdirs", new String[] { "/usr/share/snmp/mibs", "/tmp/mibs" });
Assert.assertTrue(r.configure(new Properties(props)));
r.start();
CommandResponderEvent trapEvent = new CommandResponderEvent(new MessageDispatcherImpl(), new DefaultUdpTransportMapping(), TransportIpAddress.parse("127.0.0.1/162"), 0, 0, null, 0, null, null, 0, null);
PDU pdu = new PDU();
pdu.add(new VariableBinding(new OID("1.0.8802.1.1.2.1.4.1.1.8.207185300.2.15079"), new OctetString("vnet7")));
pdu.add(new VariableBinding(new OID("1.0.8802.1.1.2.1.3.7.1.4.2"), new OctetString("eth0")));
pdu.add(new VariableBinding(new OID("1.0.8802.1.1.2.1.4.1.1.9.207185300.2.15079"), new OctetString("localhost")));
pdu.add(new VariableBinding(new OID("1.3.6.1.6.3.1.1.4.1"), new OctetString("lldpRemTablesChange")));
trapEvent.setPDU(pdu);
r.processPdu(trapEvent);
Event e = receiver.poll();
logger.debug(e.getClass());
@SuppressWarnings("unchecked") Map<String, ?> details = (Map<String, ?>) e.get("lldpRemSysName");
Assert.assertEquals(3, Array.getLength(details.get("index")));
Assert.assertEquals("localhost", details.get("value"));
r.interrupt();
}
use of org.snmp4j.smi.VariableBinding in project LogHub by fbacchella.
the class SNMPTrapGeneratorClient2 method sendSnmpV3Trap.
/**
* Sends the v3 trap
*/
private static void sendSnmpV3Trap() {
try {
Address targetAddress = GenericAddress.parse("udp:" + ipAddress + "/" + port);
TransportMapping<?> transport = new DefaultUdpTransportMapping();
Snmp snmp = new Snmp(transport);
USM usm = new USM(SecurityProtocols.getInstance().addDefaultProtocols(), new OctetString(MPv3.createLocalEngineID()), 0);
SecurityProtocols.getInstance().addPrivacyProtocol(new PrivAES192());
SecurityModels.getInstance().addSecurityModel(usm);
transport.listen();
snmp.getUSM().addUser(new OctetString("MD5DES"), new UsmUser(new OctetString("MD5DES"), AuthMD5.ID, new OctetString("UserName"), PrivAES128.ID, new OctetString("UserName")));
// Create Target
UserTarget target = new UserTarget();
target.setAddress(targetAddress);
target.setRetries(1);
target.setTimeout(11500);
target.setVersion(SnmpConstants.version3);
target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
target.setSecurityName(new OctetString("MD5DES"));
// Create PDU for V3
ScopedPDU pdu = new ScopedPDU();
pdu.setType(ScopedPDU.NOTIFICATION);
pdu.add(new VariableBinding(SnmpConstants.sysUpTime));
pdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, SnmpConstants.linkDown));
pdu.add(new VariableBinding(new OID(trapOid), new OctetString("Major")));
// Send the PDU
snmp.send(pdu, target);
System.out.println("Sending Trap to (IP:Port)=> " + ipAddress + ":" + port);
snmp.addCommandResponder(new CommandResponder() {
public void processPdu(CommandResponderEvent arg0) {
System.out.println(arg0);
}
});
snmp.close();
} catch (Exception e) {
System.err.println("Error in Sending Trap to (IP:Port)=> " + ipAddress + ":" + port);
System.err.println("Exception Message = " + e.getMessage());
}
}
use of org.snmp4j.smi.VariableBinding in project mysql_perf_analyzer by yahoo.
the class SNMPClient method get.
/**
* This method is capable of handling multiple OIDs
* @param oids
* @return
* @throws IOException
*/
public Map<OID, String> get(OID[] oids) throws IOException {
PDU pdu = createPDU();
for (OID oid : oids) {
pdu.add(new VariableBinding(oid));
}
pdu.setType(PDU.GET);
ResponseEvent event = snmp.send(pdu, getTarget(), null);
if (event != null) {
PDU pdu2 = event.getResponse();
VariableBinding[] binds = pdu2 != null ? event.getResponse().toArray() : null;
if (binds != null) {
Map<OID, String> res = new LinkedHashMap<OID, String>(binds.length);
for (VariableBinding b : binds) res.put(b.getOid(), b.getVariable().toString());
return res;
} else
return null;
}
throw new RuntimeException("GET timed out");
}
Aggregations