use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class DefaultProvisionService method deleteObsoleteInterfaces.
/**
* {@inheritDoc}
*/
@Transactional
@Override
public void deleteObsoleteInterfaces(final Integer nodeId, final Date scanStamp) {
final List<OnmsIpInterface> obsoleteInterfaces = m_nodeDao.findObsoleteIpInterfaces(nodeId, scanStamp);
final EventAccumulator accumulator = new EventAccumulator(m_eventForwarder);
for (final OnmsIpInterface iface : obsoleteInterfaces) {
iface.visit(new DeleteEventVisitor(accumulator));
}
m_nodeDao.deleteObsoleteInterfaces(nodeId, scanStamp);
accumulator.flush();
}
use of org.opennms.netmgt.model.OnmsIpInterface 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);
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class DefaultResourceDaoTest method createIpInterfaceOnNode.
private OnmsIpInterface createIpInterfaceOnNode() throws UnknownHostException {
OnmsIpInterface ip = createIpInterface();
createNode().addIpInterface(ip);
return ip;
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class ProvisionerIT method testDowntimeModelDeleteServiceEventDiscoveryEnabledDeletionDisabledDiscoveredNode.
@Test
@JUnitSnmpAgents({ @JUnitSnmpAgent(host = "198.51.100.201", resource = "classpath:/snmpTestData3.properties"), @JUnitSnmpAgent(host = "198.51.100.204", resource = "classpath:/snmpTestData3.properties") })
public void testDowntimeModelDeleteServiceEventDiscoveryEnabledDeletionDisabledDiscoveredNode() throws Exception {
System.setProperty("org.opennms.provisiond.enableDiscovery", "true");
assertTrue(m_provisionService.isDiscoveryEnabled());
final NewSuspectScan scan = m_provisioner.createNewSuspectScan(addr("198.51.100.201"), null, null);
runScan(scan);
assertEquals(2, m_ipInterfaceDao.findAll().size());
LOG.debug("ifaces = {}", m_ipInterfaceDao.findAll());
final List<OnmsIpInterface> ifaces = m_ipInterfaceDao.findByIpAddress("198.51.100.201");
assertEquals(1, ifaces.size());
final OnmsNode node = ifaces.iterator().next().getNode();
assertEquals(2, node.getIpInterfaces().size());
// SNMP on each of the 2 interfaces
assertEquals(2, getMonitoredServiceDao().findAll().size());
m_eventAnticipator.reset();
// the service and interface should be deleted
// since there is another interface, the node remains
m_eventAnticipator.anticipateEvent(serviceDeleted(node.getId(), "198.51.100.201", "SNMP"));
m_eventAnticipator.anticipateEvent(interfaceDeleted(node.getId(), "198.51.100.201"));
getScheduledExecutor().resume();
m_mockEventIpcManager.sendEventToListeners(deleteService(node.getId(), "198.51.100.201", "SNMP"));
m_eventAnticipator.waitForAnticipated(10000);
m_eventAnticipator.verifyAnticipated();
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class ProvisionerIT method testDowntimeModelDeleteServiceEventDiscoveryEnabledDeletionDisabledDiscoveredNodeSingleInterface.
@Test
@JUnitSnmpAgents({ @JUnitSnmpAgent(host = "198.51.100.201", resource = "classpath:/snmpwalk-system.properties") })
public void testDowntimeModelDeleteServiceEventDiscoveryEnabledDeletionDisabledDiscoveredNodeSingleInterface() throws Exception {
System.setProperty("org.opennms.provisiond.enableDiscovery", "true");
assertTrue(m_provisionService.isDiscoveryEnabled());
final NewSuspectScan scan = m_provisioner.createNewSuspectScan(addr("198.51.100.201"), null, null);
runScan(scan);
assertEquals(1, m_ipInterfaceDao.findAll().size());
LOG.debug("ifaces = {}", m_ipInterfaceDao.findAll());
final List<OnmsIpInterface> ifaces = m_ipInterfaceDao.findByIpAddress("198.51.100.201");
assertEquals(1, ifaces.size());
final OnmsNode node = ifaces.iterator().next().getNode();
assertEquals(1, node.getIpInterfaces().size());
m_eventAnticipator.reset();
// everything up to the node should be deleted, since there is only a single interface with a single service
// since there is another interface, the node remains
m_eventAnticipator.anticipateEvent(serviceDeleted(node.getId(), "198.51.100.201", "SNMP"));
m_eventAnticipator.anticipateEvent(interfaceDeleted(node.getId(), "198.51.100.201"));
m_eventAnticipator.anticipateEvent(nodeDeleted(node.getId()));
getScheduledExecutor().resume();
m_mockEventIpcManager.sendEventToListeners(deleteService(node.getId(), "198.51.100.201", "SNMP"));
m_eventAnticipator.waitForAnticipated(10000);
m_eventAnticipator.verifyAnticipated();
}
Aggregations