Search in sources :

Example 96 with SnmpValue

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

the class SnmpMonitorStrategyTest method testMeetsCriteriaWithSnmpNull.

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

Example 97 with SnmpValue

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

the class PercDetector method isServiceDetected.

/**
     * {@inheritDoc}
     *
     * Returns true if the protocol defined by this plugin is supported. If
     * the protocol is not supported then a false value is returned to the
     * caller. The qualifier map passed to the method is used by the plugin to
     * return additional information by key-name. These key-value pairs can be
     * added to service events if needed.
     */
@Override
public boolean isServiceDetected(final InetAddress address, final SnmpAgentConfig agentConfig) {
    try {
        configureAgentPTR(agentConfig);
        configureAgentVersion(agentConfig);
        SnmpObjId snmpObjectId = SnmpObjId.get(LOGICAL_BASE_OID + '.' + m_arrayNumber);
        SnmpValue value = SnmpUtils.get(agentConfig, snmpObjectId);
        if (value.toInt() != 2) {
            LOG.debug("PercMonitor.poll: Bad Disk Found. Log vol({}) degraded", m_arrayNumber);
            return false;
        }
    } catch (Throwable t) {
        throw new UndeclaredThrowableException(t);
    }
    return true;
}
Also used : SnmpValue(org.opennms.netmgt.snmp.SnmpValue) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId)

Example 98 with SnmpValue

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

the class SnmpDetector method isServiceDetected.

@Override
public boolean isServiceDetected(InetAddress address, SnmpAgentConfig agentConfig) {
    try {
        configureAgentPTR(agentConfig);
        configureAgentVersion(agentConfig);
        final String expectedValue = getVbvalue();
        if (this.m_isTable) {
            LOG.debug(getServiceName() + ": table detect enabled");
            final SnmpObjId snmpObjId = SnmpObjId.get(getOid());
            final Map<SnmpInstId, SnmpValue> table = SnmpUtils.getOidValues(agentConfig, DEFAULT_SERVICE_NAME, snmpObjId);
            final List<String> retrievedValues = table.values().stream().map(snmpValue -> m_hex ? snmpValue.toHexString() : snmpValue.toString()).collect(Collectors.toList());
            return isServiceDetected(this.matchType, retrievedValues, expectedValue);
        } else {
            final String retrievedValue = getValue(agentConfig, getOid(), m_hex);
            // we have to ensure that if expectedValue is defined, we use ANY, this is due to backwards compatibility
            MatchType matchType = this.matchType;
            if (matchType == null && expectedValue != null) {
                matchType = MatchType.Any;
            }
            return isServiceDetected(matchType, Lists.newArrayList(retrievedValue), expectedValue);
        }
    } catch (Throwable t) {
        throw new UndeclaredThrowableException(t);
    }
}
Also used : Logger(org.slf4j.Logger) DetectRequest(org.opennms.netmgt.provision.DetectRequest) LoggerFactory(org.slf4j.LoggerFactory) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) Collectors(java.util.stream.Collectors) InetAddress(java.net.InetAddress) Objects(java.util.Objects) SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) List(java.util.List) SnmpUtils(org.opennms.netmgt.snmp.SnmpUtils) Lists(com.google.common.collect.Lists) AgentBasedSyncAbstractDetector(org.opennms.netmgt.provision.support.AgentBasedSyncAbstractDetector) Map(java.util.Map) Pattern(java.util.regex.Pattern) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId)

Example 99 with SnmpValue

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

the class OmsaStorageDetector method isServiceDetected.

/**
     * {@inheritDoc}
     *
     * Returns true if the protocol defined by this plugin is supported. If
     * the protocol is not supported then a false value is returned to the
     * caller. The qualifier map passed to the method is used by the plugin to
     * return additional information by key-name. These key-value pairs can be
     * added to service events if needed.
     */
