Search in sources :

Example 1 with ServiceMonitorLocator

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

the class PollerFrontEndTest method anticipatePollServiceSetMonitorLocators.

private void anticipatePollServiceSetMonitorLocators() {
    ServiceMonitorLocator locator = new DefaultServiceMonitorLocator("HTTP", ServiceMonitor.class);
    Set<ServiceMonitorLocator> locators = Collections.singleton(locator);
    expect(m_backEnd.getServiceMonitorLocators(DistributionContext.REMOTE_MONITOR)).andReturn(locators);
    m_pollService.setServiceMonitorLocators(locators);
}
Also used : ServiceMonitorLocator(org.opennms.netmgt.poller.ServiceMonitorLocator) DefaultServiceMonitorLocator(org.opennms.netmgt.config.DefaultServiceMonitorLocator) DefaultServiceMonitorLocator(org.opennms.netmgt.config.DefaultServiceMonitorLocator)

Example 2 with ServiceMonitorLocator

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

the class PollerConfigManager method getServiceMonitorLocators.

/**
 * {@inheritDoc}
 */
@Override
public Collection<ServiceMonitorLocator> getServiceMonitorLocators(final DistributionContext context) {
    List<ServiceMonitorLocator> locators = new ArrayList<ServiceMonitorLocator>();
    try {
        getReadLock().lock();
        for (final Monitor monitor : monitors()) {
            try {
                final Class<? extends ServiceMonitor> mc = findServiceMonitorClass(monitor);
                if (isDistributableToContext(mc, context)) {
                    final ServiceMonitorLocator locator = new DefaultServiceMonitorLocator(monitor.getService(), mc);
                    locators.add(locator);
                }
                LOG.debug("Loaded monitor for service: {}, class-name: {}", monitor.getService(), monitor.getClassName());
            } catch (final ClassNotFoundException e) {
                LOG.warn("Unable to load monitor for service: {}, class-name: {}: {}", monitor.getService(), monitor.getClassName(), e.getMessage());
            } catch (ConfigObjectRetrievalFailureException e) {
                LOG.warn("{} {}", e.getMessage(), e.getRootCause(), e);
            }
        }
    } finally {
        getReadLock().unlock();
    }
    return locators;
}
Also used : ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) Monitor(org.opennms.netmgt.config.poller.Monitor) ArrayList(java.util.ArrayList) ServiceMonitorLocator(org.opennms.netmgt.poller.ServiceMonitorLocator)

Example 3 with ServiceMonitorLocator

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

the class PollerConfigManager method initializeServiceMonitors.

/**
 * @param poller
 * @return
 */
private void initializeServiceMonitors() {
    // Load up an instance of each monitor from the config
    // so that the event processor will have them for
    // new incoming events to create pollable service objects.
    // 
    LOG.debug("start: Loading monitors");
    final Collection<ServiceMonitorLocator> locators = getServiceMonitorLocators(DistributionContext.DAEMON);
    for (final ServiceMonitorLocator locator : locators) {
        try {
            m_svcMonitors.put(locator.getServiceName(), locator.getServiceMonitor(s_serviceMonitorRegistry));
        } catch (Throwable t) {
            LOG.warn("start: Failed to create monitor {} for service {}", locator.getServiceLocatorKey(), locator.getServiceName(), t);
        }
    }
}
Also used : ServiceMonitorLocator(org.opennms.netmgt.poller.ServiceMonitorLocator)

Example 4 with ServiceMonitorLocator

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

the class DefaultPollService method setServiceMonitorLocators.

/**
 * {@inheritDoc}
 */
@Override
public void setServiceMonitorLocators(Collection<ServiceMonitorLocator> locators) {
    Map<String, ServiceMonitor> monitors = new HashMap<String, ServiceMonitor>();
    for (ServiceMonitorLocator locator : locators) {
        monitors.put(locator.getServiceName(), locator.getServiceMonitor(s_serviceMonitorRegistry));
    }
    m_monitors = monitors;
}
Also used : ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) HashMap(java.util.HashMap) ServiceMonitorLocator(org.opennms.netmgt.poller.ServiceMonitorLocator)

Example 5 with ServiceMonitorLocator

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

the class DefaultPollerBackEnd method getServiceMonitorLocators.

/**
 * {@inheritDoc}
 */
@Transactional(readOnly = true)
@Override
public Collection<ServiceMonitorLocator> getServiceMonitorLocators(final DistributionContext context) {
    try {
        final List<ServiceMonitorLocator> locators = new ArrayList<>();
        final List<String> ex = Arrays.asList(System.getProperty("excludeServiceMonitorsFromRemotePoller", "").trim().split("\\s*,\\s*"));
        for (final ServiceMonitorLocator locator : m_pollerConfig.getServiceMonitorLocators(context)) {
            if (!ex.contains(locator.getServiceName())) {
                locators.add(locator);
            }
        }
        LOG.debug("getServiceMonitorLocators: Returning {} locators", locators.size());
        return locators;
    } catch (final Exception e) {
        LOG.warn("An error occurred getting the service monitor locators for distribution context: {}", context, e);
        return Collections.emptyList();
    }
}
Also used : ArrayList(java.util.ArrayList) ServiceMonitorLocator(org.opennms.netmgt.poller.ServiceMonitorLocator) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ServiceMonitorLocator (org.opennms.netmgt.poller.ServiceMonitorLocator)5 ArrayList (java.util.ArrayList)2 ServiceMonitor (org.opennms.netmgt.poller.ServiceMonitor)2 HashMap (java.util.HashMap)1 DefaultServiceMonitorLocator (org.opennms.netmgt.config.DefaultServiceMonitorLocator)1 Monitor (org.opennms.netmgt.config.poller.Monitor)1 ObjectRetrievalFailureException (org.springframework.orm.ObjectRetrievalFailureException)1 Transactional (org.springframework.transaction.annotation.Transactional)1