Search in sources :

Example 36 with SnmpAgentConfig

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

the class ScanManager method updateSnmpData.

void updateSnmpData(final OnmsNode node) {
    try {
        m_systemGroup = new SystemGroup(m_address);
        final Set<SnmpInstId> ipAddrs = new TreeSet<SnmpInstId>();
        final Set<InetAddress> ipAddresses = new HashSet<InetAddress>();
        for (final OnmsIpInterface iface : node.getIpInterfaces()) {
            final InetAddress addr = iface.getIpAddress();
            if (addr != null && addr instanceof Inet4Address) {
                ipAddrs.add(new SnmpInstId(InetAddressUtils.toOid(addr)));
            }
            ipAddresses.add(addr);
        }
        m_ipAddrTable = new IpAddrTable(m_address, ipAddrs);
        m_ipAddressTable = IpAddressTable.createTable(m_address, ipAddresses);
        AggregateTracker tracker = new AggregateTracker(Lists.newArrayList(m_systemGroup, m_ipAddrTable, m_ipAddressTable));
        final SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(m_address, MonitoringLocationUtils.getLocationNameOrNullIfDefault(node));
        try {
            m_locationAwareSnmpClient.walk(agentConfig, tracker).withDescription("system/ipAddrTable/ipAddressTable").withLocation(node.getLocation() == null ? null : node.getLocation().getLocationName()).execute().get();
        } catch (ExecutionException e) {
        // pass
        }
        final Set<SnmpInstId> ifIndices = new TreeSet<SnmpInstId>();
        for (final Integer ifIndex : m_ipAddrTable.getIfIndices()) {
            ifIndices.add(new SnmpInstId(ifIndex));
        }
        m_ifTable = new IfTable(m_address, ifIndices);
        m_ifXTable = new IfXTable(m_address, ifIndices);
        tracker = new AggregateTracker(Lists.newArrayList(m_systemGroup, m_ifTable, m_ifXTable));
        try {
            m_locationAwareSnmpClient.walk(agentConfig, tracker).withDescription("ifTable/ifXTable").withLocation(node.getLocation() == null ? null : node.getLocation().getLocationName()).execute().get();
        } catch (ExecutionException e) {
        // pass
        }
        m_systemGroup.updateSnmpDataForNode(node);
        for (final SnmpInstId ifIndex : ifIndices) {
            m_ifTable.updateSnmpInterfaceData(node, ifIndex.toInt());
        }
        for (final SnmpInstId ifIndex : ifIndices) {
            m_ifXTable.updateSnmpInterfaceData(node, ifIndex.toInt());
        }
        for (final SnmpInstId ipAddr : ipAddrs) {
            m_ipAddrTable.updateIpInterfaceData(node, ipAddr.toString());
        }
        for (final InetAddress addr : ipAddresses) {
            m_ipAddressTable.updateIpInterfaceData(node, InetAddressUtils.str(addr));
        }
    } catch (final InterruptedException e) {
        LOG.info("thread interrupted while updating SNMP data", e);
        Thread.currentThread().interrupt();
    }
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) Inet4Address(java.net.Inet4Address) IpAddrTable(org.opennms.netmgt.provision.service.snmp.IpAddrTable) SystemGroup(org.opennms.netmgt.provision.service.snmp.SystemGroup) IfTable(org.opennms.netmgt.provision.service.snmp.IfTable) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) TreeSet(java.util.TreeSet) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) IfXTable(org.opennms.netmgt.provision.service.snmp.IfXTable) ExecutionException(java.util.concurrent.ExecutionException) InetAddress(java.net.InetAddress) HashSet(java.util.HashSet) AggregateTracker(org.opennms.netmgt.snmp.AggregateTracker)

Example 37 with SnmpAgentConfig

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

