Search in sources :

Example 11 with Package

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

the class DefaultPollerBackEnd method reportResult.

/**
 * {@inheritDoc}
 */
@Override
public void reportResult(final String locationMonitorId, final int serviceId, final PollStatus pollResult) {
    final OnmsLocationMonitor locationMonitor;
    try {
        locationMonitor = m_locMonDao.get(locationMonitorId);
    } catch (final Exception e) {
        LOG.info("Unable to report result for location monitor ID {}: Location monitor does not exist.", locationMonitorId, e);
        return;
    }
    if (locationMonitor == null) {
        LOG.info("Unable to report result for location monitor ID {}: Location monitor does not exist.", locationMonitorId);
        return;
    }
    final OnmsMonitoredService monSvc;
    try {
        monSvc = m_monSvcDao.get(serviceId);
    } catch (final Exception e) {
        LOG.warn("Unable to report result for location monitor ID {}, monitored service ID {}: Monitored service does not exist.", locationMonitorId, serviceId, e);
        return;
    }
    if (monSvc == null) {
        LOG.warn("Unable to report result for location monitor ID {}, monitored service ID {}: Monitored service does not exist.", locationMonitorId, serviceId);
        return;
    }
    if (pollResult == null) {
        LOG.warn("Unable to report result for location monitor ID {}, monitored service ID {}: Poll result is null!", locationMonitorId, serviceId);
        return;
    }
    final OnmsLocationSpecificStatus newStatus = new OnmsLocationSpecificStatus(locationMonitor, monSvc, pollResult);
    try {
        if (newStatus.getPollResult().getResponseTime() != null) {
            final Package pkg = getPollingPackageForMonitorAndService(locationMonitor, monSvc);
            saveResponseTimeData(locationMonitorId, monSvc, newStatus.getPollResult().getResponseTime(), pkg);
        }
    } catch (final Exception e) {
        LOG.error("Unable to save response time data for location monitor ID {}, monitored service ID {}.", locationMonitorId, serviceId, e);
    }
    try {
        final OnmsLocationSpecificStatus currentStatus = m_locMonDao.getMostRecentStatusChange(locationMonitor, monSvc);
        processStatusChange(currentStatus, newStatus);
    } catch (final Exception e) {
        LOG.error("Unable to save result for location monitor ID {}, monitored service ID {}.", locationMonitorId, serviceId, e);
    }
}
Also used : OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) Package(org.opennms.netmgt.config.poller.Package) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 12 with Package

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

the class PollablesIT method addServiceToNetwork.

private PollableService addServiceToNetwork(final PollableNetwork pNetwork, int nodeId, String nodeLabel, String nodeLocation, String ipAddr, String serviceName, Number svcLostEventId, String svcLostUei, Date svcLostTime, final ScheduleTimer scheduler, final PollerConfig pollerConfig, final PollOutagesConfig pollOutageConfig) {
    InetAddress addr = getInetAddress(ipAddr);
    Package pkg = findPackageForService(pollerConfig, ipAddr, serviceName);
    if (pkg == null) {
        MockUtil.println("No package for service " + serviceName + " with ipAddr " + ipAddr);
        return null;
    }
    PollableService svc = pNetwork.createService(nodeId, nodeLabel, nodeLocation, addr, serviceName);
    PollableServiceConfig pollConfig = new PollableServiceConfig(svc, pollerConfig, pollOutageConfig, pkg, scheduler, m_persisterFactory, m_resourceStorageDao, m_locationAwarePollerClient);
    svc.setPollConfig(pollConfig);
    synchronized (svc) {
        if (svc.getSchedule() == null) {
            Schedule schedule = new Schedule(svc, pollConfig, scheduler);
            svc.setSchedule(schedule);
        }
    }
    // MockUtil.println("svcLostEventId for "+svc+" is "+svcLostEventId);
    if (svcLostEventId == null) {
        if (svc.getParent().getStatus().isUnknown()) {
            svc.updateStatus(PollStatus.up());
        } else {
            svc.updateStatus(svc.getParent().getStatus());
            svc.setCause(svc.getParent().getCause());
        }
    } else {
        svc.updateStatus(PollStatus.down());
        PollEvent cause = new DbPollEvent(svcLostEventId.intValue(), svcLostUei, svcLostTime);
        svc.setCause(cause);
    }
    return svc;
}
Also used : Schedule(org.opennms.netmgt.scheduler.Schedule) Package(org.opennms.netmgt.config.poller.Package) InetAddress(java.net.InetAddress)

