use of org.opennms.netmgt.config.poller.Package in project opennms by OpenNMS.
the class PollablesIT method testAlternateDowntimeInterval.
@Test
public void testAlternateDowntimeInterval() {
// HERE ARE the calls to setup the downtime model
// m_pollerConfig.addDowntime(500L, 0L, 1000L, false);
// m_pollerConfig.addDowntime(500L, 1000L, -1L, true);
// m_pollerConfig.setDefaultPollInterval(2000L);
// m_pollerConfig.addService(m_mockNetwork.getService(2, "192.168.1.3", "HTTP"));
// mDot3Http/pDot3Http
final Package pkg = m_pollerConfig.getPackage("TestPkg2");
final PollableServiceConfig pollConfig = new PollableServiceConfig(pDot3Http, m_pollerConfig, m_pollerConfig, pkg, m_timer, m_persisterFactory, m_resourceStorageDao, m_locationAwarePollerClient);
m_timer.setCurrentTime(1000L);
pDot3Http.updateStatus(PollStatus.down());
assertEquals(1000, pDot3Http.getStatusChangeTime());
assertChanged(pDot3Http);
assertDown(pDot3Http);
assertEquals(500L, pollConfig.getInterval());
m_timer.setCurrentTime(1234L);
assertEquals(500L, pollConfig.getInterval());
m_timer.setCurrentTime(1500L);
assertEquals(500L, pollConfig.getInterval());
m_timer.setCurrentTime(1700L);
assertEquals(500L, pollConfig.getInterval());
m_timer.setCurrentTime(2000L);
assertEquals(-1L, pollConfig.getInterval());
LOG.debug(".3 HTTP: {}: status={}, changetime={}", pDot3Http, pDot3Http.getStatus(), pDot3Http.getStatusChangeTime());
}
use of org.opennms.netmgt.config.poller.Package in project opennms by OpenNMS.
the class PollablesIT method findPackageForService.
protected Package findPackageForService(PollerConfig pollerConfig, String ipAddr, String serviceName) {
Enumeration<Package> en = pollerConfig.enumeratePackage();
Package lastPkg = null;
while (en.hasMoreElements()) {
Package pkg = (Package) en.nextElement();
if (pollableServiceInPackage(pollerConfig, ipAddr, serviceName, pkg))
lastPkg = pkg;
}
return lastPkg;
}
use of org.opennms.netmgt.config.poller.Package in project opennms by OpenNMS.
the class Poller method findPackageForService.
Package findPackageForService(String ipAddr, String serviceName) {
Enumeration<Package> en = m_pollerConfig.enumeratePackage();
Package lastPkg = null;
while (en.hasMoreElements()) {
Package pkg = (Package) en.nextElement();
if (pollableServiceInPackage(ipAddr, serviceName, pkg))
lastPkg = pkg;
}
return lastPkg;
}
use of org.opennms.netmgt.config.poller.Package in project opennms by OpenNMS.
the class PollerConfigWithPSMIT method testPSM.
@Test
public void testPSM() throws Exception {
InputStream is = new FileInputStream(new File("src/test/resources/etc/psm-poller-configuration.xml"));
PollerConfigFactory factory = new PollerConfigFactory(0, is, "localhost", false);
PollerConfigFactory.setInstance(factory);
IOUtils.closeQuietly(is);
ServiceMonitor monitor = PollerConfigFactory.getInstance().getServiceMonitor("MQ_API_DirectRte_v2");
Assert.assertNotNull(monitor);
Package pkg = PollerConfigFactory.getInstance().getPackage("MapQuest");
Assert.assertNotNull(pkg);
Service svc = PollerConfigFactory.getInstance().getServiceInPackage("MQ_API_DirectRte_v2", pkg);
Assert.assertNotNull(svc);
Map<String, Object> parameters = new HashMap<String, Object>();
for (Parameter p : svc.getParameters()) {
parameters.put(p.getKey(), p.getValue() == null ? p.getAnyObject() : p.getValue());
}
PollStatus status = monitor.poll(new MockMonitoredService(1, "www.mapquest.com", InetAddress.getByName("www.mapquest.com"), "MQ_API_DirectRte_v2"), parameters);
Assert.assertEquals(PollStatus.SERVICE_AVAILABLE, status.getStatusCode());
}
use of org.opennms.netmgt.config.poller.Package in project opennms by OpenNMS.
the class Poller method scheduleService.
private boolean scheduleService(OnmsMonitoredService service) {
final OnmsIpInterface iface = service.getIpInterface();
final Set<OnmsOutage> outages = service.getCurrentOutages();
final OnmsOutage outage = (outages == null || outages.size() < 1 ? null : outages.iterator().next());
final OnmsEvent event = (outage == null ? null : outage.getServiceLostEvent());
final String ipAddr = InetAddressUtils.str(iface.getIpAddress());
final String serviceName = service.getServiceName();
boolean active = "A".equals(service.getStatus());
final Number svcLostEventId = event == null ? null : event.getId();
final Date ifLostService = outage == null ? null : outage.getIfLostService();
final String svcLostUei = event == null ? null : event.getEventUei();
closeOutageIfSvcLostEventIsMissing(outage);
// We don't want to adjust the management state of the service if we're
// on a machine that uses multiple servers with access to the same database
// so check the value of OpennmsServerConfigFactory.getInstance().verifyServer()
// before doing any updates.
final Package pkg = findPackageForService(ipAddr, serviceName);
final boolean verifyServer = OpennmsServerConfigFactory.getInstance().verifyServer();
if (pkg == null) {
if (active && !verifyServer) {
LOG.warn("Active service {} on {} not configured for any package. Marking as Not Polled.", serviceName, ipAddr);
updateServiceStatus(service, "N");
}
return false;
} else if (!active && !verifyServer) {
LOG.info("Active service {} on {} is now configured for a package. Marking as active.", serviceName, ipAddr);
updateServiceStatus(service, "A");
}
ServiceMonitor monitor = m_pollerConfig.getServiceMonitor(serviceName);
if (monitor == null) {
LOG.info("Could not find service monitor associated with service {}", serviceName);
return false;
}
InetAddress addr;
addr = InetAddressUtils.addr(ipAddr);
if (addr == null) {
LOG.error("Could not convert {} as an InetAddress {}", ipAddr, ipAddr);
return false;
}
PollableService svc = getNetwork().createService(service.getNodeId(), iface.getNode().getLabel(), iface.getNode().getLocation().getLocationName(), addr, serviceName);
PollableServiceConfig pollConfig = new PollableServiceConfig(svc, m_pollerConfig, m_pollOutagesConfig, pkg, getScheduler(), m_persisterFactory, m_resourceStorageDao, m_locationAwarePollerClient);
svc.setPollConfig(pollConfig);
synchronized (svc) {
if (svc.getSchedule() == null) {
Schedule schedule = new Schedule(svc, pollConfig, getScheduler());
svc.setSchedule(schedule);
}
}
if (svcLostEventId == null) {
if (svc.getParent().getStatus().isUnknown()) {
svc.updateStatus(PollStatus.up());
} else {
svc.updateStatus(svc.getParent().getStatus());
}
} else {
svc.updateStatus(PollStatus.down());
PollEvent cause = new DbPollEvent(svcLostEventId.intValue(), svcLostUei, ifLostService);
svc.setCause(cause);
}
svc.schedule();
return true;
}
Aggregations