Search in sources :

Example 1 with Outages

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);
}
Also used : ThreshdConfigFactory(org.opennms.netmgt.config.ThreshdConfigFactory) Outages(org.opennms.netmgt.config.poller.outages.Outages) FilterDao(org.opennms.netmgt.filter.api.FilterDao) PollerConfigFactory(org.opennms.netmgt.config.PollerConfigFactory) CollectdConfigFactory(org.opennms.netmgt.config.CollectdConfigFactory) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 2 with Outages

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());
}
Also used : Outages(org.opennms.netmgt.config.poller.outages.Outages) Test(org.junit.Test)

Example 3 with Outages

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;
}
Also used : Outages(org.opennms.netmgt.config.poller.outages.Outages) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Outages (org.opennms.netmgt.config.poller.outages.Outages)3 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 Test (org.junit.Test)1 CollectdConfigFactory (org.opennms.netmgt.config.CollectdConfigFactory)1 PollerConfigFactory (org.opennms.netmgt.config.PollerConfigFactory)1 ThreshdConfigFactory (org.opennms.netmgt.config.ThreshdConfigFactory)1 FilterDao (org.opennms.netmgt.filter.api.FilterDao)1 FileSystemResource (org.springframework.core.io.FileSystemResource)1