Search in sources :

Example 6 with Outage

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

the class PollOutagesConfigManagerTest method testPerformance.

@Test
public void testPerformance() throws Exception {
    long start = System.currentTimeMillis();
    for (int i = 1; i <= 200; i++) {
        String outageName = "o" + Integer.toString(i);
        Outage outage = m_manager.getOutage(outageName);
        assertTrue(outage != null);
        assertTrue(m_manager.isNodeIdInOutage(i, outageName));
    }
    long end = System.currentTimeMillis();
    System.out.println("Test took " + (end - start) + " ms");
}
Also used : Outage(org.opennms.netmgt.config.poller.outages.Outage) Test(org.junit.Test)

Example 7 with Outage

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

the class PollOutagesConfigManager method isTimeInOutage.

/**
 * {@inheritDoc}
 *
 * Return if time is part of specified outage.
 */
@Override
public boolean isTimeInOutage(final long time, final String outName) {
    final Outage out = getOutage(outName);
    if (out == null)
        return false;
    final Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(time);
    return isTimeInOutage(cal, out);
}
Also used : Outage(org.opennms.netmgt.config.poller.outages.Outage) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar)

Example 8 with Outage

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

the class MockPollerConfig method addScheduledOutage.

/**
 * Adds a scehduled outage to pkg from begin to end, for the nodeid
 * @param pkg - the package to which
 * @param outageName - a name, arbitrary
 * @param begin - time, in seconds since epoch, when the outage starts
 * @param end - time, in seconds since the epoch, when the outage ends
 * @param nodeid - the node the outage applies to
 */
public void addScheduledOutage(Package pkg, String outageName, long begin, long end, int nodeid) {
    Outage outage = new Outage();
    outage.setName(outageName);
    Node node = new Node();
    node.setId(nodeid);
    outage.addNode(node);
    Time time = new Time();
    Date beginDate = new Date(begin);
    Date endDate = new Date(end);
    time.setBegins(new SimpleDateFormat(BasicScheduleUtils.FORMAT1).format(beginDate));
    time.setEnds(new SimpleDateFormat(BasicScheduleUtils.FORMAT1).format(endDate));
    outage.addTime(time);
    getObject().addOutage(outage);
    pkg.addOutageCalendar(outageName);
}
Also used : Outage(org.opennms.netmgt.config.poller.outages.Outage) Node(org.opennms.netmgt.config.poller.outages.Node) Time(org.opennms.netmgt.config.poller.outages.Time) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 9 with Outage

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

the class ThresholdingSet method updateScheduledOutages.

protected void updateScheduledOutages() {
    synchronized (m_scheduledOutages) {
        m_scheduledOutages.clear();
        ThreshdConfigManager configManager = ThreshdConfigFactory.getInstance();
        for (org.opennms.netmgt.config.threshd.Package pkg : configManager.getConfiguration().getPackages()) {
            for (String outageCal : pkg.getOutageCalendars()) {
                LOG.info("updateScheduledOutages[node={}]: checking scheduled outage '{}'", m_nodeId, outageCal);
                try {
                    Outage outage = PollOutagesConfigFactory.getInstance().getOutage(outageCal);
                    if (outage == null) {
                        LOG.info("updateScheduledOutages[node={}]: scheduled outage '{}' is not defined.", m_nodeId, outageCal);
                    } else {
                        LOG.debug("updateScheduledOutages[node={}]: outage calendar '{}' found on package '{}'", m_nodeId, outage.getName(), pkg.getName());
                        m_scheduledOutages.add(outageCal);
                    }
                } catch (Exception e) {
                    LOG.info("updateScheduledOutages[node={}]: scheduled outage '{}' does not exist.", m_nodeId, outageCal);
                }
            }
        }
    }
}
Also used : Outage(org.opennms.netmgt.config.poller.outages.Outage) ThreshdConfigManager(org.opennms.netmgt.config.ThreshdConfigManager) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 10 with Outage

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

the class MockPollerConfig method addScheduledOutage.

public void addScheduledOutage(Package pkg, String outageName, long begin, long end, String ipAddr) {
    Outage outage = new Outage();
    outage.setName(outageName);
    Interface iface = new Interface();
    iface.setAddress(ipAddr);
    outage.addInterface(iface);
    Time time = new Time();
    Date beginDate = new Date(begin);
    Date endDate = new Date(end);
    time.setBegins(new SimpleDateFormat(BasicScheduleUtils.FORMAT1).format(beginDate));
    time.setEnds(new SimpleDateFormat(BasicScheduleUtils.FORMAT1).format(endDate));
    outage.addTime(time);
    getObject().addOutage(outage);
    pkg.addOutageCalendar(outageName);
}
Also used : Outage(org.opennms.netmgt.config.poller.outages.Outage) Time(org.opennms.netmgt.config.poller.outages.Time) SimpleDateFormat(java.text.SimpleDateFormat) Interface(org.opennms.netmgt.config.poller.outages.Interface) Date(java.util.Date)

Aggregations

Outage (org.opennms.netmgt.config.poller.outages.Outage)12 Test (org.junit.Test)4 Time (org.opennms.netmgt.config.poller.outages.Time)3 SimpleDateFormat (java.text.SimpleDateFormat)2 Calendar (java.util.Calendar)2 Date (java.util.Date)2 GregorianCalendar (java.util.GregorianCalendar)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Interface (org.opennms.netmgt.config.poller.outages.Interface)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 ThreshdConfigManager (org.opennms.netmgt.config.ThreshdConfigManager)1 Node (org.opennms.netmgt.config.poller.outages.Node)1