Search in sources :

Example 26 with VariableBinding

use of org.snmp4j.smi.VariableBinding in project mysql_perf_analyzer by yahoo.

the class SNMPClient method querySingleSNMPTableByOID.

public List<SNMPTriple> querySingleSNMPTableByOID(String oid) throws IOException {
    if (oid == null || oid.isEmpty())
        return null;
    if (!oid.startsWith("."))
        oid = "." + oid;
    TableUtils tUtils = new TableUtils(snmp, new DefaultPDUFactory());
    List<TableEvent> events = tUtils.getTable(getTarget(), new OID[] { new OID(oid) }, null, null);
    List<SNMPTriple> snmpList = new ArrayList<SNMPTriple>();
    for (TableEvent event : events) {
        if (event.isError()) {
            logger.warning(this.address + ": SNMP event error: " + event.getErrorMessage());
            continue;
        // throw new RuntimeException(event.getErrorMessage());
        }
        for (VariableBinding vb : event.getColumns()) {
            String key = vb.getOid().toString();
            String value = vb.getVariable().toString();
            snmpList.add(new SNMPTriple(key, "", value));
        }
    }
    return snmpList;
}
Also used : DefaultPDUFactory(org.snmp4j.util.DefaultPDUFactory) TableEvent(org.snmp4j.util.TableEvent) ArrayList(java.util.ArrayList) TableUtils(org.snmp4j.util.TableUtils) OID(org.snmp4j.smi.OID) OctetString(org.snmp4j.smi.OctetString) VariableBinding(org.snmp4j.smi.VariableBinding)

Example 27 with VariableBinding

use of org.snmp4j.smi.VariableBinding in project opennms by OpenNMS.

the class TrapDTOMapperTest method object2dtoTestV1.

@Test
public void object2dtoTestV1() throws UnknownHostException {
    long testStartTime = new Date().getTime();
    PDUv1 snmp4JV1TrapPdu = new PDUv1();
    snmp4JV1TrapPdu.setType(PDU.V1TRAP);
    snmp4JV1TrapPdu.setEnterprise(new OID(".1.3.6.1.6.3.1.1.4.1.0"));
    snmp4JV1TrapPdu.setGenericTrap(10);
    snmp4JV1TrapPdu.setSpecificTrap(0);
    snmp4JV1TrapPdu.setTimestamp(5000);
    snmp4JV1TrapPdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.0"), new OctetString("mockhost")));
    snmp4JV1TrapPdu.add(new VariableBinding(new OID(".1.3.6.1.2.1.1.3"), new OctetString("mockhost")));
    snmp4JV1TrapPdu.add(new VariableBinding(new OID(".1.3.6.1.6.3.1.1.4.1.0"), new OctetString("mockhost")));
    InetAddress inetAddress = InetAddress.getByName("127.0.0.1");
    ;
    TrapInformation snmp4JV1Trap = new Snmp4JTrapNotifier.Snmp4JV1TrapInformation(inetAddress, "public", snmp4JV1TrapPdu);
    TrapDTO trapDto = new TrapDTO(snmp4JV1Trap);
    System.out.println("trapDto is : " + trapDto);
    System.out.println("trapDto.getBody() is : " + trapDto.getRawMessage());
    System.out.println("trapDto.getCommunity() is : " + trapDto.getCommunity());
    assertEquals(".1.3.6.1.6.3.1.1.4.1.0", trapDto.getTrapIdentity().getEnterpriseId());
    assertEquals(10, trapDto.getTrapIdentity().getGeneric());
    assertEquals(0, trapDto.getTrapIdentity().getSpecific());
    assertEquals(InetAddressUtils.ONE_TWENTY_SEVEN, trapDto.getAgentAddress());
    assertEquals("public", trapDto.getCommunity());
    assertEquals(5000, trapDto.getTimestamp());
    // This is the "default" value from SNMP4J that indicates that the trap has not been forwarded
    assertEquals("v1", trapDto.getVersion());
    // Make sure that the message was created after the start of the test
    assertTrue(trapDto.getCreationTime() >= testStartTime);
}
Also used : OctetString(org.snmp4j.smi.OctetString) PDUv1(org.snmp4j.PDUv1) OID(org.snmp4j.smi.OID) VariableBinding(org.snmp4j.smi.VariableBinding) InetAddress(java.net.InetAddress) Date(java.util.Date) TrapInformation(org.opennms.netmgt.snmp.TrapInformation) Test(org.junit.Test)

Example 28 with VariableBinding

