Search in sources :

Example 41 with VariableBinding

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);
}
Also used : DynamicVariable(org.opennms.mock.snmp.responder.DynamicVariable) Variable(org.snmp4j.smi.Variable) VariableBinding(org.snmp4j.smi.VariableBinding) RequestStatus(org.snmp4j.agent.request.RequestStatus)

Example 42 with VariableBinding

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);
}
Also used : VariableBinding(org.snmp4j.smi.VariableBinding) RequestStatus(org.snmp4j.agent.request.RequestStatus)

Example 43 with VariableBinding

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();
}
Also used : PDU(org.snmp4j.PDU) OctetString(org.snmp4j.smi.OctetString) HashMap(java.util.HashMap) CommandResponderEvent(org.snmp4j.CommandResponderEvent) MessageDispatcherImpl(org.snmp4j.MessageDispatcherImpl) DefaultUdpTransportMapping(org.snmp4j.transport.DefaultUdpTransportMapping) OctetString(org.snmp4j.smi.OctetString) OID(org.snmp4j.smi.OID) Properties(loghub.configuration.Properties) Pipeline(loghub.Pipeline) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) CommandResponderEvent(org.snmp4j.CommandResponderEvent) Event(loghub.Event) VariableBinding(org.snmp4j.smi.VariableBinding) HashMap(java.util.HashMap) Map(java.util.Map) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 44 with VariableBinding

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());
    }
}
Also used : OctetString(org.snmp4j.smi.OctetString) Address(org.snmp4j.smi.Address) IpAddress(org.snmp4j.smi.IpAddress) UdpAddress(org.snmp4j.smi.UdpAddress) GenericAddress(org.snmp4j.smi.GenericAddress) ScopedPDU(org.snmp4j.ScopedPDU) CommandResponderEvent(org.snmp4j.CommandResponderEvent) DefaultUdpTransportMapping(org.snmp4j.transport.DefaultUdpTransportMapping) OID(org.snmp4j.smi.OID) UsmUser(org.snmp4j.security.UsmUser) USM(org.snmp4j.security.USM) PrivAES192(org.snmp4j.security.PrivAES192) Snmp(org.snmp4j.Snmp) UserTarget(org.snmp4j.UserTarget) VariableBinding(org.snmp4j.smi.VariableBinding) CommandResponder(org.snmp4j.CommandResponder)

Example 45 with VariableBinding

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");
}
Also used : ScopedPDU(org.snmp4j.ScopedPDU) PDU(org.snmp4j.PDU) ResponseEvent(org.snmp4j.event.ResponseEvent) OID(org.snmp4j.smi.OID) OctetString(org.snmp4j.smi.OctetString) VariableBinding(org.snmp4j.smi.VariableBinding) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

VariableBinding (org.snmp4j.smi.VariableBinding)52 OID (org.snmp4j.smi.OID)37 OctetString (org.snmp4j.smi.OctetString)31 PDU (org.snmp4j.PDU)30 ScopedPDU (org.snmp4j.ScopedPDU)17 Test (org.junit.Test)11 PDUv1 (org.snmp4j.PDUv1)10 IOException (java.io.IOException)9 HashMap (java.util.HashMap)9 LinkedHashMap (java.util.LinkedHashMap)8 ResponseEvent (org.snmp4j.event.ResponseEvent)8 Variable (org.snmp4j.smi.Variable)8 ArrayList (java.util.ArrayList)7 IpAddress (org.snmp4j.smi.IpAddress)7 TimeTicks (org.snmp4j.smi.TimeTicks)6 DefaultPDUFactory (org.snmp4j.util.DefaultPDUFactory)6 TableEvent (org.snmp4j.util.TableEvent)6 TableUtils (org.snmp4j.util.TableUtils)6 TrapInformation (org.opennms.netmgt.snmp.TrapInformation)5 Map (java.util.Map)4