the class TableStrategy 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 = SnmpPeerFactory.getInstance().getAgentConfig(ipaddr);
    if (agentConfig == null) {
        throw new IllegalStateException("SnmpAgentConfig object not available for interface " + 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.");
    }
    agentConfig.hashCode();
    // Set timeout and retries on SNMP peer object
    agentConfig.setTimeout(ParameterMap.getKeyedInteger(m_parameters, "timeout", agentConfig.getTimeout()));
    agentConfig.setRetries(ParameterMap.getKeyedInteger(m_parameters, "retry", ParameterMap.getKeyedInteger(m_parameters, "retries", agentConfig.getRetries())));
    agentConfig.setPort(ParameterMap.getKeyedInteger(m_parameters, "port", agentConfig.getPort()));
    LOG.debug("TableStrategy.poll: SnmpAgentConfig address={}", agentConfig);
    // Establish SNMP session with interface
    try {
        SnmpObjId snmpObjectId = SnmpObjId.get(oid);
        Map<SnmpInstId, SnmpValue> map = SnmpUtils.getOidValues(agentConfig, "AccessPointMonitor::TableStrategy", snmpObjectId);
        if (map.size() <= 0) {
            throw new IOException("No entries found in table (possible timeout).");
        }
        for (Map.Entry<SnmpInstId, SnmpValue> entry : map.entrySet()) {
            SnmpValue value = entry.getValue();
            String physAddr = getPhysAddrFromValue(value);
            LOG.debug("AP at value '{}' with MAC '{}' is considered to be ONLINE on controller '{}'", value.toHexString(), 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 value '{}'.", value.toHexString());
            }
        }
    } 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 38 with SnmpAgentConfig

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

the class InstanceStrategy method getAgentConfig.

private SnmpAgentConfig getAgentConfig(InetAddress ipaddr) {
    // Retrieve this interface's SNMP peer object
    SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(ipaddr);
    if (agentConfig == null) {
        throw new IllegalStateException("SnmpAgentConfig object not available for interface " + ipaddr);
    }
    agentConfig.hashCode();
    // Set timeout and retries on SNMP peer object
    agentConfig.setTimeout(ParameterMap.getKeyedInteger(m_parameters, "timeout", agentConfig.getTimeout()));
    agentConfig.setRetries(ParameterMap.getKeyedInteger(m_parameters, "retry", ParameterMap.getKeyedInteger(m_parameters, "retries", agentConfig.getRetries())));
    agentConfig.setPort(ParameterMap.getKeyedInteger(m_parameters, "port", agentConfig.getPort()));
    return agentConfig;
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig)

Example 39 with SnmpAgentConfig

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

the class SnmpAssetProvisioningAdapter method doAddNode.

/**
	 * <p>doAdd</p>
	 *
	 * @param nodeId a int.
	 * @param retry a boolean.
	 * @throws org.opennms.netmgt.provision.ProvisioningAdapterException if any.
	 */
@Override
public void doAddNode(final int nodeId) throws ProvisioningAdapterException {
    LOG.debug("doAdd: adding nodeid: {}", nodeId);
    final OnmsNode node = m_nodeDao.get(nodeId);
    Assert.notNull(node, "doAdd: failed to return node for given nodeId:" + nodeId);
    InetAddress ipaddress = m_template.execute(new TransactionCallback<InetAddress>() {

        @Override
        public InetAddress doInTransaction(TransactionStatus arg0) {
            return getIpForNode(node);
        }
    });
    SnmpAgentConfig agentConfig = null;
    String locationName = node.getLocation() != null ? node.getLocation().getLocationName() : null;
    agentConfig = m_snmpConfigDao.getAgentConfig(ipaddress, locationName);
    final OnmsAssetRecord asset = node.getAssetRecord();
    m_config.getReadLock().lock();
    try {
        for (final AssetField field : m_config.getAssetFieldsForAddress(ipaddress, node.getSysObjectId())) {
            try {
                final String value = fetchSnmpAssetString(m_locationAwareSnmpClient, agentConfig, locationName, field.getMibObjs(), field.getFormatString());
                LOG.debug("doAdd: Setting asset field \" {} \" to value: {}", field.getName(), value);
                // Use Spring bean-accessor classes to set the field value
                final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(asset);
                try {
                    wrapper.setPropertyValue(field.getName(), value);
                } catch (final BeansException e) {
                    LOG.warn("doAdd: Could not set property \" {} \" on asset object {}", field.getName(), e.getMessage(), e);
                }
            } catch (final Throwable t) {
                // This exception is thrown if the SNMP operation fails or an incorrect number of
                // parameters is returned by the agent or because of a misconfiguration.
                LOG.warn("doAdd: Could not set value for asset field \" {} \": {}", field.getName(), t.getMessage(), t);
            }
        }
    } finally {
        m_config.getReadLock().unlock();
    }
    node.setAssetRecord(asset);
    m_nodeDao.saveOrUpdate(node);
    m_nodeDao.flush();
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) BeanWrapper(org.springframework.beans.BeanWrapper) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAssetRecord(org.opennms.netmgt.model.OnmsAssetRecord) AssetField(org.opennms.netmgt.config.snmpAsset.adapter.AssetField) TransactionStatus(org.springframework.transaction.TransactionStatus) InetAddress(java.net.InetAddress) BeansException(org.springframework.beans.BeansException)

Example 40 with SnmpAgentConfig

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

the class SnmpCollectionSet method getAgentConfig.

/**
     * <p>getAgentConfig</p>
     *
     * @return a {@link org.opennms.netmgt.snmp.SnmpAgentConfig} object.
     */
public SnmpAgentConfig getAgentConfig() {
    SnmpAgentConfig agentConfig = getCollectionAgent().getAgentConfig();
    agentConfig.setPort(m_snmpCollection.getSnmpPort(agentConfig.getPort()));
    agentConfig.setRetries(m_snmpCollection.getSnmpRetries(agentConfig.getRetries()));
    agentConfig.setTimeout(m_snmpCollection.getSnmpTimeout(agentConfig.getTimeout()));
    agentConfig.setReadCommunity(m_snmpCollection.getSnmpReadCommunity(agentConfig.getReadCommunity()));
    agentConfig.setWriteCommunity(m_snmpCollection.getSnmpWriteCommunity(agentConfig.getWriteCommunity()));
    agentConfig.setProxyFor(m_snmpCollection.getSnmpProxyFor(agentConfig.getProxyFor()));
    agentConfig.setVersion(m_snmpCollection.getSnmpVersion(agentConfig.getVersion()));
    agentConfig.setMaxVarsPerPdu(m_snmpCollection.getSnmpMaxVarsPerPdu(agentConfig.getMaxVarsPerPdu()));
    agentConfig.setMaxRepetitions(m_snmpCollection.getSnmpMaxRepetitions(agentConfig.getMaxRepetitions()));
    agentConfig.setMaxRequestSize(m_snmpCollection.getSnmpMaxRequestSize(agentConfig.getMaxRequestSize()));
    agentConfig.setSecurityName(m_snmpCollection.getSnmpSecurityName(agentConfig.getSecurityName()));
    agentConfig.setAuthPassPhrase(m_snmpCollection.getSnmpAuthPassPhrase(agentConfig.getAuthPassPhrase()));
    agentConfig.setAuthProtocol(m_snmpCollection.getSnmpAuthProtocol(agentConfig.getAuthProtocol()));
    agentConfig.setPrivPassPhrase(m_snmpCollection.getSnmpPrivPassPhrase(agentConfig.getPrivPassPhrase()));
    agentConfig.setPrivProtocol(m_snmpCollection.getSnmpPrivProtocol(agentConfig.getPrivProtocol()));
    return agentConfig;
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig)

Aggregations

SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)117 Test (org.junit.Test)31 InetAddress (java.net.InetAddress)30 JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)23 ArrayList (java.util.ArrayList)22 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)21 SnmpObjId (org.opennms.netmgt.snmp.SnmpObjId)20 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)16 PollStatus (org.opennms.netmgt.poller.PollStatus)14 Map (java.util.Map)11 ExecutionException (java.util.concurrent.ExecutionException)9 ParameterMap (org.opennms.core.utils.ParameterMap)9 SnmpWalker (org.opennms.netmgt.snmp.SnmpWalker)8 Date (java.util.Date)7 LldpLink (org.opennms.netmgt.model.LldpLink)7 OnmsNode (org.opennms.netmgt.model.OnmsNode)7 HashMap (java.util.HashMap)6 List (java.util.List)4 LldpLocPortGetter (org.opennms.netmgt.enlinkd.snmp.LldpLocPortGetter)4 LldpRemTableTracker (org.opennms.netmgt.enlinkd.snmp.LldpRemTableTracker)4