@Override
public boolean isServiceDetected(final InetAddress address, final SnmpAgentConfig agentConfig) {
    try {
        configureAgentPTR(agentConfig);
        configureAgentVersion(agentConfig);
        SnmpObjId virtualDiskRollUpStatusSnmpObject = SnmpObjId.get(virtualDiskRollUpStatus + '.' + m_virtualDiskNumber);
        SnmpValue virtualDiskRollUpStatus = SnmpUtils.get(agentConfig, virtualDiskRollUpStatusSnmpObject);
        if (virtualDiskRollUpStatus == null || virtualDiskRollUpStatus.isNull()) {
            LOG.debug("SNMP poll failed: no results, addr={} oid={}", agentConfig.getAddress(), virtualDiskRollUpStatusSnmpObject);
            return false;
        }
        if (virtualDiskRollUpStatus.toInt() != 3) {
            // 3 means Online
            LOG.debug("OMSAStorageMonitor.poll: Bad Disk Found. Log vol({}) degraded", m_virtualDiskNumber);
            return false;
        }
    } catch (Throwable t) {
        throw new UndeclaredThrowableException(t);
    }
    return true;
}
Also used : SnmpValue(org.opennms.netmgt.snmp.SnmpValue) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId)

Example 100 with SnmpValue

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

the class ThresholdingVisitorIT method runCounterWrapTest.

/*
     * Parameter expectedValue should be around 200:
     * Initial counter value is 20000 below limit.
     * Next value is 40000, so the difference will be 60000.
     * Counters are treated as rates so 60000/300 is 200.
     */
private void runCounterWrapTest(double bits, double expectedValue) throws Exception {
    Integer ifIndex = 1;
    Long ifSpeed = 10000000l;
    String ifName = "wlan0";
    initFactories("/threshd-configuration.xml", "/test-thresholds-bug3194.xml");
    addHighThresholdEvent(1, 100, 90, expectedValue, ifName, "1", "ifOutOctets", ifName, ifIndex.toString());
    ThresholdingVisitor visitor = createVisitor();
    // Creating Interface Resource Type
    SnmpIfData ifData = createSnmpIfData("127.0.0.1", ifName, ifSpeed, ifIndex, true);
    SnmpCollectionAgent agent = createCollectionAgent();
    IfResourceType resourceType = createInterfaceResourceType(agent);
    // Creating Data Source
    MibObject object = createMibObject("counter", "ifOutOctets", "ifIndex");
    SnmpAttributeType objectType = new NumericAttributeType(resourceType, "default", object, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
    long timestamp = new Date().getTime();
    // Step 1 - Initialize Counter
    visitor.visitCollectionSet(ThresholdingVisitorIT.createAnonymousCollectionSet(timestamp));
    BigDecimal n = new BigDecimal(Math.pow(2, bits) - 20000);
    SnmpValue snmpValue1 = SnmpUtils.getValueFactory().getCounter64(n.toBigInteger());
    SnmpCollectionResource resource1 = new IfInfo(resourceType, agent, ifData);
    resource1.setAttributeValue(objectType, snmpValue1);
    resource1.visit(visitor);
    // Step 2 - Wrap Counter
    visitor.visitCollectionSet(ThresholdingVisitorIT.createAnonymousCollectionSet(timestamp + 300000));
    SnmpValue snmpValue2 = SnmpUtils.getValueFactory().getCounter64(new BigInteger("40000"));
    SnmpCollectionResource resource2 = new IfInfo(resourceType, agent, ifData);
    resource2.setAttributeValue(objectType, snmpValue2);
    resource2.visit(visitor);
    // Verify Events
    EasyMock.verify(agent);
    verifyEvents(0);
}
Also used : NumericAttributeType(org.opennms.netmgt.collectd.NumericAttributeType) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) SnmpIfData(org.opennms.netmgt.collectd.SnmpIfData) SnmpAttributeType(org.opennms.netmgt.collectd.SnmpAttributeType) Date(java.util.Date) BigDecimal(java.math.BigDecimal) BigInteger(java.math.BigInteger) IfResourceType(org.opennms.netmgt.collectd.IfResourceType) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) AttributeGroupType(org.opennms.netmgt.collection.api.AttributeGroupType) BigInteger(java.math.BigInteger) IfInfo(org.opennms.netmgt.collectd.IfInfo) MibObject(org.opennms.netmgt.config.datacollection.MibObject) SnmpCollectionResource(org.opennms.netmgt.collectd.SnmpCollectionResource)

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