use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.
the class EifTranslatorTest method setUp.
@Before
public void setUp() {
OnmsNode fqhostnameNode = new OnmsNode(m_locationDao.getDefaultLocation(), "localhost.localdomain");
OnmsNode shortnameNode = new OnmsNode(m_locationDao.getDefaultLocation(), "localhost");
OnmsNode originNode = new OnmsNode(m_locationDao.getDefaultLocation(), "10.0.0.7");
fqhostnameNode.setForeignSource("eifTestSource");
fqhostnameNode.setForeignId("eifTestId");
shortnameNode.setForeignSource("eifTestSource");
shortnameNode.setForeignId("eifTestId");
originNode.setForeignSource("eifTestSource");
originNode.setForeignId("eifTestId");
fqhostnameNode.setId(1);
shortnameNode.setId(2);
originNode.setId(3);
m_nodeDao.saveOrUpdate(fqhostnameNode);
m_nodeDao.saveOrUpdate(shortnameNode);
m_nodeDao.saveOrUpdate(originNode);
m_nodeDao.flush();
}
use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.
the class EventUtilHibernateIT method getHardwareFieldValue.
@Test
public void getHardwareFieldValue() {
OnmsNode node1 = m_populator.getNode1();
OnmsHwEntity hwEntity = new OnmsHwEntity();
hwEntity.setNode(node1);
hwEntity.setEntPhysicalIndex(0);
hwEntity.setEntPhysicalName("Chassis");
hwEntity.setEntPhysicalDescr("some-physical-d3scr");
m_hwEntityDao.save(hwEntity);
// Access the field by index
String hwfield = eventUtilDaoImpl.getHardwareFieldValue("hardware[0:entPhysicalDescr]", node1.getId());
assertEquals("some-physical-d3scr", hwfield);
// Access the field by name
hwfield = eventUtilDaoImpl.getHardwareFieldValue("hardware[Chassis:entPhysicalDescr]", node1.getId());
assertEquals("some-physical-d3scr", hwfield);
// Access the field by regex
hwfield = eventUtilDaoImpl.getHardwareFieldValue("hardware[~%Cha%:entPhysicalDescr]", node1.getId());
assertEquals("some-physical-d3scr", hwfield);
}
use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.
the class EventUtilHibernateIT method testExpandParms.
@Test
@JUnitTemporaryDatabase
public void testExpandParms() {
String testString = "%uei%:%nodeid%:%nodelabel%:%nodelocation%";
/*
* Checking default location
*/
Event event1 = new EventBuilder("testUei", "testSource").setNodeid(1).getEvent();
String string1 = eventUtilDaoImpl.expandParms(testString, event1);
assertEquals("testUei:1:node1:Default", string1);
/*
* Checking custom location
*/
OnmsNode onmsNode = m_populator.getNodeDao().get(2);
onmsNode.setLocation(m_populator.getMonitoringLocationDao().get("RDU"));
m_populator.getNodeDao().update(onmsNode);
Event event2 = new EventBuilder("testUei", "testSource").setNodeid(2).getEvent();
String string2 = eventUtilDaoImpl.expandParms(testString, event2);
assertEquals("testUei:2:node2:RDU", string2);
}
use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.
the class EventdIT method testPersistEventWithService.
/**
* Test that eventd's service ID lookup works properly.
*/
@Test(timeout = 30000)
public void testPersistEventWithService() throws Exception {
CriteriaBuilder cb = new CriteriaBuilder(OnmsEvent.class);
cb.eq("eventUei", EventConstants.SERVICE_UNRESPONSIVE_EVENT_UEI);
assertEquals(0, m_eventDao.countMatching(cb.toCriteria()));
assertNotNull(m_serviceTypeDao.findByName("ICMP"));
OnmsNode node = m_databasePopulator.getNode1();
assertNotNull(node);
OnmsIpInterface intf = node.getIpInterfaceByIpAddress("192.168.1.1");
assertNotNull(intf);
System.err.println("services = " + intf.getMonitoredServices());
OnmsMonitoredService svc = intf.getMonitoredServiceByServiceType("ICMP");
assertNotNull(svc);
assertEquals("192.168.1.1", str(svc.getIpAddress()));
final Integer serviceId = svc.getServiceId();
sendServiceDownEvent(null, svc);
while (m_eventDao.countMatching(cb.toCriteria()) != 1) {
Thread.sleep(SLEEP_TIME);
}
assertEquals(1, m_eventDao.countMatching(cb.toCriteria()));
assertEquals("service ID for event", serviceId, m_eventDao.findMatching(cb.toCriteria()).get(0).getServiceType().getId());
}
use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.
the class EventdIT method testPersistEvent.
@Test(timeout = 30000)
public void testPersistEvent() throws Exception {
CriteriaBuilder cb = new CriteriaBuilder(OnmsEvent.class);
cb.eq("eventUei", EventConstants.NODE_DOWN_EVENT_UEI);
assertEquals(0, m_eventDao.countMatching(cb.toCriteria()));
OnmsNode node = m_databasePopulator.getNode1();
assertNotNull(node);
sendNodeDownEvent(null, node);
while (m_eventDao.countMatching(cb.toCriteria()) < 1) {
Thread.sleep(SLEEP_TIME);
}
final List<OnmsEvent> matching = m_eventDao.findMatching(cb.toCriteria());
System.err.println("matching = " + matching);
assertEquals(1, m_eventDao.countMatching(cb.toCriteria()));
node = m_databasePopulator.getNode2();
assertNotNull(node);
Event generatedEvent = sendNodeDownEvent(null, node);
while (m_eventDao.countMatching(cb.toCriteria()) < 2) {
Thread.sleep(SLEEP_TIME);
}
assertEquals(2, m_eventDao.countMatching(cb.toCriteria()));
assertNull(generatedEvent.getInterfaceAddress());
cb.isNull("ipAddr");
assertEquals("failed, found: " + m_eventDao.findMatching(cb.toCriteria()), 2, m_eventDao.countMatching(cb.toCriteria()));
}
Aggregations