Search in sources :

Example 36 with SnmpInstId

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

the class Snmp4jTrapReceiverIT method sendTraps.

private void sendTraps(final Snmp4JStrategy strategy, final int v3Level) throws Exception {
    final String hostAddress = str(getAgentAddress());
    LOG.debug("Sending V2 Trap");
    SnmpObjId enterpriseId = SnmpObjId.get(".0.0");
    SnmpObjId trapOID = SnmpObjId.get(enterpriseId, new SnmpInstId(1));
    SnmpTrapBuilder pdu = strategy.getV2TrapBuilder();
    pdu.addVarBind(SnmpObjId.get(".1.3.6.1.2.1.1.3.0"), strategy.getValueFactory().getTimeTicks(0));
    pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.1.0"), strategy.getValueFactory().getObjectId(trapOID));
    pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.3.0"), strategy.getValueFactory().getObjectId(enterpriseId));
    pdu.send(hostAddress, 9162, "public");
    LOG.debug("Sending V3 Trap");
    SnmpV3TrapBuilder pduv3 = strategy.getV3TrapBuilder();
    pduv3.addVarBind(SnmpObjId.get(".1.3.6.1.2.1.1.3.0"), strategy.getValueFactory().getTimeTicks(0));
    pduv3.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.1.0"), strategy.getValueFactory().getObjectId(trapOID));
    pduv3.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.3.0"), strategy.getValueFactory().getObjectId(enterpriseId));
    switch(v3Level) {
        case SnmpConfiguration.NOAUTH_NOPRIV:
            pduv3.send(hostAddress, 9162, SnmpConfiguration.NOAUTH_NOPRIV, "noAuthUser", null, null, null, null);
            break;
        case SnmpConfiguration.AUTH_PRIV:
            pduv3.send(hostAddress, 9162, SnmpConfiguration.AUTH_PRIV, "opennmsUser", "0p3nNMSv3", SnmpConfiguration.DEFAULT_AUTH_PROTOCOL, "0p3nNMSv3", SnmpConfiguration.DEFAULT_PRIV_PROTOCOL);
            break;
        default:
    }
}
Also used : SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) SnmpV3TrapBuilder(org.opennms.netmgt.snmp.SnmpV3TrapBuilder) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) OctetString(org.snmp4j.smi.OctetString) SnmpTrapBuilder(org.opennms.netmgt.snmp.SnmpTrapBuilder)

Example 37 with SnmpInstId

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

the class SnmpMultiResponseDTOTest method getSnmpMultiResponse.

private static SnmpMultiResponseDTO getSnmpMultiResponse() {
    final SnmpValueFactory snmpValueFactory = new Snmp4JValueFactory();
    final SnmpResult result = new SnmpResult(SnmpObjId.get(".1.3.6.1.2"), new SnmpInstId(".1.3.6.1.2.1.4.34.1.3.1.2.3.4"), snmpValueFactory.getCounter64(BigInteger.TEN));
    final SnmpResponseDTO responseDTO = new SnmpResponseDTO();
    responseDTO.setCorrelationId("42");
    responseDTO.getResults().add(result);
    final SnmpMultiResponseDTO multiResponseDTO = new SnmpMultiResponseDTO();
    multiResponseDTO.getResponses().add(responseDTO);
    return multiResponseDTO;
}
Also used : SnmpValueFactory(org.opennms.netmgt.snmp.SnmpValueFactory) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) Snmp4JValueFactory(org.opennms.netmgt.snmp.snmp4j.Snmp4JValueFactory) SnmpResult(org.opennms.netmgt.snmp.SnmpResult)

Example 38 with SnmpInstId

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

the class InstanceStrategy method call.

