Search in sources :

Example 96 with OnmsIpInterface

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();
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) DeleteEventVisitor(org.opennms.netmgt.model.events.DeleteEventVisitor) Transactional(org.springframework.transaction.annotation.Transactional)

Example 97 with OnmsIpInterface

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

Example 98 with OnmsIpInterface

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;
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface)

Example 99 with OnmsIpInterface

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();
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Example 100 with OnmsIpInterface

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();
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Aggregations

OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)186 OnmsNode (org.opennms.netmgt.model.OnmsNode)117 Test (org.junit.Test)53 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)43 InetAddress (java.net.InetAddress)40 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)33 Transactional (org.springframework.transaction.annotation.Transactional)30 ArrayList (java.util.ArrayList)22 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)21 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)20 Date (java.util.Date)17 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)17 File (java.io.File)16 HashMap (java.util.HashMap)15 Before (org.junit.Before)15 LinkedList (java.util.LinkedList)14 IpInterfaceDao (org.opennms.netmgt.dao.api.IpInterfaceDao)14 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)12 OnmsEventParameter (org.opennms.netmgt.model.OnmsEventParameter)12 OnmsResource (org.opennms.netmgt.model.OnmsResource)11