Search in sources :

Example 46 with EventBuilder

use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.

the class PollerBackEndTest method testStatusChangeFromUpToDown.

// reportResult test variations
// what if we cant' find the locationMonitor with that ID
// what if we can't find the service with that ID
// what if we can't find a current status
// do I send events for status changed
public void testStatusChangeFromUpToDown() {
    expect(m_locMonDao.get(LOCATION_MONITOR_ID)).andReturn(m_locationMonitor);
    expect(m_monSvcDao.get(1)).andReturn(m_httpService);
    expect(m_locMonDao.getMostRecentStatusChange(m_locationMonitor, m_httpService)).andReturn(m_httpCurrentStatus);
    // TODO: make anticipate method
    EventBuilder eventBuilder = new EventBuilder(EventConstants.REMOTE_NODE_LOST_SERVICE_UEI, "PollerBackEnd").setMonitoredService(m_httpService).addParam(EventConstants.PARM_LOCATION_MONITOR_ID, LOCATION_MONITOR_ID);
    m_eventIpcManager.getEventAnticipator().anticipateEvent(eventBuilder.getEvent());
    final PollStatus newStatus = PollStatus.unavailable("Test Down");
    OnmsLocationSpecificStatus expectedStatus = new OnmsLocationSpecificStatus(m_locationMonitor, m_httpService, newStatus);
    m_locMonDao.saveStatusChange(isA(OnmsLocationSpecificStatus.class));
    expectLastCall().andAnswer(new StatusChecker(expectedStatus));
    m_mocks.replayAll();
    m_backEnd.reportResult(LOCATION_MONITOR_ID, 1, newStatus);
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) PollStatus(org.opennms.netmgt.poller.PollStatus) OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus)

Example 47 with EventBuilder

use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.

the class PollerBackEndTest method testStatusDownWhenNoneKnown.

public void testStatusDownWhenNoneKnown() {
    expect(m_locMonDao.get(LOCATION_MONITOR_ID)).andReturn(m_locationMonitor);
    expect(m_monSvcDao.get(2)).andReturn(m_dnsService);
    expect(m_locMonDao.getMostRecentStatusChange(m_locationMonitor, m_dnsService)).andReturn(null);
    final PollStatus newStatus = PollStatus.unavailable("where'd he go?");
    OnmsLocationSpecificStatus expectedStatus = new OnmsLocationSpecificStatus(m_locationMonitor, m_dnsService, newStatus);
    m_locMonDao.saveStatusChange(isA(OnmsLocationSpecificStatus.class));
    expectLastCall().andAnswer(new StatusChecker(expectedStatus));
    // expect a status change if the node is now down and we didn't know before
    EventBuilder eventBuilder = new EventBuilder(EventConstants.REMOTE_NODE_LOST_SERVICE_UEI, "PollerBackEnd").setMonitoredService(m_dnsService).addParam(EventConstants.PARM_LOCATION_MONITOR_ID, LOCATION_MONITOR_ID);
    m_eventIpcManager.getEventAnticipator().anticipateEvent(eventBuilder.getEvent());
    m_mocks.replayAll();
    m_backEnd.reportResult(LOCATION_MONITOR_ID, 2, newStatus);
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus)

Example 48 with EventBuilder

use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.

the class ConfigureSnmpTest method createConfigureSnmpEventBuilder.

private EventBuilder createConfigureSnmpEventBuilder(final String firstIp, final String lastIp) {
    EventBuilder bldr = new EventBuilder(EventConstants.CONFIGURE_SNMP_EVENT_UEI, "ConfigureSnmpTest");
    bldr.addParam(EventConstants.PARM_FIRST_IP_ADDRESS, firstIp);
    bldr.addParam(EventConstants.PARM_LAST_IP_ADDRESS, lastIp);
    return bldr;
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder)

Example 49 with EventBuilder

use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.

the class MockPollContext method createEvent.

@Override
public Event createEvent(String uei, int nodeId, InetAddress address, String svcName, Date date, String reason) {
    EventBuilder e = MockEventUtil.createEventBuilder("Test", uei, nodeId, (address == null ? null : InetAddressUtils.str(address)), svcName, reason);
    e.setTime(date);
    return e.getEvent();
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder)

Example 50 with EventBuilder

use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.

the class LatencyStoringServiceMonitorAdaptorIT method testThresholds.

@Test
@JUnitTemporaryDatabase(tempDbClass = MockDatabase.class)
public void testThresholds() throws Exception {
    EventBuilder bldr = new EventBuilder(EventConstants.HIGH_THRESHOLD_EVENT_UEI, "LatencyStoringServiceMonitorAdaptorTest");
    bldr.setNodeid(1);
    bldr.setInterface(addr("127.0.0.1"));
    bldr.setService("ICMP");
    m_eventIpcManager.getEventAnticipator().anticipateEvent(bldr.getEvent());
    bldr = new EventBuilder(EventConstants.HIGH_THRESHOLD_REARM_EVENT_UEI, "LatencyStoringServiceMonitorAdaptorTest");
    bldr.setNodeid(1);
    bldr.setInterface(addr("127.0.0.1"));
    bldr.setService("ICMP");
    m_eventIpcManager.getEventAnticipator().anticipateEvent(bldr.getEvent());
    // This should emulate a trigger and a rearm
    executeThresholdTest(new Double[] { 100.0, 10.0 });
    m_eventIpcManager.getEventAnticipator().verifyAnticipated();
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Aggregations

EventBuilder (org.opennms.netmgt.model.events.EventBuilder)305 Test (org.junit.Test)88 Event (org.opennms.netmgt.xml.event.Event)84 Date (java.util.Date)22 OnmsNode (org.opennms.netmgt.model.OnmsNode)17 InetAddress (java.net.InetAddress)16 EventProxyException (org.opennms.netmgt.events.api.EventProxyException)15 AlarmData (org.opennms.netmgt.xml.event.AlarmData)14 EventAnticipator (org.opennms.netmgt.dao.mock.EventAnticipator)12 ServletException (javax.servlet.ServletException)9 EventHandler (org.opennms.netmgt.events.api.annotations.EventHandler)9 Parm (org.opennms.netmgt.xml.event.Parm)9 Event (org.opennms.netmgt.xml.eventconf.Event)9 File (java.io.File)8 ArrayList (java.util.ArrayList)8 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)7 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)7 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)7 SyntaxToEvent (org.opennms.netmgt.model.events.snmp.SyntaxToEvent)7 Transactional (org.springframework.transaction.annotation.Transactional)6