Search in sources :

Example 61 with OnmsIpInterface

use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.

the class VmwareTopologyProvider method addVirtualMachine.

private void addVirtualMachine(OnmsNode virtualMachine) {
    String vmwareManagementServer = virtualMachine.getAssetRecord().getVmwareManagementServer().trim();
    String vmwareManagedObjectId = virtualMachine.getAssetRecord().getVmwareManagedObjectId().trim();
    String vmwareState = virtualMachine.getAssetRecord().getVmwareState().trim();
    String primaryInterface = "unknown";
    OnmsIpInterface ipInterface = m_ipInterfaceDao.findPrimaryInterfaceByNodeId(virtualMachine.getId());
    if (ipInterface != null) {
        primaryInterface = ipInterface.getIpHostName();
    }
    Map<String, ParsedEntity> parsedEntities = parseNodeAssets(virtualMachine);
    String vmwareHostSystemId = parsedEntities.values().stream().filter(e -> "host".equals(e.getEntityType())).findFirst().map(ParsedEntity::getEntityId).orElse(null);
    if (vmwareHostSystemId == null) {
        LOG.warn("Cannot find host system id for virtual machine {}/{}", vmwareManagementServer, vmwareManagedObjectId);
    }
    AbstractVertex virtualMachineVertex = createVirtualMachineVertex(vmwareManagementServer + "/" + vmwareManagedObjectId, virtualMachine.getLabel(), primaryInterface, virtualMachine.getId(), vmwareState);
    addVertices(virtualMachineVertex);
    if (!containsVertexId(vmwareManagementServer + "/" + vmwareHostSystemId)) {
        LOG.warn("Cannot find associated vertex for host system {}/{}", vmwareManagementServer, vmwareHostSystemId);
    }
    connectVertices(vmwareManagementServer + "/" + vmwareManagedObjectId + "->" + vmwareManagementServer + "/" + vmwareHostSystemId, virtualMachineVertex, getVertex(getNamespace(), vmwareManagementServer + "/" + vmwareHostSystemId), getNamespace());
}
Also used : IpInterfaceDao(org.opennms.netmgt.dao.api.IpInterfaceDao) Arrays(java.util.Arrays) NodeDao(org.opennms.netmgt.dao.api.NodeDao) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Logger(org.slf4j.Logger) URLDecoder(java.net.URLDecoder) DefaultVertexHopCriteria(org.opennms.features.topology.api.support.VertexHopGraphProvider.DefaultVertexHopCriteria) AbstractTopologyProvider(org.opennms.features.topology.api.topo.AbstractTopologyProvider) LoggerFactory(org.slf4j.LoggerFactory) AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) List(java.util.List) Lists(com.google.common.collect.Lists) Map(java.util.Map) Defaults(org.opennms.features.topology.api.topo.Defaults) SelectionChangedListener(org.opennms.features.topology.api.browsers.SelectionChangedListener) VertexRef(org.opennms.features.topology.api.topo.VertexRef) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ContentType(org.opennms.features.topology.api.browsers.ContentType) OnmsNode(org.opennms.netmgt.model.OnmsNode) AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface)

Example 62 with OnmsIpInterface

use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.

the class NewSuspectScanIT method testScanNewSuspectWithForeignSource.

