Search in sources :

Example 6 with OnmsNode

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

Example 7 with OnmsNode

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

Example 8 with OnmsNode

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);
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) Event(org.opennms.netmgt.xml.event.Event) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 9 with OnmsNode

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());
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test)

Example 10 with OnmsNode

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()));
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) Event(org.opennms.netmgt.xml.event.Event) Test(org.junit.Test)

Aggregations

OnmsNode (org.opennms.netmgt.model.OnmsNode)438 Test (org.junit.Test)187 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)99 Transactional (org.springframework.transaction.annotation.Transactional)76 ArrayList (java.util.ArrayList)48 Date (java.util.Date)40 JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)38 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)36 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)31 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)31 InetAddress (java.net.InetAddress)28 OnmsResource (org.opennms.netmgt.model.OnmsResource)28 Before (org.junit.Before)27 OnmsCategory (org.opennms.netmgt.model.OnmsCategory)26 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)26 File (java.io.File)24 HashMap (java.util.HashMap)23 List (java.util.List)21 Path (javax.ws.rs.Path)21 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)20