Search in sources :

Example 6 with Package

use of org.opennms.netmgt.config.poller.Package 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();
}
Also used : Filter(org.opennms.netmgt.config.poller.Filter) Rrd(org.opennms.netmgt.config.poller.Rrd) Downtime(org.opennms.netmgt.config.poller.Downtime) FileWriter(java.io.FileWriter) Service(org.opennms.netmgt.config.poller.Service) Package(org.opennms.netmgt.config.poller.Package) File(java.io.File)

Example 7 with Package

use of org.opennms.netmgt.config.poller.Package 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));
}
Also used : Filter(org.opennms.netmgt.config.poller.Filter) Rrd(org.opennms.netmgt.config.poller.Rrd) Downtime(org.opennms.netmgt.config.poller.Downtime) Service(org.opennms.netmgt.config.poller.Service) Package(org.opennms.netmgt.config.poller.Package)

Example 8 with Package

use of org.opennms.netmgt.config.poller.Package 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));
}
Also used : IncludeRange(org.opennms.netmgt.config.poller.IncludeRange) Filter(org.opennms.netmgt.config.poller.Filter) Rrd(org.opennms.netmgt.config.poller.Rrd) Downtime(org.opennms.netmgt.config.poller.Downtime) Service(org.opennms.netmgt.config.poller.Service) Package(org.opennms.netmgt.config.poller.Package)

Example 9 with Package

use of org.opennms.netmgt.config.poller.Package in project opennms by OpenNMS.

the class PollerConfigFactoryIT method testInterfaceInPackage.

public void testInterfaceInPackage() throws Exception {
    TestPollerConfigManager factory = new TestPollerConfigManager(POLLER_CONFIG, "localhost", false);
    Package pkg = factory.getPackage("default");
    assertNotNull("Unable to find pkg default", pkg);
    assertTrue("Expected 192.168.1.1 to be in the package", factory.isInterfaceInPackage("192.168.1.1", pkg));
}
Also used : Package(org.opennms.netmgt.config.poller.Package)

Example 10 with Package

use of org.opennms.netmgt.config.poller.Package 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);
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Rrd(org.opennms.netmgt.config.poller.Rrd) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Service(org.opennms.netmgt.config.poller.Service) Package(org.opennms.netmgt.config.poller.Package) Properties(java.util.Properties) NumberFormat(java.text.NumberFormat) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Aggregations

Package (org.opennms.netmgt.config.poller.Package)31 Service (org.opennms.netmgt.config.poller.Service)11 Test (org.junit.Test)10 PollStatus (org.opennms.netmgt.poller.PollStatus)6 File (java.io.File)5 Rrd (org.opennms.netmgt.config.poller.Rrd)5 FileInputStream (java.io.FileInputStream)4 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)4 PersisterFactory (org.opennms.netmgt.collection.api.PersisterFactory)4 PollOutagesConfig (org.opennms.netmgt.config.PollOutagesConfig)4 Filter (org.opennms.netmgt.config.poller.Filter)4 ResourceStorageDao (org.opennms.netmgt.dao.api.ResourceStorageDao)4 FilesystemResourceStorageDao (org.opennms.netmgt.dao.support.FilesystemResourceStorageDao)4 MockPersisterFactory (org.opennms.netmgt.mock.MockPersisterFactory)4 Timer (org.opennms.netmgt.scheduler.Timer)4 InetAddress (java.net.InetAddress)3 Properties (java.util.Properties)3 PollerConfig (org.opennms.netmgt.config.PollerConfig)3 PollerConfigFactory (org.opennms.netmgt.config.PollerConfigFactory)3