use of org.snmp4j.smi.VariableBinding in project opennms by OpenNMS.

the class TrapNotificationSerializationTest method testsnmp4JV1Serialization.

@Test
public void testsnmp4JV1Serialization() throws UnknownHostException {
    // create instance of Snmp4JV1
    PDUv1 snmp4JV1TrapPdu = new PDUv1();
    snmp4JV1TrapPdu.setType(PDU.V1TRAP);
    snmp4JV1TrapPdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.0"), new OctetString("mockhost")));
    snmp4JV1TrapPdu.add(new VariableBinding(new OID(".1.3.6.1.2.1.1.3"), new OctetString("mockhost")));
    snmp4JV1TrapPdu.add(new VariableBinding(new OID(".1.3.6.1.6.3.1.1.4.1.0"), new OctetString("mockhost")));
    TrapInformation snmp4JV1Trap = new Snmp4JTrapNotifier.Snmp4JV1TrapInformation(inetAddress, new String("public"), snmp4JV1TrapPdu);
    assertTrue(writeTrapNotificationObject(snmp4JV1Trap));
}
Also used : OctetString(org.snmp4j.smi.OctetString) PDUv1(org.snmp4j.PDUv1) OID(org.snmp4j.smi.OID) OctetString(org.snmp4j.smi.OctetString) VariableBinding(org.snmp4j.smi.VariableBinding) TrapInformation(org.opennms.netmgt.snmp.TrapInformation) Test(org.junit.Test)

Example 29 with VariableBinding

use of org.snmp4j.smi.VariableBinding in project opennms by OpenNMS.

the class Snmp4JDummyTransportTest method makePdu.

private static final PDU makePdu() {
    PDU snmp4JV2cTrapPdu = new PDUv1();
    OID oid = new OID(".1.3.6.1.2.1.1.3.0");
    snmp4JV2cTrapPdu.add(new VariableBinding(SnmpConstants.sysUpTime, new TimeTicks(5000)));
    snmp4JV2cTrapPdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, new OID(oid)));
    snmp4JV2cTrapPdu.add(new VariableBinding(SnmpConstants.snmpTrapAddress, new IpAddress("127.0.0.1")));
    snmp4JV2cTrapPdu.add(new VariableBinding(new OID(oid), new OctetString("Trap Msg v2-1")));
    snmp4JV2cTrapPdu.add(new VariableBinding(new OID(oid), new OctetString("Trap Msg v2-2")));
    snmp4JV2cTrapPdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.0"), new OctetString("Trap v1 msg-1")));
    snmp4JV2cTrapPdu.add(new VariableBinding(new OID(".1.3.6.1.2.1.1.3"), new OctetString("Trap v1 msg-2")));
    snmp4JV2cTrapPdu.add(new VariableBinding(new OID(".1.3.6.1.6.3.1.1.4.1.1"), new OctetString("Trap v1 msg-3")));
    snmp4JV2cTrapPdu.add(new VariableBinding(new OID(".1.3.6.1.4.1.733.6.3.18.1.5.0"), new Integer32(1)));
    snmp4JV2cTrapPdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.0"), new Null()));
    snmp4JV2cTrapPdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.1"), new Null(128)));
    snmp4JV2cTrapPdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.2"), new Null(129)));
    snmp4JV2cTrapPdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.3"), new Null(130)));
    snmp4JV2cTrapPdu.setType(PDU.V1TRAP);
    return snmp4JV2cTrapPdu;
}
Also used : PDU(org.snmp4j.PDU) OctetString(org.snmp4j.smi.OctetString) Integer32(org.snmp4j.smi.Integer32) Null(org.snmp4j.smi.Null) TimeTicks(org.snmp4j.smi.TimeTicks) IpAddress(org.snmp4j.smi.IpAddress) PDUv1(org.snmp4j.PDUv1) OID(org.snmp4j.smi.OID) VariableBinding(org.snmp4j.smi.VariableBinding)

Example 30 with VariableBinding

use of org.snmp4j.smi.VariableBinding in project opennms by OpenNMS.

the class MapSubAgent method get.

@Override
public VariableBinding get(OID requested) {
    if (!m_values.containsKey(requested)) {
        return null;
    }
    OID response = new OID(requested);
    Variable value = m_values.get(response);
    return new VariableBinding(response, value);
}
Also used : Variable(org.snmp4j.smi.Variable) OID(org.snmp4j.smi.OID) VariableBinding(org.snmp4j.smi.VariableBinding)

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