Example 13 with Package

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

the class PollablesIT method testDowntimeInterval.

@Test
public void testDowntimeInterval() {
    // HERE ARE the calls to setup the downtime model
    // m_pollerConfig.addDowntime(100L, 0L, 500L, false);
    // m_pollerConfig.addDowntime(200L, 500L, 1500L, false);
    // m_pollerConfig.addDowntime(500L, 1500L, -1L, true);
    Package pkg = m_pollerConfig.getPackage("TestPackage");
    PollableServiceConfig pollConfig = new PollableServiceConfig(pDot1Smtp, m_pollerConfig, m_pollerConfig, pkg, m_timer, m_persisterFactory, m_resourceStorageDao, m_locationAwarePollerClient);
    m_timer.setCurrentTime(1000L);
    pDot1Smtp.updateStatus(PollStatus.down());
    assertEquals(1000, pDot1Smtp.getStatusChangeTime());
    assertDown(pDot1Smtp);
    pDot1.resetStatusChanged();
    assertEquals(100L, pollConfig.getInterval());
    m_timer.setCurrentTime(1234L);
    assertEquals(100L, pollConfig.getInterval());
    m_timer.setCurrentTime(1500L);
    assertEquals(200L, pollConfig.getInterval());
    m_timer.setCurrentTime(1700L);
    assertEquals(200L, pollConfig.getInterval());
    m_timer.setCurrentTime(2500L);
    assertEquals(-1L, pollConfig.getInterval());
}
Also used : Package(org.opennms.netmgt.config.poller.Package) Test(org.junit.Test)

Example 14 with Package

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

the class PollerBackEndTest method createPackage.

private static Package createPackage(String pkgName, String filterRule) {
    Package pkg = new Package();
    pkg.setName(pkgName);
    pkg.setFilter(new Filter());
    pkg.getFilter().setContent(filterRule);
    return pkg;
}
Also used : Filter(org.opennms.netmgt.config.poller.Filter) Package(org.opennms.netmgt.config.poller.Package)

Example 15 with Package

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

the class DefaultPollerBackEnd method createPollerConfiguration.

private SimplePollerConfiguration createPollerConfiguration(String pollingPackageName) {
    final Package pkg = getPollingPackage(pollingPackageName);
    final ServiceSelector selector = m_pollerConfig.getServiceSelectorForPackage(pkg);
    final Collection<OnmsMonitoredService> services = m_monSvcDao.findMatchingServices(selector);
    final List<PolledService> configs = new ArrayList<PolledService>(services.size());
    LOG.debug("Found {} services in polling package {}", services.size(), pollingPackageName);
    for (final OnmsMonitoredService monSvc : services) {
        final Service serviceConfig = m_pollerConfig.getServiceInPackage(monSvc.getServiceName(), pkg);
        final long interval = serviceConfig.getInterval();
        final Map<String, Object> parameters = getParameterMap(serviceConfig);
        if (LOG.isTraceEnabled()) {
            for (Map.Entry<String, Object> entry : parameters.entrySet()) {
                LOG.trace("Service {} has parameter {} with type {} and value: {}", monSvc.getServiceName(), entry.getKey(), entry.getValue() != null ? entry.getValue().getClass().getCanonicalName() : "null", entry.getValue());
            }
        }
        configs.add(new PolledService(monSvc, parameters, new OnmsPollModel(interval)));
    }
    Collections.sort(configs);
    return new SimplePollerConfiguration(getConfigurationTimestamp(), configs.toArray(new PolledService[configs.size()]));
}
Also used : OnmsPollModel(org.opennms.netmgt.poller.remote.OnmsPollModel) ServiceSelector(org.opennms.netmgt.model.ServiceSelector) ArrayList(java.util.ArrayList) PolledService(org.opennms.netmgt.poller.remote.PolledService) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Service(org.opennms.netmgt.config.poller.Service) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) PolledService(org.opennms.netmgt.poller.remote.PolledService) Package(org.opennms.netmgt.config.poller.Package) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

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