Search in sources :

Example 1 with SystemGroup

use of org.opennms.netmgt.provision.service.snmp.SystemGroup in project opennms by OpenNMS.

the class NodeInfoScan method collectNodeInfo.

private void collectNodeInfo() {
    Assert.notNull(getAgentConfigFactory(), "agentConfigFactory was not injected");
    InetAddress primaryAddress = getAgentAddress();
    SnmpAgentConfig agentConfig = getAgentConfig(primaryAddress);
    SystemGroup systemGroup = new SystemGroup(primaryAddress);
    try {
        try {
            m_provisionService.getLocationAwareSnmpClient().walk(agentConfig, systemGroup).withDescription("systemGroup").withLocation(getLocationName()).execute().get();
            systemGroup.updateSnmpDataForNode(getNode());
        } catch (ExecutionException e) {
            abort("Aborting node scan : Agent failed while scanning the system table: " + e.getMessage());
        }
        List<NodePolicy> nodePolicies = getProvisionService().getNodePoliciesForForeignSource(getEffectiveForeignSource());
        OnmsNode node = null;
        if (isAborted()) {
            if (getNodeId() != null && nodePolicies.size() > 0) {
                restoreCategories = true;
                node = m_provisionService.getDbNodeInitCat(getNodeId());
                LOG.debug("collectNodeInfo: checking {} node policies for restoration of categories", nodePolicies.size());
            }
        } else {
            node = getNode();
        }
        for (NodePolicy policy : nodePolicies) {
            if (node != null) {
                LOG.info("Applying NodePolicy {}({}) to {}", policy.getClass(), policy, node.getLabel());
                node = policy.apply(node);
            }
        }
        if (node == null) {
            restoreCategories = false;
            if (!isAborted()) {
                String reason = "Aborted scan of node due to configured policy";
                abort(reason);
            }
        } else {
            setNode(node);
        }
    } catch (final InterruptedException e) {
        abort("Aborting node scan : Scan thread interrupted!");
        Thread.currentThread().interrupt();
    }
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) OnmsNode(org.opennms.netmgt.model.OnmsNode) SystemGroup(org.opennms.netmgt.provision.service.snmp.SystemGroup) ExecutionException(java.util.concurrent.ExecutionException) InetAddress(java.net.InetAddress) NodePolicy(org.opennms.netmgt.provision.NodePolicy)

Example 2 with SystemGroup

use of org.opennms.netmgt.provision.service.snmp.SystemGroup 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<>();
        final Set<InetAddress> ipAddresses = new HashSet<>();
        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<>();
        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)

Aggregations

InetAddress (java.net.InetAddress)2 ExecutionException (java.util.concurrent.ExecutionException)2 SystemGroup (org.opennms.netmgt.provision.service.snmp.SystemGroup)2 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)2 Inet4Address (java.net.Inet4Address)1 HashSet (java.util.HashSet)1 TreeSet (java.util.TreeSet)1 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 NodePolicy (org.opennms.netmgt.provision.NodePolicy)1 IfTable (org.opennms.netmgt.provision.service.snmp.IfTable)1 IfXTable (org.opennms.netmgt.provision.service.snmp.IfXTable)1 IpAddrTable (org.opennms.netmgt.provision.service.snmp.IpAddrTable)1 AggregateTracker (org.opennms.netmgt.snmp.AggregateTracker)1 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)1