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);
}
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;
}
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);
}
}
}
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;
}
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();
}
}
Aggregations