use of org.opennms.netmgt.poller.remote.PolledService in project opennms by OpenNMS.
the class DefaultPollerFrontEnd method doLoadConfig.
private void doLoadConfig() {
Date oldTime = getCurrentConfigTimestamp();
try {
m_pollService.setServiceMonitorLocators(m_backEnd.getServiceMonitorLocators(DistributionContext.REMOTE_MONITOR));
m_pollerConfiguration = retrieveLatestConfiguration();
synchronized (m_pollState) {
int i = 0;
m_pollState.clear();
// Initialize the monitor for the service
for (final PolledService service : getPolledServices()) {
m_pollState.put(service.getServiceId(), new ServicePollState(service, i++));
}
}
fireConfigurationChange(oldTime, getCurrentConfigTimestamp());
} catch (final Throwable e) {
LOG.warn("Unable to get updated poller configuration.", e);
if (m_pollerConfiguration == null) {
m_pollerConfiguration = new EmptyPollerConfiguration();
}
}
}
use of org.opennms.netmgt.poller.remote.PolledService in project opennms by OpenNMS.
the class DefaultPollerBackEnd method getApplicationsForLocation.
@Transactional(readOnly = true)
@Override
public Set<String> getApplicationsForLocation(final String location) {
final Set<String> retval = new HashSet<>();
PollerConfiguration config = getPollerConfigurationForLocation(location);
for (PolledService service : config.getPolledServices()) {
retval.addAll(service.getApplications());
}
return Collections.unmodifiableSet(retval);
}
use of org.opennms.netmgt.poller.remote.PolledService in project opennms by OpenNMS.
the class ScanReportPollerFrontEnd method performServiceScans.
/**
* Perform all scans for a given location and return the results as a {@link ScanReport}
* object. To filter by application, specify the selected applications by using the
* {@link #setSelectedApplications(Set)} method.
*/
private void performServiceScans() {
firePropertyChange(ScanReportProperties.percentageComplete.toString(), null, 0.0);
ScanReport scanReport = new ScanReport();
scanReport.setLocation(m_location);
// scanReport.addProperty("monitoring-system-id", getMonitoringSystemId());
scanReport.setTimestamp(new Date());
// Add all of the OS and connection metadata to the scan report
for (final Map.Entry<String, String> entry : getDetails().entrySet()) {
scanReport.addProperty(entry);
}
// Add all of the metadata to the scan report
for (final Map.Entry<String, String> entry : m_metadata.entrySet()) {
scanReport.addProperty(entry);
}
// Add the selected applications as scan report metadata
if (m_selectedApplications != null && m_selectedApplications.size() > 0) {
scanReport.addProperty("applications", m_selectedApplications.stream().collect(Collectors.joining(", ")));
}
// Create a log appender that will capture log output to the root logger
Log4j2StringAppender appender = Log4j2StringAppender.createAppender();
appender.start();
try {
m_pollService.setServiceMonitorLocators(m_backEnd.getServiceMonitorLocators(DistributionContext.REMOTE_MONITOR));
m_pollerConfiguration = retrieveLatestConfiguration();
appender.addToLogger(LogManager.ROOT_LOGGER_NAME, Level.DEBUG);
Set<PolledService> polledServices = getPolledServices().stream().filter(s -> matchesApplications(s, m_selectedApplications)).collect(Collectors.toSet());
PolledService[] services = polledServices.toArray(POLLED_SERVICE_ARRAY);
LOG.debug("Polling {} services.", services.length);
for (int i = 0; i < services.length; i++) {
PolledService service = services[i];
try {
final PollStatus result = doPoll(service);
if (result == null) {
LOG.warn("Null poll result for service {}", service.getServiceId());
} else {
LOG.info(new ToStringBuilder(this).append("statusName", result.getStatusName()).append("reason", result.getReason()).toString());
scanReport.addPollResult(new ScanReportPollResult(service.getSvcName(), service.getServiceId(), service.getNodeLabel(), service.getNodeId(), service.getIpAddr(), result));
}
} catch (Throwable e) {
LOG.error("Unexpected exception occurred while polling service ID {}", service.getServiceId(), e);
setState(new FatalExceptionOccurred(e));
}
firePropertyChange(ScanReportProperties.percentageComplete.toString(), null, ((double) i / (double) services.length));
}
} catch (final Throwable e) {
LOG.error("Error while performing scan", e);
} finally {
// Remove the log appender from the root logger
appender.removeFromLogger(LogManager.ROOT_LOGGER_NAME);
}
// Set the percentage complete to 100%
firePropertyChange(ScanReportProperties.percentageComplete.toString(), null, 1.0);
scanReport.setLog(new ScanReportLog(scanReport.getId(), appender.getOutput()));
LOG.debug("Returning scan report: {}", scanReport);
/*
LOG.debug("=============== Scan report log START ===============");
LOG.debug("Scan report log: '{}'", appender.getOutput());
LOG.debug("=============== Scan report log END ===============");
*/
// Fire an exitNecessary event with the scanReport as the parameter
firePropertyChange(PollerFrontEndStates.exitNecessary.toString(), null, scanReport);
}
use of org.opennms.netmgt.poller.remote.PolledService 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()]));
}
Aggregations