use of org.opennms.netmgt.config.poller.outages.Outages in project opennms by OpenNMS.
the class ScheduledOutagesRestServiceIT method beforeServletStart.
@Override
protected void beforeServletStart() throws Exception {
MockLogAppender.setupLogging();
File etc = new File("target/test-work-dir/etc");
etc.mkdirs();
m_onmsHome = etc.getParent();
System.setProperty("opennms.home", m_onmsHome);
ConfigurationTestUtils.setRelativeHomeDirectory(m_onmsHome);
// Setup Scheduled Outages Configuration
File outagesConfig = new File(etc, "poll-outages.xml");
FileUtils.writeStringToFile(outagesConfig, "<?xml version=\"1.0\"?>" + "<outages>" + "<outage name='my-junit-test' type='weekly'>" + "<time day='monday' begins='13:30:00' ends='13:30:01'/>" + "<interface address='match-any'/>" + "<node id='18'/><node id='40'/>" + "</outage>" + "</outages>");
m_pollOutagesConfigManager.setConfigResource(new FileSystemResource(outagesConfig));
m_pollOutagesConfigManager.afterPropertiesSet();
// Setup Filter DAO
m_filterDao = EasyMock.createMock(FilterDao.class);
EasyMock.expect(m_filterDao.getActiveIPAddressList("IPADDR != '0.0.0.0'")).andReturn(Collections.singletonList(InetAddressUtils.getLocalHostAddress())).anyTimes();
m_filterDao.flushActiveIpAddressListCache();
EasyMock.expectLastCall().anyTimes();
EasyMock.replay(m_filterDao);
FilterDaoFactory.setInstance(m_filterDao);
// Setup Collectd Configuration
File collectdConfig = new File(etc, "collectd-configuration.xml");
FileUtils.writeStringToFile(collectdConfig, "<?xml version=\"1.0\"?>" + "<collectd-configuration threads=\"50\">" + "<package name=\"example1\">" + "<filter>IPADDR != '0.0.0.0'</filter>" + "<include-range begin=\"1.1.1.1\" end=\"254.254.254.254\"/>" + "<service name=\"SNMP\" interval=\"300000\" user-defined=\"false\" status=\"on\">" + "<parameter key=\"collection\" value=\"default\"/>" + "</service>" + "</package>" + "<collector service=\"SNMP\" class-name=\"org.opennms.netmgt.collectd.SnmpCollector\"/>" + "</collectd-configuration>");
CollectdConfigFactory collectdConfigFactory = new CollectdConfigFactory(new FileInputStream(collectdConfig), "localhost", false);
// Setup Pollerd Configuration
File pollerdConfig = new File(etc, "poller-configuration.xml");
FileUtils.writeStringToFile(pollerdConfig, "<?xml version=\"1.0\"?>" + "<poller-configuration threads=\"10\" nextOutageId=\"SELECT nextval(\'outageNxtId\')\" serviceUnresponsiveEnabled=\"false\">" + "<node-outage status=\"on\" pollAllIfNoCriticalServiceDefined=\"true\"></node-outage>" + "<package name=\"example1\">" + "<filter>IPADDR != '0.0.0.0'</filter>" + "<rrd step = \"300\">" + "<rra>RRA:AVERAGE:0.5:1:2016</rra>" + "<rra>RRA:AVERAGE:0.5:12:4464</rra>" + "<rra>RRA:MIN:0.5:12:4464</rra>" + "<rra>RRA:MAX:0.5:12:4464</rra>" + "</rrd>" + "<service name=\"ICMP\" interval=\"300000\"/>" + "<downtime begin=\"0\" end=\"30000\"/>" + "</package>" + "<monitor service=\"ICMP\" class-name=\"org.opennms.netmgt.mock.MockMonitor\"/>" + "</poller-configuration>");
PollerConfigFactory.setInstance(new PollerConfigFactory(1, new FileInputStream(pollerdConfig), "localserver", false));
// Setup Threshd Configuration
File threshdConfig = new File(etc, "threshd-configuration.xml");
FileUtils.writeStringToFile(threshdConfig, "<?xml version=\"1.0\"?>" + "<threshd-configuration threads=\"5\">" + "<package name=\"example1\">" + "<filter>IPADDR != '0.0.0.0'</filter>" + "<include-range begin=\"1.1.1.1\" end=\"254.254.254.254\"/>" + "<service name=\"SNMP\" interval=\"300000\" user-defined=\"false\" status=\"on\">" + "<parameter key=\"thresholding-group\" value=\"mib2\"/>" + "</service>" + "</package>" + "</threshd-configuration>");
ThreshdConfigFactory.setInstance(new ThreshdConfigFactory(new FileInputStream(threshdConfig), "localserver", false));
// Setup Notifid Configuration
FileUtils.writeStringToFile(new File(etc, "notifd-configuration.xml"), "<?xml version=\"1.0\"?>" + "<notifd-configuration status=\"off\" match-all=\"true\">" + "<queue><queue-id>default</queue-id><interval>20s</interval>" + "<handler-class><name>org.opennms.netmgt.notifd.DefaultQueueHandler</name></handler-class>" + "</queue>" + "</notifd-configuration>");
NotifdConfigFactory.init();
m_jaxbContext = JaxbUtils.getContextFor(Outages.class);
}
use of org.opennms.netmgt.config.poller.outages.Outages in project opennms by OpenNMS.
the class ScheduledOutagesRestServiceIT method testGetOutages.
@Test
public void testGetOutages() throws Exception {
String url = "/sched-outages";
Outages outages = getXmlObject(m_jaxbContext, url, 200, Outages.class);
Assert.assertNotNull(outages);
Assert.assertEquals(1, outages.getOutages().size());
Assert.assertEquals("match-any", outages.getOutages().get(0).getInterfaces().get(0).getAddress());
}
use of org.opennms.netmgt.config.poller.outages.Outages in project opennms by OpenNMS.
the class ScheduledOutagesRestService method getOutages.
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
public Outages getOutages() {
Outages outages = new Outages();
outages.setOutages(m_pollOutagesConfigFactory.getOutages());
return outages;
}
Aggregations