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