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