Search in sources :

Example 1 with PollEvent

use of org.opennms.netmgt.poller.pollables.PollEvent in project opennms by OpenNMS.

the class PollContextIT method testOpenResolveOutage.

@Test
public void testOpenResolveOutage() throws Exception {
    Event downEvent = m_mSvc.createDownEvent();
    m_outageAnticipator.anticipateOutageOpened(m_mSvc, downEvent);
    PollEvent pollDownEvent = m_pollContext.sendEvent(downEvent);
    m_pollContext.openOutage(m_pSvc, pollDownEvent);
    verifyOutages();
    m_outageAnticipator.reset();
    Event upEvent = m_mSvc.createUpEvent();
    m_outageAnticipator.anticipateOutageClosed(m_mSvc, upEvent);
    PollEvent pollUpEvent = m_pollContext.sendEvent(upEvent);
    m_pollContext.resolveOutage(m_pSvc, pollUpEvent);
    verifyOutages();
    // doing this a second time to ensure the database doesn't hose the outages
    // this was added to detect an actual bug
    Event downEvent2 = m_mSvc.createDownEvent();
    m_outageAnticipator.anticipateOutageOpened(m_mSvc, downEvent2);
    PollEvent pollDownEvent2 = m_pollContext.sendEvent(downEvent2);
    m_pollContext.openOutage(m_pSvc, pollDownEvent2);
    verifyOutages();
    m_outageAnticipator.reset();
    Event upEvent2 = m_mSvc.createUpEvent();
    m_outageAnticipator.anticipateOutageClosed(m_mSvc, upEvent2);
    PollEvent pollUpEvent2 = m_pollContext.sendEvent(upEvent2);
    m_pollContext.resolveOutage(m_pSvc, pollUpEvent2);
    verifyOutages();
}
Also used : PollEvent(org.opennms.netmgt.poller.pollables.PollEvent) Event(org.opennms.netmgt.xml.event.Event) PollEvent(org.opennms.netmgt.poller.pollables.PollEvent) Test(org.junit.Test)

Example 2 with PollEvent

use of org.opennms.netmgt.poller.pollables.PollEvent in project opennms by OpenNMS.

the class Poller method scheduleService.

private boolean scheduleService(OnmsMonitoredService service) {
    final OnmsIpInterface iface = service.getIpInterface();
    final Set<OnmsOutage> outages = service.getCurrentOutages();
    final OnmsOutage outage = (outages == null || outages.size() < 1 ? null : outages.iterator().next());
    final OnmsEvent event = (outage == null ? null : outage.getServiceLostEvent());
    final String ipAddr = InetAddressUtils.str(iface.getIpAddress());
    final String serviceName = service.getServiceName();
    boolean active = "A".equals(service.getStatus());
    final Number svcLostEventId = event == null ? null : event.getId();
    final Date ifLostService = outage == null ? null : outage.getIfLostService();
    final String svcLostUei = event == null ? null : event.getEventUei();
    closeOutageIfSvcLostEventIsMissing(outage);
    // We don't want to adjust the management state of the service if we're
    // on a machine that uses multiple servers with access to the same database
    // so check the value of OpennmsServerConfigFactory.getInstance().verifyServer()
    // before doing any updates.
    final Package pkg = findPackageForService(ipAddr, serviceName);
    final boolean verifyServer = OpennmsServerConfigFactory.getInstance().verifyServer();
    if (pkg == null) {
        if (active && !verifyServer) {
            LOG.warn("Active service {} on {} not configured for any package. Marking as Not Polled.", serviceName, ipAddr);
            updateServiceStatus(service, "N");
        }
        return false;
    } else if (!active && !verifyServer) {
        LOG.info("Active service {} on {} is now configured for a package. Marking as active.", serviceName, ipAddr);
        updateServiceStatus(service, "A");
    }
    ServiceMonitor monitor = m_pollerConfig.getServiceMonitor(serviceName);
    if (monitor == null) {
        LOG.info("Could not find service monitor associated with service {}", serviceName);
        return false;
    }
    InetAddress addr;
    addr = InetAddressUtils.addr(ipAddr);
    if (addr == null) {
        LOG.error("Could not convert {} as an InetAddress {}", ipAddr, ipAddr);
        return false;
    }
    PollableService svc = getNetwork().createService(service.getNodeId(), iface.getNode().getLabel(), iface.getNode().getLocation().getLocationName(), addr, serviceName);
    PollableServiceConfig pollConfig = new PollableServiceConfig(svc, m_pollerConfig, m_pollOutagesConfig, pkg, getScheduler(), m_persisterFactory, m_resourceStorageDao, m_locationAwarePollerClient);
    svc.setPollConfig(pollConfig);
    synchronized (svc) {
        if (svc.getSchedule() == null) {
            Schedule schedule = new Schedule(svc, pollConfig, getScheduler());
            svc.setSchedule(schedule);
        }
    }
    if (svcLostEventId == null) {
        if (svc.getParent().getStatus().isUnknown()) {
            svc.updateStatus(PollStatus.up());
        } else {
            svc.updateStatus(svc.getParent().getStatus());
        }
    } else {
        svc.updateStatus(PollStatus.down());
        PollEvent cause = new DbPollEvent(svcLostEventId.intValue(), svcLostUei, ifLostService);
        svc.setCause(cause);
    }
    svc.schedule();
    return true;
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) DbPollEvent(org.opennms.netmgt.poller.pollables.DbPollEvent) Date(java.util.Date) PollEvent(org.opennms.netmgt.poller.pollables.PollEvent) DbPollEvent(org.opennms.netmgt.poller.pollables.DbPollEvent) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) PollableServiceConfig(org.opennms.netmgt.poller.pollables.PollableServiceConfig) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) PollableService(org.opennms.netmgt.poller.pollables.PollableService) Schedule(org.opennms.netmgt.scheduler.Schedule) Package(org.opennms.netmgt.config.poller.Package) InetAddress(java.net.InetAddress)

Example 3 with PollEvent

use of org.opennms.netmgt.poller.pollables.PollEvent in project opennms by OpenNMS.

the class PollContextIT method testSendEvent.

@Test
public void testSendEvent() {
    m_eventMgr.getEventAnticipator().anticipateEvent(m_mSvc.createDownEvent());
    PollEvent e = m_pollContext.sendEvent(m_mSvc.createDownEvent());
    m_eventMgr.finishProcessingEvents();
    assertNotNull(e);
    assertTrue("Invalid Event Id", e.getEventId() > 0);
    assertEquals(0, m_eventMgr.getEventAnticipator().waitForAnticipated(0).size());
    assertEquals(0, m_eventMgr.getEventAnticipator().getUnanticipatedEvents().size());
}
Also used : PollEvent(org.opennms.netmgt.poller.pollables.PollEvent) Test(org.junit.Test)

Aggregations

PollEvent (org.opennms.netmgt.poller.pollables.PollEvent)3 Test (org.junit.Test)2 InetAddress (java.net.InetAddress)1 Date (java.util.Date)1 Package (org.opennms.netmgt.config.poller.Package)1 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)1 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)1 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)1 DbPollEvent (org.opennms.netmgt.poller.pollables.DbPollEvent)1 PollableService (org.opennms.netmgt.poller.pollables.PollableService)1 PollableServiceConfig (org.opennms.netmgt.poller.pollables.PollableServiceConfig)1 Schedule (org.opennms.netmgt.scheduler.Schedule)1 Event (org.opennms.netmgt.xml.event.Event)1