@Test(timeout = 300000)
@JUnitSnmpAgents({ @JUnitSnmpAgent(host = "198.51.100.201", resource = "classpath:/snmpTestData3.properties"), @JUnitSnmpAgent(host = "198.51.100.204", resource = "classpath:/snmpTestData3.properties") })
public void testScanNewSuspectWithForeignSource() throws Exception {
    final int nextNodeId = m_nodeDao.getNextNodeId();
    // Verify empty database
    assertEquals(1, getDistPollerDao().countAll());
    assertEquals(0, getNodeDao().countAll());
    assertEquals(0, getInterfaceDao().countAll());
    assertEquals(0, getMonitoredServiceDao().countAll());
    assertEquals(0, getServiceTypeDao().countAll());
    assertEquals(0, getSnmpInterfaceDao().countAll());
    final EventAnticipator anticipator = m_eventSubscriber.getEventAnticipator();
    anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_ADDED_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).getEvent());
    anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_GAINED_INTERFACE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(addr("198.51.100.201")).getEvent());
    anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_GAINED_INTERFACE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(addr("198.51.100.204")).getEvent());
    anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_GAINED_SERVICE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(addr("198.51.100.201")).setService("SNMP").getEvent());
    anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_GAINED_SERVICE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(addr("198.51.100.204")).setService("SNMP").getEvent());
    anticipator.anticipateEvent(new EventBuilder(EventConstants.REINITIALIZE_PRIMARY_SNMP_INTERFACE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(addr("198.51.100.201")).getEvent());
    anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_LABEL_CHANGED_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).getEvent());
    anticipator.anticipateEvent(new EventBuilder(EventConstants.PROVISION_SCAN_COMPLETE_UEI, "Provisiond").setNodeid(nextNodeId).getEvent());
    final String foreignSource = "Testie";
    NewSuspectScan scan = m_provisioner.createNewSuspectScan(addr("198.51.100.201"), foreignSource, MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID);
    runScan(scan);
    anticipator.verifyAnticipated(20000, 0, 0, 0, 0);
    // Verify distpoller count
    assertEquals(1, getDistPollerDao().countAll());
    // Verify node count
    assertEquals(1, getNodeDao().countAll());
    List<OnmsNode> onmsNodes = getNodeDao().findByLabel("brozow.local");
    OnmsNode onmsNode = onmsNodes.get(0);
    assertEquals("Testie", onmsNode.getForeignSource());
    assertEquals(MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID, onmsNode.getLocation().getLocationName());
    final StringBuilder errorMsg = new StringBuilder();
    // Verify ipinterface count
    for (final OnmsIpInterface iface : getInterfaceDao().findAll()) {
        errorMsg.append(iface.toString());
    }
    assertEquals(errorMsg.toString(), 2, getInterfaceDao().countAll());
    // Verify ifservices count - discover snmp service on other if
    assertEquals("Unexpected number of services found.", 2, getMonitoredServiceDao().countAll());
    // Verify service count
    assertEquals(1, getServiceTypeDao().countAll());
    // Verify snmpInterface count
    assertEquals(6, getSnmpInterfaceDao().countAll());
    // NMS-8835: Now send another new suspect event for the same IP address and foreignSource
    scan = m_provisioner.createNewSuspectScan(addr("198.51.100.201"), foreignSource, MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID);
    runScan(scan);
    // The node count should not increase
    assertEquals(1, getNodeDao().countAll());
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) EventAnticipator(org.opennms.netmgt.dao.mock.EventAnticipator) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Example 63 with OnmsIpInterface

use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.

the class ProvisionerIT method testPopulateWithIpv6SnmpAndNodeScan.

