Search in sources :

Example 1 with Monitor

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

the class PollerConfigServlet method removeMonitor.

/**
     * <p>removeMonitor</p>
     * 
     * FIXME: I think that this should be using Iterator.remove()
     *
     * @param service a {@link java.lang.String} object.
     */
public void removeMonitor(String service) {
    // Add the new monitor with the protocol.
    Collection<Monitor> monitorColl = pollerConfig.getMonitors();
    Monitor newMonitor = new Monitor();
    if (monitorColl != null) {
        for (Monitor mon : monitorColl) {
            if (mon != null) {
                if (mon.getService().equals(service)) {
                    newMonitor.setService(service);
                    newMonitor.setClassName(mon.getClassName());
                    newMonitor.setParameters(mon.getParameters());
                    break;
                }
            }
        }
        monitorColl.remove(newMonitor);
    }
}
Also used : Monitor(org.opennms.netmgt.config.poller.Monitor)

Example 2 with Monitor

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

the class PollerConfigManager method addMonitor.

/** {@inheritDoc} */
@Override
public void addMonitor(final String svcName, final String className) {
    try {
        getWriteLock().lock();
        final Monitor monitor = new Monitor();
        monitor.setService(svcName);
        monitor.setClassName(className);
        m_config.addMonitor(monitor);
    } finally {
        getWriteLock().unlock();
    }
}
Also used : ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) Monitor(org.opennms.netmgt.config.poller.Monitor)

Example 3 with Monitor

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

Aggregations

Monitor (org.opennms.netmgt.config.poller.Monitor)3 ServiceMonitor (org.opennms.netmgt.poller.ServiceMonitor)2 ArrayList (java.util.ArrayList)1 ServiceMonitorLocator (org.opennms.netmgt.poller.ServiceMonitorLocator)1