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