Search in sources :

Example 6 with TrapInformation

use of org.opennms.netmgt.snmp.TrapInformation 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 7 with TrapInformation

use of org.opennms.netmgt.snmp.TrapInformation 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)

Aggregations

TrapInformation (org.opennms.netmgt.snmp.TrapInformation)7 Test (org.junit.Test)5 OID (org.snmp4j.smi.OID)5 OctetString (org.snmp4j.smi.OctetString)5 VariableBinding (org.snmp4j.smi.VariableBinding)5 PDU (org.snmp4j.PDU)3 Date (java.util.Date)2 PDUv1 (org.snmp4j.PDUv1)2 ScopedPDU (org.snmp4j.ScopedPDU)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 NotSerializableException (java.io.NotSerializableException)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 InetAddress (java.net.InetAddress)1 AggregationPolicy (org.opennms.core.ipc.sink.api.AggregationPolicy)1 Integer32 (org.snmp4j.smi.Integer32)1 IpAddress (org.snmp4j.smi.IpAddress)1