// fail if we take more than five minutes
@Test(timeout = 300000)
@JUnitSnmpAgents({ @JUnitSnmpAgent(host = "10.1.15.245", resource = "classpath:/snmpwalk-demo.properties"), @JUnitSnmpAgent(host = "10.3.20.23", resource = "classpath:/snmpwalk-demo.properties"), @JUnitSnmpAgent(host = "2001:0470:e2f1:cafe:16c1:7cff:12d6:7bb9", resource = "classpath:/snmpwalk-demo.properties") })
public void testPopulateWithIpv6SnmpAndNodeScan() throws Exception {
    final ForeignSource fs = new ForeignSource();
    fs.setName("matt:");
    fs.addDetector(new PluginConfig("SNMP", "org.opennms.netmgt.provision.detector.snmp.SnmpDetector"));
    m_foreignSourceRepository.putDefaultForeignSource(fs);
    importFromResource("classpath:/requisition_then_scanv6.xml", Boolean.TRUE.toString());
    // Verify distpoller count
    assertEquals(1, getDistPollerDao().countAll());
    // Verify node count
    assertEquals(1, getNodeDao().countAll());
    // Verify ipinterface count
    assertEquals(1, getInterfaceDao().countAll());
    // Verify ifservices count
    assertEquals(1, getMonitoredServiceDao().countAll());
    // Verify service count
    assertEquals(1, getServiceTypeDao().countAll());
    // Verify snmpInterface count
    assertEquals(1, getSnmpInterfaceDao().countAll());
    runPendingScans();
    // Verify distpoller count
    assertEquals(1, getDistPollerDao().countAll());
    // Verify node count
    assertEquals(1, getNodeDao().countAll());
    // Verify ipinterface count
    assertEquals("Unexpected number of IP interfaces found: " + getInterfaceDao().findAll(), 3, getInterfaceDao().countAll());
    // Verify ifservices count - discover snmp service on other if
    assertEquals("Unexpected number of services found: " + getMonitoredServiceDao().findAll(), 3, getMonitoredServiceDao().countAll());
    // Verify service count
    assertEquals("Unexpected number of service types found: " + getServiceTypeDao().findAll(), 1, getServiceTypeDao().countAll());
    // Verify snmpInterface count
    assertEquals("Unexpected number of SNMP interfaces found: " + getSnmpInterfaceDao().findAll(), 6, getSnmpInterfaceDao().countAll());
    // Ensure that collection is on for all ip interfaces
    for (OnmsIpInterface iface : getInterfaceDao().findAll()) {
        OnmsSnmpInterface snmpIface = iface.getSnmpInterface();
        assertNotNull("Expected an snmp interface associated with " + iface.getIpAddress(), snmpIface);
        assertTrue("Expected snmp interface associated with " + iface.getIpAddress() + " to have collection enabled.", snmpIface.isCollectionEnabled());
    }
}
Also used : PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Example 64 with OnmsIpInterface

use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.

the class DefaultResourceDaoTest method testFindNodeResourcesWithResponseTime.

@Test
public void testFindNodeResourcesWithResponseTime() throws Exception {
    List<OnmsNode> nodes = new LinkedList<>();
    OnmsNode node = createNode();
    OnmsIpInterface ip = createIpInterface();
    node.addIpInterface(ip);
    nodes.add(node);
    expect(m_nodeDao.findAll()).andReturn(nodes);
    File response = m_fileAnticipator.tempDir("response");
    File ipDir = m_fileAnticipator.tempDir(response, "192.168.1.1");
    m_fileAnticipator.tempFile(ipDir, "icmp" + m_rrdFileExtension);
    expect(m_resourceTypesDao.getLastUpdate()).andReturn(m_lastUpdateTime);
    m_easyMockUtils.replayAll();
    List<OnmsResource> resources = m_resourceDao.findTopLevelResources();
    m_easyMockUtils.verifyAll();
    assertNotNull("resource list should not be null", resources);
    assertEquals("resource list size", 1, resources.size());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) File(java.io.File) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 65 with OnmsIpInterface

use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.

the class DefaultResourceDaoTest method testFindNodeResourcesWithNodeSnmp.

@Test
public void testFindNodeResourcesWithNodeSnmp() throws Exception {
    List<OnmsNode> nodes = new LinkedList<>();
    OnmsNode node = createNode();
    OnmsIpInterface ip = createIpInterface();
    node.addIpInterface(ip);
    nodes.add(node);
    expect(m_nodeDao.findAll()).andReturn(nodes);
    File snmp = m_fileAnticipator.tempDir("snmp");
    File nodeDir = m_fileAnticipator.tempDir(snmp, "1");
    m_fileAnticipator.tempFile(nodeDir, "foo" + m_rrdFileExtension);
    expect(m_resourceTypesDao.getLastUpdate()).andReturn(m_lastUpdateTime);
    m_easyMockUtils.replayAll();
    List<OnmsResource> resources = m_resourceDao.findTopLevelResources();
    m_easyMockUtils.verifyAll();
    assertNotNull("resource list should not be null", resources);
    assertEquals("resource list size", 1, resources.size());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) File(java.io.File) LinkedList(java.util.LinkedList) Test(org.junit.Test)

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