Search in sources :

Example 6 with PollOutagesConfigFactory

use of org.opennms.netmgt.config.PollOutagesConfigFactory in project opennms by OpenNMS.

the class ThresholdingVisitorIT method setUp.

@Before
public void setUp() throws Exception {
    // Resets Counters Cache Data
    CollectionResourceWrapper.s_cache.clear();
    MockLogAppender.setupLogging();
    m_fileAnticipator = new FileAnticipator();
    m_hrStorageProperties = new HashMap<Integer, File>();
    m_resourceStorageDao = new FilesystemResourceStorageDao();
    m_resourceStorageDao.setRrdDirectory(new File(m_fileAnticipator.getTempDir(), "snmp"));
    m_filterDao = EasyMock.createMock(FilterDao.class);
    EasyMock.expect(m_filterDao.getActiveIPAddressList((String) EasyMock.anyObject())).andReturn(Collections.singletonList(addr("127.0.0.1"))).anyTimes();
    m_filterDao.flushActiveIpAddressListCache();
    EasyMock.expectLastCall().anyTimes();
    FilterDaoFactory.setInstance(m_filterDao);
    EasyMock.replay(m_filterDao);
    m_anticipator = new EventAnticipator();
    MockEventIpcManager eventMgr = new MockEventIpcManager();
    eventMgr.setEventAnticipator(m_anticipator);
    eventMgr.setSynchronous(true);
    EventIpcManager eventdIpcMgr = (EventIpcManager) eventMgr;
    EventIpcManagerFactory.setIpcManager(eventdIpcMgr);
    DateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
    StringBuffer sb = new StringBuffer("<?xml version=\"1.0\"?>");
    sb.append("<outages>");
    sb.append("<outage name=\"junit outage\" type=\"specific\">");
    sb.append("<time begins=\"");
    sb.append(formatter.format(new Date(System.currentTimeMillis() - 3600000)));
    sb.append("\" ends=\"");
    sb.append(formatter.format(new Date(System.currentTimeMillis() + 3600000)));
    sb.append("\"/>");
    sb.append("<interface address=\"match-any\"/>");
    sb.append("</outage>");
    sb.append("</outages>");
    File file = new File("target/poll-outages.xml");
    FileWriter writer = new FileWriter(file);
    writer.write(sb.toString());
    writer.close();
    PollOutagesConfigFactory.setInstance(new PollOutagesConfigFactory(new FileSystemResource(file)));
    PollOutagesConfigFactory.getInstance().afterPropertiesSet();
    initFactories("/threshd-configuration.xml", "/test-thresholds.xml");
    m_anticipatedEvents = new ArrayList<Event>();
}
Also used : MockEventIpcManager(org.opennms.netmgt.dao.mock.MockEventIpcManager) FileWriter(java.io.FileWriter) PollOutagesConfigFactory(org.opennms.netmgt.config.PollOutagesConfigFactory) FilesystemResourceStorageDao(org.opennms.netmgt.dao.support.FilesystemResourceStorageDao) FileSystemResource(org.springframework.core.io.FileSystemResource) Date(java.util.Date) EventAnticipator(org.opennms.netmgt.dao.mock.EventAnticipator) BigInteger(java.math.BigInteger) FilterDao(org.opennms.netmgt.filter.api.FilterDao) JdbcFilterDao(org.opennms.netmgt.filter.JdbcFilterDao) EventIpcManager(org.opennms.netmgt.events.api.EventIpcManager) MockEventIpcManager(org.opennms.netmgt.dao.mock.MockEventIpcManager) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Event(org.opennms.netmgt.xml.event.Event) FileAnticipator(org.opennms.test.FileAnticipator) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) Before(org.junit.Before)

Example 7 with PollOutagesConfigFactory

use of org.opennms.netmgt.config.PollOutagesConfigFactory in project opennms by OpenNMS.

the class CollectionSpecification method scheduledOutage.

/**
     * <p>scheduledOutage</p>
     *
     * @param agent a {@link org.opennms.netmgt.collection.api.CollectionAgent} object.
     * @return a boolean.
     */
