Search in sources :

Example 6 with Service

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

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));
}
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 Service

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));
}
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 Service

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();
    }
}
Also used : ServiceSelector(org.opennms.netmgt.model.ServiceSelector) CriticalService(org.opennms.netmgt.config.poller.CriticalService) Service(org.opennms.netmgt.config.poller.Service) LinkedList(java.util.LinkedList)

Example 10 with Service

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);
}
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

Service (org.opennms.netmgt.config.poller.Service)22 Package (org.opennms.netmgt.config.poller.Package)11 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)6 Test (org.junit.Test)5 PollerConfig (org.opennms.netmgt.config.PollerConfig)5 Parameter (org.opennms.netmgt.config.poller.Parameter)5 PollStatus (org.opennms.netmgt.poller.PollStatus)5 File (java.io.File)4 Rrd (org.opennms.netmgt.config.poller.Rrd)4 Downtime (org.opennms.netmgt.config.poller.Downtime)3 Filter (org.opennms.netmgt.config.poller.Filter)3 OnmsNode (org.opennms.netmgt.model.OnmsNode)3 MonitoredService (org.opennms.netmgt.poller.MonitoredService)3 ServiceMonitor (org.opennms.netmgt.poller.ServiceMonitor)3 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 InetAddress (java.net.InetAddress)2 HashMap (java.util.HashMap)2 List (java.util.List)2 CompletableFuture (java.util.concurrent.CompletableFuture)2