Search in sources :

Example 1 with NodePolicy

use of org.opennms.netmgt.provision.NodePolicy 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)

Aggregations

InetAddress (java.net.InetAddress)1 ExecutionException (java.util.concurrent.ExecutionException)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 NodePolicy (org.opennms.netmgt.provision.NodePolicy)1 SystemGroup (org.opennms.netmgt.provision.service.snmp.SystemGroup)1 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)1