Search in sources :

Example 21 with Package

use of org.opennms.netmgt.config.poller.Package in project opennms by OpenNMS.

the class PollablesIT method testAlternateDowntimeInterval.

@Test
public void testAlternateDowntimeInterval() {
    // HERE ARE the calls to setup the downtime model
    // m_pollerConfig.addDowntime(500L, 0L, 1000L, false);
    // m_pollerConfig.addDowntime(500L, 1000L, -1L, true);
    // m_pollerConfig.setDefaultPollInterval(2000L);
    // m_pollerConfig.addService(m_mockNetwork.getService(2, "192.168.1.3", "HTTP"));
    // mDot3Http/pDot3Http
    final Package pkg = m_pollerConfig.getPackage("TestPkg2");
    final PollableServiceConfig pollConfig = new PollableServiceConfig(pDot3Http, m_pollerConfig, m_pollerConfig, pkg, m_timer, m_persisterFactory, m_resourceStorageDao, m_locationAwarePollerClient);
    m_timer.setCurrentTime(1000L);
    pDot3Http.updateStatus(PollStatus.down());
    assertEquals(1000, pDot3Http.getStatusChangeTime());
    assertChanged(pDot3Http);
    assertDown(pDot3Http);
    assertEquals(500L, pollConfig.getInterval());
    m_timer.setCurrentTime(1234L);
    assertEquals(500L, pollConfig.getInterval());
    m_timer.setCurrentTime(1500L);
    assertEquals(500L, pollConfig.getInterval());
    m_timer.setCurrentTime(1700L);
    assertEquals(500L, pollConfig.getInterval());
    m_timer.setCurrentTime(2000L);
    assertEquals(-1L, pollConfig.getInterval());
    LOG.debug(".3 HTTP: {}: status={}, changetime={}", pDot3Http, pDot3Http.getStatus(), pDot3Http.getStatusChangeTime());
}
Also used : Package(org.opennms.netmgt.config.poller.Package) Test(org.junit.Test)

Example 22 with Package

use of org.opennms.netmgt.config.poller.Package in project opennms by OpenNMS.

the class PollablesIT method findPackageForService.

protected Package findPackageForService(PollerConfig pollerConfig, String ipAddr, String serviceName) {
    Enumeration<Package> en = pollerConfig.enumeratePackage();
    Package lastPkg = null;
    while (en.hasMoreElements()) {
        Package pkg = (Package) en.nextElement();
        if (pollableServiceInPackage(pollerConfig, ipAddr, serviceName, pkg))
            lastPkg = pkg;
    }
    return lastPkg;
}
Also used : Package(org.opennms.netmgt.config.poller.Package)

Example 23 with Package

use of org.opennms.netmgt.config.poller.Package in project opennms by OpenNMS.

the class Poller method findPackageForService.

Package findPackageForService(String ipAddr, String serviceName) {
    Enumeration<Package> en = m_pollerConfig.enumeratePackage();
    Package lastPkg = null;
    while (en.hasMoreElements()) {
        Package pkg = (Package) en.nextElement();
        if (pollableServiceInPackage(ipAddr, serviceName, pkg))
            lastPkg = pkg;
    }
    return lastPkg;
}
Also used : Package(org.opennms.netmgt.config.poller.Package)

Example 24 with Package

use of org.opennms.netmgt.config.poller.Package in project opennms by OpenNMS.

the class PollerConfigWithPSMIT method testPSM.

@Test
public void testPSM() throws Exception {
    InputStream is = new FileInputStream(new File("src/test/resources/etc/psm-poller-configuration.xml"));
    PollerConfigFactory factory = new PollerConfigFactory(0, is, "localhost", false);
    PollerConfigFactory.setInstance(factory);
    IOUtils.closeQuietly(is);
    ServiceMonitor monitor = PollerConfigFactory.getInstance().getServiceMonitor("MQ_API_DirectRte_v2");
    Assert.assertNotNull(monitor);
    Package pkg = PollerConfigFactory.getInstance().getPackage("MapQuest");
    Assert.assertNotNull(pkg);
    Service svc = PollerConfigFactory.getInstance().getServiceInPackage("MQ_API_DirectRte_v2", pkg);
    Assert.assertNotNull(svc);
    Map<String, Object> parameters = new HashMap<String, Object>();
    for (Parameter p : svc.getParameters()) {
        parameters.put(p.getKey(), p.getValue() == null ? p.getAnyObject() : p.getValue());
    }
    PollStatus status = monitor.poll(new MockMonitoredService(1, "www.mapquest.com", InetAddress.getByName("www.mapquest.com"), "MQ_API_DirectRte_v2"), parameters);
    Assert.assertEquals(PollStatus.SERVICE_AVAILABLE, status.getStatusCode());
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) HashMap(java.util.HashMap) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) Service(org.opennms.netmgt.config.poller.Service) FileInputStream(java.io.FileInputStream) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) Parameter(org.opennms.netmgt.config.poller.Parameter) Package(org.opennms.netmgt.config.poller.Package) File(java.io.File) Test(org.junit.Test)

Example 25 with Package

use of org.opennms.netmgt.config.poller.Package 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)

Aggregations

Package (org.opennms.netmgt.config.poller.Package)31 Service (org.opennms.netmgt.config.poller.Service)11 Test (org.junit.Test)10 PollStatus (org.opennms.netmgt.poller.PollStatus)6 File (java.io.File)5 Rrd (org.opennms.netmgt.config.poller.Rrd)5 FileInputStream (java.io.FileInputStream)4 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)4 PersisterFactory (org.opennms.netmgt.collection.api.PersisterFactory)4 PollOutagesConfig (org.opennms.netmgt.config.PollOutagesConfig)4 Filter (org.opennms.netmgt.config.poller.Filter)4 ResourceStorageDao (org.opennms.netmgt.dao.api.ResourceStorageDao)4 FilesystemResourceStorageDao (org.opennms.netmgt.dao.support.FilesystemResourceStorageDao)4 MockPersisterFactory (org.opennms.netmgt.mock.MockPersisterFactory)4 Timer (org.opennms.netmgt.scheduler.Timer)4 InetAddress (java.net.InetAddress)3 Properties (java.util.Properties)3 PollerConfig (org.opennms.netmgt.config.PollerConfig)3 PollerConfigFactory (org.opennms.netmgt.config.PollerConfigFactory)3