use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class ResponseTimeResourceType method getResourcesForParent.
private List<OnmsResource> getResourcesForParent(OnmsResource parent, boolean stopAfterFirst) {
if (!NodeResourceType.isNode(parent)) {
return Collections.emptyList();
}
// Grab the node entity
final OnmsNode node = ResourceTypeUtils.getNodeFromResource(parent);
// Determine the location name
final String locationName = MonitoringLocationUtils.getLocationNameOrNullIfDefault(node);
// Verify the existence of the individual interfaces
final LinkedList<OnmsResource> resources = new LinkedList<>();
for (final OnmsIpInterface i : node.getIpInterfaces()) {
String ipAddr = InetAddressUtils.str(i.getIpAddress());
final ResourcePath path = getInterfacePath(locationName, ipAddr);
if (m_resourceStorageDao.exists(path, 0)) {
resources.add(createResource(locationName, i, ipAddr, path));
if (stopAfterFirst) {
break;
}
}
}
return resources;
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class NotificationManagerIT method setUp.
@Before
public void setUp() throws Exception {
// Initialize Filter DAO
DatabaseSchemaConfigFactory.init();
JdbcFilterDao jdbcFilterDao = new JdbcFilterDao();
jdbcFilterDao.setDataSource(m_dataSource);
jdbcFilterDao.setDatabaseSchemaConfigFactory(DatabaseSchemaConfigFactory.getInstance());
jdbcFilterDao.afterPropertiesSet();
FilterDaoFactory.setInstance(jdbcFilterDao);
m_configManager = new MockNotifdConfigManager(ConfigurationTestUtils.getConfigForResourceWithReplacements(this, "notifd-configuration.xml"));
m_notificationManager = new NotificationManagerIT.NotificationManagerImpl(m_configManager, m_dataSource);
OnmsNode node;
OnmsIpInterface ipInterface;
OnmsMonitoredService service;
OnmsServiceType serviceType;
OnmsCategory category1 = new OnmsCategory("CategoryOne");
m_categoryDao.save(category1);
OnmsCategory category2 = new OnmsCategory("CategoryTwo");
m_categoryDao.save(category2);
OnmsCategory category3 = new OnmsCategory("CategoryThree");
m_categoryDao.save(category3);
OnmsCategory category4 = new OnmsCategory("CategoryFour");
m_categoryDao.save(category4);
m_categoryDao.flush();
serviceType = new OnmsServiceType("ICMP");
m_serviceTypeDao.save(serviceType);
serviceType = new OnmsServiceType("HTTP");
m_serviceTypeDao.save(serviceType);
// node 1
node = new OnmsNode(m_locationDao.getDefaultLocation(), "node 1");
node.addCategory(category1);
node.addCategory(category2);
node.addCategory(category3);
node1 = node;
ipInterface = new OnmsIpInterface(addr("192.168.1.1"), node);
ipInterfaceOnNode1 = ipInterface;
service = new OnmsMonitoredService(ipInterface, serviceType);
m_nodeDao.save(node);
// node 2
node = new OnmsNode(m_locationDao.getDefaultLocation(), "node 2");
node.addCategory(category1);
node.addCategory(category2);
node.addCategory(category4);
m_nodeDao.save(node);
ipInterface = new OnmsIpInterface(addr("192.168.1.1"), node);
m_ipInterfaceDao.save(ipInterface);
service = new OnmsMonitoredService(ipInterface, serviceType);
m_serviceDao.save(service);
ipInterface = new OnmsIpInterface(addr("0.0.0.0"), node);
m_ipInterfaceDao.save(ipInterface);
// node 3
node = new OnmsNode(m_locationDao.getDefaultLocation(), "node 3");
m_nodeDao.save(node);
ipInterface = new OnmsIpInterface(addr("192.168.1.2"), node);
m_ipInterfaceDao.save(ipInterface);
service = new OnmsMonitoredService(ipInterface, serviceType);
m_serviceDao.save(service);
// node 4 has an interface, but no services
node = new OnmsNode(m_locationDao.getDefaultLocation(), "node 4");
m_nodeDao.save(node);
ipInterface = new OnmsIpInterface(addr("192.168.1.3"), node);
m_ipInterfaceDao.save(ipInterface);
// node 5 has no interfaces
node = new OnmsNode(m_locationDao.getDefaultLocation(), "node 5");
m_nodeDao.save(node);
m_nodeDao.flush();
m_ipInterfaceDao.flush();
m_serviceDao.flush();
m_serviceTypeDao.flush();
m_categoryDao.flush();
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class EventDaoIT method testSave.
@Test
@Transactional
public void testSave() {
OnmsEvent event = new OnmsEvent();
event.setDistPoller(m_distPollerDao.whoami());
event.setEventCreateTime(new Date());
event.setEventDescr("event dao test");
event.setEventHost("localhost");
event.setEventLog("Y");
event.setEventDisplay("Y");
event.setEventLogGroup("event dao test log group");
event.setEventLogMsg("event dao test log msg");
event.setEventSeverity(OnmsSeverity.CRITICAL.getId());
event.setEventSource("EventDaoTest");
event.setEventTime(new Date());
event.setEventUei("uei://org/opennms/test/EventDaoTest");
OnmsNode node = (OnmsNode) m_nodeDao.findAll().iterator().next();
OnmsIpInterface iface = (OnmsIpInterface) node.getIpInterfaces().iterator().next();
OnmsMonitoredService service = (OnmsMonitoredService) iface.getMonitoredServices().iterator().next();
event.setNode(node);
event.setServiceType(service.getServiceType());
OnmsAlarm alarm = new OnmsAlarm();
event.setAlarm(alarm);
event.setIpAddr(iface.getIpAddress());
event.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event, "label", "node", "string"), new OnmsEventParameter(event, "ds", "(memAvailReal + memCached) / memTotalReal * 100.0", "string"), new OnmsEventParameter(event, "description", "(memAvailReal + memCached) / memTotalReal * 100.0", "string"), new OnmsEventParameter(event, "value", "4.7", "string"), new OnmsEventParameter(event, "instance", "node", "string"), new OnmsEventParameter(event, "instanceLabel", "node", "string"), new OnmsEventParameter(event, "resourceId", "node[70].nodeSnmp[]", "string"), new OnmsEventParameter(event, "threshold", "5.0", "string"), new OnmsEventParameter(event, "trigger", "2", "string"), new OnmsEventParameter(event, "rearm", "10.0", "string")));
m_eventDao.save(event);
OnmsEvent newEvent = m_eventDao.load(event.getId());
assertEquals("uei://org/opennms/test/EventDaoTest", newEvent.getEventUei());
assertNotNull(newEvent.getServiceType());
assertEquals(service.getNodeId(), newEvent.getNode().getId());
assertEquals(event.getIpAddr(), newEvent.getIpAddr());
System.err.println(JaxbUtils.marshal(event));
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class InterfaceToNodeCacheDaoImplIT method testDuplicate.
@Test
public void testDuplicate() throws Exception {
final OnmsMonitoringLocation defaultLocation = m_monitoringLocationDao.getDefaultLocation();
final InetAddress theAddress = InetAddress.getByName("1.2.3.4");
Assert.assertNotNull(m_interfaceToNodeCache);
final OnmsNode node1 = new OnmsNode(defaultLocation, "node1");
final OnmsIpInterface iface1 = new OnmsIpInterface();
iface1.setIpAddress(theAddress);
iface1.setIsSnmpPrimary(PrimaryType.PRIMARY);
node1.addIpInterface(iface1);
final int nodeId1 = m_nodeDao.save(node1);
m_interfaceToNodeCache.setNodeId(defaultLocation.getLocationName(), iface1.getIpAddress(), node1.getId());
Assert.assertEquals(nodeId1, (int) m_interfaceToNodeCache.getFirstNodeId(defaultLocation.getLocationName(), theAddress).get());
final OnmsNode node2 = new OnmsNode(defaultLocation, "node2");
final OnmsIpInterface iface2 = new OnmsIpInterface();
iface2.setIpAddress(theAddress);
iface2.setIsSnmpPrimary(PrimaryType.PRIMARY);
node2.addIpInterface(iface2);
final int nodeId2 = m_nodeDao.save(node2);
m_interfaceToNodeCache.setNodeId(defaultLocation.getLocationName(), iface2.getIpAddress(), node2.getId());
Assert.assertEquals(nodeId1, (int) m_interfaceToNodeCache.getFirstNodeId(defaultLocation.getLocationName(), theAddress).get());
m_interfaceToNodeCache.removeNodeId(defaultLocation.getLocationName(), theAddress, nodeId1);
Assert.assertEquals(nodeId2, (int) m_interfaceToNodeCache.getFirstNodeId(defaultLocation.getLocationName(), theAddress).get());
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class NodeDaoIT method testQueryWithHierarchyCloseTransaction.
/**
* Test for bug 1594
*/
@Test
@Transactional
public void testQueryWithHierarchyCloseTransaction() throws Exception {
OnmsNode n = getNodeHierarchy(getNode1().getId());
validateNode(n);
for (OnmsIpInterface ip : n.getIpInterfaces()) {
ip.getIpAddress();
for (OnmsMonitoredService service : ip.getMonitoredServices()) {
service.getServiceName();
}
}
// Test for bug 1594
for (OnmsSnmpInterface snmp : n.getSnmpInterfaces()) {
for (OnmsIpInterface ip : snmp.getIpInterfaces()) {
ip.getIpAddress();
}
}
}
Aggregations