Search in sources :

Example 26 with SnmpValue

use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.

the class SnmpMonitorStrategyTest method testMeetsCriteriaWithIPAddr.

@Test
public void testMeetsCriteriaWithIPAddr() throws Exception {
    SnmpValue result = ipAddr("10.1.1.1");
    testSyntaxEquals(result, "10.1.1.1", "10.1.1.2");
    testSyntaxMatches(result, "10\\.1\\.1\\.[1-5]", "10\\.1\\.1\\.[02-9]");
}
Also used : SnmpValue(org.opennms.netmgt.snmp.SnmpValue) Test(org.junit.Test)

Example 27 with SnmpValue

use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.

the class SnmpMonitorStrategyTest method testErrorConditions2.

@Test
public void testErrorConditions2() {
    SnmpValue result = int32Value(1);
    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(new NumberFormatException("For input string: \"abc\""));
    try {
        monitor.meetsCriteria(result, "<", "abc");
        fail("expected an exception");
    } catch (Throwable t) {
        ta.throwableReceived(t);
    }
    ta.verifyAnticipated();
}
Also used : SnmpValue(org.opennms.netmgt.snmp.SnmpValue) ThrowableAnticipator(org.opennms.test.ThrowableAnticipator) Test(org.junit.Test)

Example 28 with SnmpValue

use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.

the class SnmpMonitorStrategyTest method testMeetsCriteriaWithGauge32.

@Test
public void testMeetsCriteriaWithGauge32() {
    SnmpValue result = gauge32Value(1);
    testSyntaxEquals(result, "1", "2");
    testOrderOperations(result, 1);
}
Also used : SnmpValue(org.opennms.netmgt.snmp.SnmpValue) Test(org.junit.Test)

Example 29 with SnmpValue

use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.

the class SnmpMonitorStrategyTest method testNumericString.

@Test
public void testNumericString() {
    SnmpValue result = octetString("12345");
    testOrderOperations(result, 12345);
}
Also used : SnmpValue(org.opennms.netmgt.snmp.SnmpValue) Test(org.junit.Test)

Example 30 with SnmpValue

use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.

the class SyntaxToEventTest method testProcessSyntaxForMacAddresses.

@Test
public void testProcessSyntaxForMacAddresses() {
    SnmpValueFactory valueFactory = SnmpUtils.getValueFactory();
    assertNotNull(valueFactory);
    byte[] macAddr = { 001, 002, 003, 004, 005, 006 };
    SnmpValue octetString = valueFactory.getOctetString(macAddr);
    Parm parm = SyntaxToEvent.processSyntax("testMacAddress", octetString);
    assertEquals("testMacAddress", parm.getParmName());
    assertEquals(EventConstants.XML_ENCODING_MAC_ADDRESS, parm.getValue().getEncoding());
    assertEquals("01:02:03:04:05:06", parm.getValue().getContent());
    macAddr = new byte[] { (byte) 0x80, (byte) 0x81, (byte) 0x8C, (byte) 0x8F, (byte) 0xFF, (byte) 0x05 };
    octetString = valueFactory.getOctetString(macAddr);
    parm = SyntaxToEvent.processSyntax("testMacAddress", octetString);
    assertEquals("testMacAddress", parm.getParmName());
    assertEquals(EventConstants.XML_ENCODING_MAC_ADDRESS, parm.getValue().getEncoding());
    assertEquals("80:81:8C:8F:FF:05", parm.getValue().getContent());
    macAddr = new byte[] { 0101, 0101, 0101, 0101, 0101, 0101 };
    octetString = valueFactory.getOctetString(macAddr);
    parm = SyntaxToEvent.processSyntax("otherDataType", octetString);
    assertEquals("otherDataType", parm.getParmName());
    assertEquals(EventConstants.XML_ENCODING_TEXT, parm.getValue().getEncoding());
    assertEquals("AAAAAA", parm.getValue().getContent());
    parm = SyntaxToEvent.processSyntax("testMacAddress", octetString);
    assertEquals("testMacAddress", parm.getParmName());
    assertEquals(EventConstants.XML_ENCODING_MAC_ADDRESS, parm.getValue().getEncoding());
    assertEquals("41:41:41:41:41:41", parm.getValue().getContent());
}
Also used : SnmpValueFactory(org.opennms.netmgt.snmp.SnmpValueFactory) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) Parm(org.opennms.netmgt.xml.event.Parm) Test(org.junit.Test)

Aggregations

SnmpValue (org.opennms.netmgt.snmp.SnmpValue)112 Test (org.junit.Test)57 SnmpObjId (org.opennms.netmgt.snmp.SnmpObjId)47 SnmpValueFactory (org.opennms.netmgt.snmp.SnmpValueFactory)24 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)21 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)20 InetAddress (java.net.InetAddress)19 Map (java.util.Map)14 PollStatus (org.opennms.netmgt.poller.PollStatus)14 JoeSnmpValueFactory (org.opennms.netmgt.snmp.joesnmp.JoeSnmpValueFactory)12 ArrayList (java.util.ArrayList)11 ParameterMap (org.opennms.core.utils.ParameterMap)9 Parm (org.opennms.netmgt.xml.event.Parm)9 PDU (org.snmp4j.PDU)9 AttributeGroupType (org.opennms.netmgt.collection.api.AttributeGroupType)8 SnmpResult (org.opennms.netmgt.snmp.SnmpResult)8 LinkedHashMap (java.util.LinkedHashMap)7 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)5 HashMap (java.util.HashMap)4 NumericAttributeType (org.opennms.netmgt.collectd.NumericAttributeType)4