Search in sources :

Example 31 with PollStatus

use of org.opennms.netmgt.poller.PollStatus in project opennms by OpenNMS.

the class PollerBackEndTest method testStatusChangeFromDownToUp.

public void testStatusChangeFromDownToUp() {
    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(m_dnsCurrentStatus);
    // called when saving performance data
    expect(m_monitoringLocationDao.get(m_locationDefinition.getLocationName())).andReturn(m_locationDefinition);
    expect(m_pollerConfig.getPackage(m_package.getName())).andReturn(m_package);
    expect(m_pollerConfig.getServiceInPackage("DNS", m_package)).andReturn(m_dnsSvcConfig).times(3);
    expect(m_pollerConfig.parameters(m_dnsSvcConfig)).andReturn(m_dnsSvcConfig.getParameters()).times(6);
    final PollStatus newStatus = PollStatus.available(1234.0);
    OnmsLocationSpecificStatus expectedStatus = new OnmsLocationSpecificStatus(m_locationMonitor, m_dnsService, newStatus);
    // TODO: make anticipate method
    EventBuilder eventBuilder = new EventBuilder(EventConstants.REMOTE_NODE_REGAINED_SERVICE_UEI, "PollerBackEnd").setMonitoredService(m_dnsService).addParam(EventConstants.PARM_LOCATION_MONITOR_ID, LOCATION_MONITOR_ID);
    m_eventIpcManager.getEventAnticipator().anticipateEvent(eventBuilder.getEvent());
    m_locMonDao.saveStatusChange(isA(OnmsLocationSpecificStatus.class));
    expectLastCall().andAnswer(new StatusChecker(expectedStatus));
    m_mocks.replayAll();
    m_backEnd.saveResponseTimeData(m_locationMonitor.getId(), m_dnsService, 1234, m_package);
    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 32 with PollStatus

use of org.opennms.netmgt.poller.PollStatus 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 33 with PollStatus

use of org.opennms.netmgt.poller.PollStatus 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 34 with PollStatus

use of org.opennms.netmgt.poller.PollStatus in project opennms by OpenNMS.

the class PassiveServiceMonitorIT method testPoll.

// inherit from PassiveStatusKeeperTest so we can inherit all the proper initialization
public void testPoll() throws UnknownHostException {
    PassiveStatusKeeper psk = PassiveStatusKeeper.getInstance();
    psk.setStatus("localhost", "127.0.0.1", "my-passive-service", PollStatus.get(PollStatus.SERVICE_UNAVAILABLE, "testing failure"));
    ServiceMonitor sm = new PassiveServiceMonitor();
    MonitoredService ms = createMonitoredService(1, "localhost", null, "127.0.0.1", "my-passive-service");
    PollStatus ps = sm.poll(ms, new HashMap<String, Object>());
    assertEquals(PollStatus.down("fail."), ps);
    psk.setStatus("localhost", "127.0.0.1", "my-passive-service", PollStatus.get(PollStatus.SERVICE_AVAILABLE, "testing failure"));
    ps = sm.poll(ms, new HashMap<String, Object>());
    assertEquals(PollStatus.up(), ps);
}
Also used : ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) PollStatus(org.opennms.netmgt.poller.PollStatus) HashMap(java.util.HashMap) MonitoredService(org.opennms.netmgt.poller.MonitoredService) PassiveStatusKeeper(org.opennms.netmgt.passive.PassiveStatusKeeper)

Example 35 with PollStatus

use of org.opennms.netmgt.poller.PollStatus in project opennms by OpenNMS.

the class HostResourceSWRunMonitorTest method testInvalidRange.

@Test
public void testInvalidRange() throws Exception {
    // warning is expected here, skip the assert in tearDown()
    m_ignoreWarnings = true;
    Map<String, Object> parameters = createBasicParams();
    parameters.put("min-services", "8");
    parameters.put("max-services", "5");
    PollStatus status = monitor.poll(createMonitor(), parameters);
    Assert.assertFalse(status.isAvailable());
    log(status.getReason());
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) Test(org.junit.Test)

Aggregations

PollStatus (org.opennms.netmgt.poller.PollStatus)209 Test (org.junit.Test)98 MonitoredService (org.opennms.netmgt.poller.MonitoredService)57 ServiceMonitor (org.opennms.netmgt.poller.ServiceMonitor)53 InetAddress (java.net.InetAddress)40 HashMap (java.util.HashMap)36 MockMonitoredService (org.opennms.netmgt.poller.mock.MockMonitoredService)36 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)32 TimeoutTracker (org.opennms.core.utils.TimeoutTracker)29 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)18 IOException (java.io.IOException)17 Socket (java.net.Socket)17 InputStreamReader (java.io.InputStreamReader)16 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)14 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)14 BufferedReader (java.io.BufferedReader)13 SnmpObjId (org.opennms.netmgt.snmp.SnmpObjId)12 InterruptedIOException (java.io.InterruptedIOException)11 ConnectException (java.net.ConnectException)11 NoRouteToHostException (java.net.NoRouteToHostException)11