Search in sources :

Example 1 with NodeModel

use of org.opennms.web.svclayer.model.NodeListModel.NodeModel in project opennms by OpenNMS.

the class DefaultNodeListService method createModelForNodes.

private static NodeListModel createModelForNodes(NodeListCommand command, Collection<OnmsNode> onmsNodes) {
    int interfaceCount = 0;
    List<NodeModel> displayNodes = new LinkedList<NodeModel>();
    for (OnmsNode node : onmsNodes) {
        List<OnmsIpInterface> displayInterfaces = new LinkedList<OnmsIpInterface>();
        List<OnmsSnmpInterface> displaySnmpInterfaces = new LinkedList<OnmsSnmpInterface>();
        if (command.getListInterfaces()) {
            if (command.hasSnmpParm() && command.getSnmpParmMatchType().equals("contains")) {
                String parmValueMatchString = (".*" + command.getSnmpParmValue().toLowerCase().replaceAll("([\\W])", "\\\\$0").replaceAll("\\\\%", ".*").replaceAll("_", ".") + ".*");
                if (command.getSnmpParm().equals("ifAlias")) {
                    for (OnmsSnmpInterface snmpIntf : node.getSnmpInterfaces()) {
                        if (snmpIntf != null && !"D".equals(snmpIntf.getCollect()) && snmpIntf.getIfAlias() != null && snmpIntf.getIfAlias().toLowerCase().matches(parmValueMatchString)) {
                            displaySnmpInterfaces.add(snmpIntf);
                        }
                    }
                } else if (command.getSnmpParm().equals("ifName")) {
                    for (OnmsSnmpInterface snmpIntf : node.getSnmpInterfaces()) {
                        if (snmpIntf != null && !"D".equals(snmpIntf.getCollect()) && snmpIntf.getIfName() != null && snmpIntf.getIfName().toLowerCase().matches(parmValueMatchString)) {
                            displaySnmpInterfaces.add(snmpIntf);
                        }
                    }
                } else if (command.getSnmpParm().equals("ifDescr")) {
                    for (OnmsSnmpInterface snmpIntf : node.getSnmpInterfaces()) {
                        if (snmpIntf != null && !"D".equals(snmpIntf.getCollect()) && snmpIntf.getIfDescr() != null && snmpIntf.getIfDescr().toLowerCase().matches(parmValueMatchString)) {
                            displaySnmpInterfaces.add(snmpIntf);
                        }
                    }
                }
            } else if (command.hasSnmpParm() && command.getSnmpParmMatchType().equals("equals")) {
                if (command.getSnmpParm().equals("ifAlias")) {
                    for (OnmsSnmpInterface snmpIntf : node.getSnmpInterfaces()) {
                        if (snmpIntf != null && !"D".equals(snmpIntf.getCollect()) && snmpIntf.getIfAlias() != null && snmpIntf.getIfAlias().equalsIgnoreCase(command.getSnmpParmValue())) {
                            displaySnmpInterfaces.add(snmpIntf);
                        }
                    }
                } else if (command.getSnmpParm().equals("ifName")) {
                    for (OnmsSnmpInterface snmpIntf : node.getSnmpInterfaces()) {
                        if (snmpIntf != null && !"D".equals(snmpIntf.getCollect()) && snmpIntf.getIfName() != null && snmpIntf.getIfName().equalsIgnoreCase(command.getSnmpParmValue())) {
                            displaySnmpInterfaces.add(snmpIntf);
                        }
                    }
                } else if (command.getSnmpParm().equals("ifDescr")) {
                    for (OnmsSnmpInterface snmpIntf : node.getSnmpInterfaces()) {
                        if (snmpIntf != null && !"D".equals(snmpIntf.getCollect()) && snmpIntf.getIfDescr() != null && snmpIntf.getIfDescr().equalsIgnoreCase(command.getSnmpParmValue())) {
                            displaySnmpInterfaces.add(snmpIntf);
                        }
                    }
                }
            } else if (command.hasMaclike()) {
                String macLikeStripped = command.getMaclike().toLowerCase().replaceAll("[:-]", "");
                for (OnmsSnmpInterface snmpIntf : node.getSnmpInterfaces()) {
                    if (snmpIntf.getPhysAddr() != null && !"D".equals(snmpIntf.getCollect()) && snmpIntf.getPhysAddr().toLowerCase().contains(macLikeStripped)) {
                        displaySnmpInterfaces.add(snmpIntf);
                    }
                }
            } else {
                for (OnmsIpInterface intf : node.getIpInterfaces()) {
                    if (!"D".equals(intf.getIsManaged()) && !"0.0.0.0".equals(InetAddressUtils.str(intf.getIpAddress()))) {
                        displayInterfaces.add(intf);
                    }
                }
            }
        }
        Collections.sort(displayInterfaces, IP_INTERFACE_COMPARATOR);
        Collections.sort(displaySnmpInterfaces, SNMP_INTERFACE_COMPARATOR);
        displayNodes.add(new NodeListModel.NodeModel(node, displayInterfaces, displaySnmpInterfaces));
        interfaceCount += displayInterfaces.size();
        interfaceCount += displaySnmpInterfaces.size();
    }
    return new NodeListModel(displayNodes, interfaceCount);
}
Also used : NodeModel(org.opennms.web.svclayer.model.NodeListModel.NodeModel) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) NodeModel(org.opennms.web.svclayer.model.NodeListModel.NodeModel) NodeListModel(org.opennms.web.svclayer.model.NodeListModel) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) LinkedList(java.util.LinkedList)

Aggregations

LinkedList (java.util.LinkedList)1 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)1 NodeListModel (org.opennms.web.svclayer.model.NodeListModel)1 NodeModel (org.opennms.web.svclayer.model.NodeListModel.NodeModel)1