use of org.opennms.netmgt.config.poller.Service in project opennms by OpenNMS.
the class PollerConfigFactoryIT method testIncludeUrl.
public void testIncludeUrl() throws Exception {
TestPollerConfigManager factory = new TestPollerConfigManager(POLLER_CONFIG, "localhost", false);
assertNull(factory.getPackage("TestPkg"));
Package pkg = new Package();
pkg.setName("TestPkg");
Filter filter = new Filter();
filter.setContent("IPADDR != '0.0.0.0'");
pkg.setFilter(filter);
Rrd rrd = new Rrd();
rrd.setStep(300);
rrd.addRra("RRA:AVERAGE:0.5:1:2016");
pkg.setRrd(rrd);
Service svc = new Service();
svc.setName("TestService");
svc.setInterval(300000l);
pkg.addService(svc);
Downtime dt = new Downtime();
dt.setBegin(0l);
pkg.addDowntime(dt);
File iplistFile = new File(System.getProperty("java.io.tmpdir"), "iplist.txt");
FileWriter fw = new FileWriter(iplistFile);
fw.write("#192.168.1.1");
fw.write(System.lineSeparator());
fw.write("123.12.123.121");
fw.write(System.lineSeparator());
fw.write("123.12.123.122");
fw.close();
pkg.addIncludeUrl("file:" + iplistFile.getAbsolutePath());
factory.addPackage(pkg);
factory.save();
assertNotNull(factory.getPackage("TestPkg"));
TestPollerConfigManager newFactory = new TestPollerConfigManager(factory.getXml(), "localhost", false);
Package p = newFactory.getPackage("TestPkg");
assertNotNull(p);
System.out.println(factory.getXml());
assertTrue("Expect 123.12.123.121 to be part of the package", newFactory.isInterfaceInPackage("123.12.123.121", p));
assertTrue("Expect 123.12.123.122 to be part of the package", newFactory.isInterfaceInPackage("123.12.123.122", p));
assertFalse("Expected 192.168.1.1 to be excluded from the package", newFactory.isInterfaceInPackage("192.168.1.1", p));
iplistFile.delete();
}
use of org.opennms.netmgt.config.poller.Service in project opennms by OpenNMS.
the class PollerConfigFactoryIT method testSpecific.
public void testSpecific() throws Exception {
TestPollerConfigManager factory = new TestPollerConfigManager(POLLER_CONFIG, "localhost", false);
assertNull(factory.getPackage("TestPkg"));
Package pkg = new Package();
pkg.setName("TestPkg");
Filter filter = new Filter();
filter.setContent("IPADDR != '0.0.0.0'");
pkg.setFilter(filter);
Rrd rrd = new Rrd();
rrd.setStep(300);
rrd.addRra("RRA:AVERAGE:0.5:1:2016");
pkg.setRrd(rrd);
Service svc = new Service();
svc.setName("TestService");
svc.setInterval(300000l);
pkg.addService(svc);
Downtime dt = new Downtime();
dt.setBegin(0l);
pkg.addDowntime(dt);
pkg.addSpecific("123.12.123.121");
pkg.addSpecific("123.12.123.122");
factory.addPackage(pkg);
factory.save();
assertNotNull(factory.getPackage("TestPkg"));
TestPollerConfigManager newFactory = new TestPollerConfigManager(factory.getXml(), "localhost", false);
Package p = newFactory.getPackage("TestPkg");
assertNotNull("package 'TestPkg' from new factory", p);
assertTrue("Expect 123.12.123.121 to be part of the package", newFactory.isInterfaceInPackage("123.12.123.121", p));
assertTrue("Expect 123.12.123.122 to be part of the package", newFactory.isInterfaceInPackage("123.12.123.122", p));
assertFalse("Expected 192.168.1.1 to be excluded from the package", newFactory.isInterfaceInPackage("192.168.1.1", p));
}
use of org.opennms.netmgt.config.poller.Service in project opennms by OpenNMS.
the class PollerConfigFactoryIT method testPollerConfigFactory.
public void testPollerConfigFactory() throws Exception {
TestPollerConfigManager factory = new TestPollerConfigManager(POLLER_CONFIG, "localhost", false);
assertNull(factory.getPackage("TestPkg"));
Package pkg = new Package();
pkg.setName("TestPkg");
Filter filter = new Filter();
filter.setContent("IPADDR IPLIKE *.*.*.*");
pkg.setFilter(filter);
Rrd rrd = new Rrd();
rrd.setStep(300);
rrd.addRra("RRA:AVERAGE:0.5:1:2016");
pkg.setRrd(rrd);
Service svc = new Service();
svc.setName("TestService");
svc.setInterval(300000l);
pkg.addService(svc);
Downtime dt = new Downtime();
dt.setBegin(0l);
pkg.addDowntime(dt);
IncludeRange inclde = new IncludeRange();
inclde.setBegin("192.169.0.0");
inclde.setEnd("192.169.255.255");
pkg.addIncludeRange(inclde);
factory.addPackage(pkg);
factory.save();
assertNotNull(factory.getPackage("TestPkg"));
TestPollerConfigManager newFactory = new TestPollerConfigManager(factory.getXml(), "localhost", false);
Package p = newFactory.getPackage("TestPkg");
assertNotNull("package for 'TestPkg'", p);
assertTrue("Expected 192.169.1.5 to be in the package", newFactory.isInterfaceInPackage("192.169.1.5", p));
assertFalse("Expected 192.168.1.5 to *not* be in the package", newFactory.isInterfaceInPackage("192.168.1.5", p));
}
use of org.opennms.netmgt.config.poller.Service in project opennms by OpenNMS.
the class PollerConfigManager method getServiceSelectorForPackage.
/**
* {@inheritDoc}
*/
@Override
public ServiceSelector getServiceSelectorForPackage(final Package pkg) {
try {
getReadLock().lock();
final List<String> svcNames = new LinkedList<String>();
for (Service svc : services(pkg)) {
svcNames.add(svc.getName());
}
final String filter = pkg.getFilter().getContent();
return new ServiceSelector(filter, svcNames);
} finally {
getReadLock().unlock();
}
}
use of org.opennms.netmgt.config.poller.Service in project opennms by OpenNMS.
the class PollerBackEndTest method testSaveResponseTimeDataWithLocaleThatUsesCommasForDecimals.
public void testSaveResponseTimeDataWithLocaleThatUsesCommasForDecimals() throws Exception {
Properties p = new Properties();
p.setProperty("org.opennms.netmgt.ConfigFileConstants", "ERROR");
MockLogAppender.setupLogging(p);
Locale.setDefault(Locale.FRENCH);
// Make sure we actually have a valid test
NumberFormat nf = NumberFormat.getInstance();
assertEquals("ensure that the newly set default locale (" + Locale.getDefault() + ") uses ',' as the decimal marker", "1,5", nf.format(1.5));
OnmsMonitoredService svc = new OnmsMonitoredService();
OnmsServiceType svcType = new OnmsServiceType();
svcType.setName("HTTP");
svc.setServiceType(svcType);
OnmsIpInterface intf = new OnmsIpInterface();
intf.setIpAddress(InetAddressUtils.addr("1.2.3.4"));
svc.setIpInterface(intf);
Package pkg = new Package();
Service pkgService = new Service();
pkgService.setName("HTTP");
addParameterToService(pkgService, "ds-name", "http");
addParameterToService(pkgService, "rrd-repository", "/foo");
pkg.addService(pkgService);
Rrd rrd = new Rrd();
rrd.setStep(300);
rrd.addRra("bogusRRA");
pkg.setRrd(rrd);
// TODO: Figure out why these mock calls aren't being invoked
// expect(m_rrdStrategy.createDefinition(isA(String.class), isA(String.class), isA(String.class), anyInt(), isAList(RrdDataSource.class), isAList(String.class))).andReturn(new Object());
// m_rrdStrategy.createFile(isA(Object.class));
// expect(m_rrdStrategy.openFile(isA(String.class))).andReturn(new Object());
// m_rrdStrategy.updateFile(isA(Object.class), isA(String.class), endsWith(":1.5"));
// m_rrdStrategy.closeFile(isA(Object.class));
expect(m_pollerConfig.getServiceInPackage("HTTP", pkg)).andReturn(m_httpSvcConfig);
expect(m_pollerConfig.parameters(m_httpSvcConfig)).andReturn(m_httpSvcConfig.getParameters()).atLeastOnce();
m_mocks.replayAll();
m_backEnd.saveResponseTimeData("Tuvalu", svc, 1.5, pkg);
}
Aggregations