Search in sources :

Example 1 with Downtime

use of org.opennms.netmgt.config.poller.Downtime 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 2 with Downtime

use of org.opennms.netmgt.config.poller.Downtime 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 3 with Downtime

use of org.opennms.netmgt.config.poller.Downtime 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 4 with Downtime

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

the class PollableServiceConfig method getInterval.

/**
     * <p>getInterval</p>
     *
     * @return a long.
     */
@Override
public synchronized long getInterval() {
    if (m_service.isDeleted()) {
        LOG.debug("getInterval(): {} is deleted", m_service);
        return -1;
    }
    long when = m_configService.getInterval();
    if (m_service.getStatus().isDown()) {
        final long downFor = m_timer.getCurrentTime() - m_service.getStatusChangeTime();
        LOG.debug("getInterval(): Service {} has been down for {} seconds, checking downtime model.", m_service, TimeUnit.SECONDS.convert(downFor, TimeUnit.MILLISECONDS));
        boolean matched = false;
        for (final Downtime dt : m_pkg.getDowntimes()) {
            LOG.debug("getInterval(): Checking downtime: {}", dt);
            if (dt.getBegin() <= downFor) {
                LOG.debug("getInterval(): begin ({}) <= {}", dt.getBegin(), downFor);
                if (isTrue(dt.getDelete())) {
                    when = -1;
                    matched = true;
                } else if (dt.getEnd() != null && dt.getEnd() > downFor) {
                    // in this interval
                    when = dt.getInterval();
                    matched = true;
                } else // no end
                {
                    when = dt.getInterval();
                    matched = true;
                }
            }
        }
        LOG.debug("getInterval(): when={}, matched={}", when, matched);
        if (!matched) {
            LOG.error("Downtime model is invalid on package {}, cannot schedule service {}", m_pkg.getName(), m_service);
            return -1;
        }
    }
    if (when < 0) {
        m_service.sendDeleteEvent();
    }
    return when;
}
Also used : Downtime(org.opennms.netmgt.config.poller.Downtime)

Example 5 with Downtime

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

the class MockPollerConfig method addDowntime.

public void addDowntime(long interval, long begin, long end, boolean delete) {
    Downtime downtime = new Downtime();
    downtime.setDelete(delete ? "true" : "false");
    downtime.setBegin(begin);
    downtime.setInterval(interval);
    if (end >= 0)
        downtime.setEnd(end);
    m_currentPkg.addDowntime(downtime);
}
Also used : Downtime(org.opennms.netmgt.config.poller.Downtime)

Aggregations

Downtime (org.opennms.netmgt.config.poller.Downtime)5 Filter (org.opennms.netmgt.config.poller.Filter)3 Package (org.opennms.netmgt.config.poller.Package)3 Rrd (org.opennms.netmgt.config.poller.Rrd)3 Service (org.opennms.netmgt.config.poller.Service)3 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IncludeRange (org.opennms.netmgt.config.poller.IncludeRange)1