Search in sources :

Example 1 with NodeListModel

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

the class NodeListController method handle.

@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST })
public ModelAndView handle(@ModelAttribute("command") NodeListCommand command) {
    NodeListModel model = m_nodeListService.createNodeList(command);
    ModelAndView modelAndView = new ModelAndView("element/nodeList", "model", model);
    modelAndView.addObject("command", command);
    return modelAndView;
}
Also used : NodeListModel(org.opennms.web.svclayer.model.NodeListModel) ModelAndView(org.springframework.web.servlet.ModelAndView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with NodeListModel

use of org.opennms.web.svclayer.model.NodeListModel 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<>();
    for (OnmsNode node : onmsNodes) {
        List<OnmsIpInterface> displayInterfaces = new LinkedList<>();
        List<OnmsSnmpInterface> displaySnmpInterfaces = new LinkedList<>();
        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

NodeListModel (org.opennms.web.svclayer.model.NodeListModel)2 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 NodeModel (org.opennms.web.svclayer.model.NodeListModel.NodeModel)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1