public boolean scheduledOutage(CollectionAgent agent) {
    boolean outageFound = false;
    PollOutagesConfigFactory outageFactory = PollOutagesConfigFactory.getInstance();
    /*
         * Iterate over the outage names defined in the interface's package.
         * For each outage...if the outage contains a calendar entry which
         * applies to the current time and the outage applies to this
         * interface then break and return true. Otherwise process the
         * next outage.
         */
    for (String outageName : m_package.getOutageCalendars()) {
        // Does the outage apply to the current time?
        if (outageFactory.isCurTimeInOutage(outageName)) {
            // Does the outage apply to this interface?
            if ((outageFactory.isNodeIdInOutage(agent.getNodeId(), outageName)) || (outageFactory.isInterfaceInOutage(agent.getHostAddress(), outageName))) {
                LOG.debug("scheduledOutage: configured outage '{}' applies, interface {} will not be collected for {}", outageName, agent.getHostAddress(), this);
                outageFound = true;
                break;
            }
        }
    }
    return outageFound;
}
Also used : PollOutagesConfigFactory(org.opennms.netmgt.config.PollOutagesConfigFactory)

Example 8 with PollOutagesConfigFactory

use of org.opennms.netmgt.config.PollOutagesConfigFactory in project opennms by OpenNMS.

the class LatencyStoringServiceMonitorAdaptorIT method testThresholdsWithScheduledOutage.

// TODO: This test will fail if you have a default locale with >3 characters for month, e.g. Locale.FRENCH
@Test
@JUnitTemporaryDatabase(tempDbClass = MockDatabase.class)
public void testThresholdsWithScheduledOutage() throws Exception {
    DateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
    StringBuffer sb = new StringBuffer("<?xml version=\"1.0\"?>");
    sb.append("<outages>");
    sb.append("<outage name=\"junit outage\" type=\"specific\">");
    sb.append("<time begins=\"");
    sb.append(formatter.format(new Date(System.currentTimeMillis() - 3600000)));
    sb.append("\" ends=\"");
    sb.append(formatter.format(new Date(System.currentTimeMillis() + 3600000)));
    sb.append("\"/>");
    sb.append("<interface address=\"match-any\"/>");
    sb.append("</outage>");
    sb.append("</outages>");
    File file = new File("target/poll-outages.xml");
    FileWriter writer = new FileWriter(file);
    writer.write(sb.toString());
    writer.close();
    PollOutagesConfigFactory oldFactory = PollOutagesConfigFactory.getInstance();
    PollOutagesConfigFactory.setInstance(new PollOutagesConfigFactory(new FileSystemResource(file)));
    PollOutagesConfigFactory.getInstance().afterPropertiesSet();
    executeThresholdTest(new Double[] { 100.0 });
    m_eventIpcManager.getEventAnticipator().verifyAnticipated();
    // Reset the state of the PollOutagesConfigFactory for any subsequent tests
    PollOutagesConfigFactory.setInstance(oldFactory);
    file.delete();
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) FileWriter(java.io.FileWriter) PollOutagesConfigFactory(org.opennms.netmgt.config.PollOutagesConfigFactory) FileSystemResource(org.springframework.core.io.FileSystemResource) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) Date(java.util.Date) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Aggregations

PollOutagesConfigFactory (org.opennms.netmgt.config.PollOutagesConfigFactory)8 File (java.io.File)6 FilterDao (org.opennms.netmgt.filter.api.FilterDao)5 Before (org.junit.Before)4 FileWriter (java.io.FileWriter)3 DateFormat (java.text.DateFormat)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Date (java.util.Date)3 DefaultServiceCollectorRegistry (org.opennms.netmgt.collection.support.DefaultServiceCollectorRegistry)3 IpInterfaceDao (org.opennms.netmgt.dao.api.IpInterfaceDao)3 NodeDao (org.opennms.netmgt.dao.api.NodeDao)3 MockEventIpcManager (org.opennms.netmgt.dao.mock.MockEventIpcManager)3 MockTransactionTemplate (org.opennms.netmgt.dao.mock.MockTransactionTemplate)3 MockPersisterFactory (org.opennms.netmgt.mock.MockPersisterFactory)3 ClassPathResource (org.springframework.core.io.ClassPathResource)3 FileSystemResource (org.springframework.core.io.FileSystemResource)3 Resource (org.springframework.core.io.Resource)3 ArrayList (java.util.ArrayList)2 InsufficientInformationException (org.opennms.core.utils.InsufficientInformationException)2 CollectdConfigFactory (org.opennms.netmgt.config.CollectdConfigFactory)2