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);
}
Aggregations