@Override
public OnmsAccessPointCollection call() throws IOException {
    OnmsAccessPointCollection apsUp = new OnmsAccessPointCollection();
    InetAddress ipaddr = m_iface.getIpAddress();
    // Retrieve this interface's SNMP peer object
    SnmpAgentConfig agentConfig = getAgentConfig(ipaddr);
    final String hostAddress = InetAddressUtils.str(ipaddr);
    LOG.debug("poll: setting SNMP peer attribute for interface {}", hostAddress);
    // Get configuration parameters
    String oid = ParameterMap.getKeyedString(m_parameters, "oid", null);
    if (oid == null) {
        throw new IllegalStateException("oid parameter is not set.");
    }
    String operator = ParameterMap.getKeyedString(m_parameters, "operator", null);
    String operand = ParameterMap.getKeyedString(m_parameters, "operand", null);
    String matchstr = ParameterMap.getKeyedString(m_parameters, "match", "true");
    LOG.debug("InstanceStrategy.poll: SnmpAgentConfig address= {}", agentConfig);
    // Establish SNMP session with interface
    try {
        SnmpObjId snmpObjectId = SnmpObjId.get(oid);
        Map<SnmpInstId, SnmpValue> map = SnmpUtils.getOidValues(agentConfig, "AccessPointMonitor::InstanceStrategy", snmpObjectId);
        if (map.size() <= 0) {
            throw new IOException("No entries found in table (possible timeout).");
        }
        for (Map.Entry<SnmpInstId, SnmpValue> entry : map.entrySet()) {
            boolean isUp = false;
            SnmpInstId instance = entry.getKey();
            SnmpValue value = entry.getValue();
            // Check the value against the configured criteria
            if (meetsCriteria(value, operator, operand)) {
                if ("true".equals(matchstr)) {
                    isUp = true;
                }
            } else if ("false".equals(matchstr)) {
                isUp = true;
            }
            // of online APs
            if (isUp) {
                String physAddr = getPhysAddrFromInstance(instance);
                LOG.debug("AP at instance '{}' with MAC '{}' is considered to be ONLINE on controller '{}'", instance, physAddr, m_iface.getIpAddress());
                OnmsAccessPoint ap = m_accessPointDao.get(physAddr);
                if (ap != null) {
                    if (ap.getPollingPackage().compareToIgnoreCase(getPackage().getName()) == 0) {
                        // Save the controller's IP address
                        ap.setControllerIpAddress(ipaddr);
                        apsUp.add(ap);
                    } else {
                        LOG.info("AP with MAC '{}' is in a different package.", physAddr);
                    }
                } else {
                    LOG.info("No matching AP in database for instance '{}'.", instance);
                }
            }
        }
    } catch (NumberFormatException e) {
        LOG.error("Number operator used on a non-number ", e);
    } catch (IllegalArgumentException e) {
        LOG.error("Invalid SNMP Criteria ", e);
    } catch (InterruptedException e) {
        LOG.error("Interrupted while polling {}", hostAddress, e);
    }
    return apsUp;
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) OnmsAccessPoint(org.opennms.netmgt.model.OnmsAccessPoint) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) OnmsAccessPointCollection(org.opennms.netmgt.model.OnmsAccessPointCollection) IOException(java.io.IOException) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) InetAddress(java.net.InetAddress) Map(java.util.Map) ParameterMap(org.opennms.core.utils.ParameterMap)

Example 39 with SnmpInstId

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

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

the class ThresholdingVisitorIT method testBug3554_withMockFilterDao.

/*
     * This test uses this files from src/test/resources:
     * - threshd-configuration-bug3554.xml
     * - test-thresholds-bug3554.xml
     */
@Test
public void testBug3554_withMockFilterDao() throws Exception {
    initFactories("/threshd-configuration-bug3554.xml", "/test-thresholds-bug3554.xml");
    // Visitor with Mock FavoriteFilterDao
    ThresholdingVisitor visitor = createVisitor();
    visitor.visitCollectionSet(createAnonymousCollectionSet(new Date().getTime()));
    // Do nothing, just to check visitor
    // real value = (46000 - 10000)/300 = 120
    runInterfaceResource(visitor, "127.0.0.1", "eth0", 10000000l, 1, 10000, 46000);
    // Do nothing, just to check visitor
    runGaugeDataTest(visitor, 12000);
    // Do nothing, just to check visitor
    SnmpCollectionAgent agent = createCollectionAgent();
    GenericIndexResourceType resourceType = createGenericIndexResourceType(agent, "ciscoEnvMonTemperatureStatusIndex");
    SnmpCollectionResource resource = new GenericIndexResource(resourceType, "ciscoEnvMonTemperatureStatusIndex", new SnmpInstId(45));
    resource.visit(visitor);
    EasyMock.verify(agent);
}
Also used : SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) GenericIndexResource(org.opennms.netmgt.collectd.GenericIndexResource) SnmpCollectionResource(org.opennms.netmgt.collectd.SnmpCollectionResource) GenericIndexResourceType(org.opennms.netmgt.collectd.GenericIndexResourceType) Date(java.util.Date) Test(org.junit.Test)

Aggregations

SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)42 SnmpObjId (org.opennms.netmgt.snmp.SnmpObjId)23 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)20 InetAddress (java.net.InetAddress)16 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)16 Map (java.util.Map)12 Test (org.junit.Test)11 PollStatus (org.opennms.netmgt.poller.PollStatus)10 ParameterMap (org.opennms.core.utils.ParameterMap)9 SnmpResult (org.opennms.netmgt.snmp.SnmpResult)9 HashMap (java.util.HashMap)8 ArrayList (java.util.ArrayList)7 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)7 MockDataCollectionConfig (org.opennms.netmgt.mock.MockDataCollectionConfig)6 SnmpTrapBuilder (org.opennms.netmgt.snmp.SnmpTrapBuilder)6 GenericIndexResource (org.opennms.netmgt.collectd.GenericIndexResource)5 GenericIndexResourceType (org.opennms.netmgt.collectd.GenericIndexResourceType)5 SnmpCollectionAgent (org.opennms.netmgt.collectd.SnmpCollectionAgent)5 SnmpCollectionResource (org.opennms.netmgt.collectd.SnmpCollectionResource)5 AttributeGroupType (org.opennms.netmgt.collection.api.AttributeGroupType)5