Search in sources :

Example 1 with PollOutagesConfigFactory

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

the class ThresholdingSet method isNodeInOutage.

public final boolean isNodeInOutage() {
    PollOutagesConfigFactory outageFactory = PollOutagesConfigFactory.getInstance();
    boolean outageFound = false;
    synchronized (m_scheduledOutages) {
        for (String outageName : m_scheduledOutages) {
            if (outageFactory.isCurTimeInOutage(outageName)) {
                LOG.debug("isNodeInOutage[node={}]: current time is on outage using '{}'; checking the node with IP {}", m_nodeId, outageName, m_hostAddress);
                if (outageFactory.isNodeIdInOutage(m_nodeId, outageName) || outageFactory.isInterfaceInOutage(m_hostAddress, outageName)) {
                    LOG.debug("isNodeInOutage[node={}]: configured outage '{}' applies, interface {} will be ignored for threshold processing", m_nodeId, outageName, m_hostAddress);
                    outageFound = true;
                    break;
                }
            }
        }
    }
    return outageFound;
}
Also used : PollOutagesConfigFactory(org.opennms.netmgt.config.PollOutagesConfigFactory)

Example 2 with PollOutagesConfigFactory

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

the class LatencyThresholdingSetIT method setUp.

@Before
public void setUp() throws Exception {
    BeanUtils.setStaticApplicationContext(m_context);
    // Resets Counters Cache Data
    CollectionResourceWrapper.s_cache.clear();
    MockLogAppender.setupLogging();
    m_fileAnticipator = new FileAnticipator();
    m_resourceStorageDao = new FilesystemResourceStorageDao();
    m_resourceStorageDao.setRrdDirectory(m_fileAnticipator.getTempDir());
    // Use a mock FilterDao that always returns 127.0.0.1 in the active IP list
    FilterDao filterDao = EasyMock.createMock(FilterDao.class);
    EasyMock.expect(filterDao.getActiveIPAddressList((String) EasyMock.anyObject())).andReturn(Collections.singletonList(addr("127.0.0.1"))).anyTimes();
    filterDao.flushActiveIpAddressListCache();
    EasyMock.expectLastCall().anyTimes();
    FilterDaoFactory.setInstance(filterDao);
    EasyMock.replay(filterDao);
    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 : 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) FilterDao(org.opennms.netmgt.filter.api.FilterDao) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Event(org.opennms.netmgt.xml.event.Event) FileAnticipator(org.opennms.test.FileAnticipator) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) Before(org.junit.Before)

Example 3 with PollOutagesConfigFactory

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

the class CollectdIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    m_eventIpcManager = new MockEventIpcManager();
    EventIpcManagerFactory.setIpcManager(m_eventIpcManager);
    m_mockUtils = new EasyMockUtils();
    m_filterDao = m_mockUtils.createMock(FilterDao.class);
    FilterDaoFactory.setInstance(m_filterDao);
    // This call will also ensure that the poll-outages.xml file can parse IPv4
    // and IPv6 addresses.
    Resource resource = new ClassPathResource("etc/poll-outages.xml");
    PollOutagesConfigFactory factory = new PollOutagesConfigFactory(resource);
    factory.afterPropertiesSet();
    PollOutagesConfigFactory.setInstance(factory);
    File homeDir = resource.getFile().getParentFile().getParentFile();
    System.setProperty("opennms.home", homeDir.getAbsolutePath());
    resource = new ClassPathResource("/test-thresholds.xml");
    ThresholdingConfigFactory.setInstance(new ThresholdingConfigFactory(resource.getInputStream()));
    // set up test using a string key
    m_key = m_testName.getMethodName() + System.nanoTime();
    m_tests.put(m_key, this);
    //create a collector definition
    Collector collector = new Collector();
    collector.setService("SNMP");
    collector.setClassName(MockServiceCollector.class.getName());
    // pass the key to the collector definition so it can look up the associated test
    Parameter param = new Parameter();
    param.setKey(TEST_KEY_PARM_NAME);
    param.setValue(m_key);
    collector.addParameter(param);
    m_collectdConfigFactory = m_mockUtils.createMock(CollectdConfigFactory.class);
    m_collectdConfiguration = m_mockUtils.createMock(CollectdConfiguration.class);
    EasyMock.expect(m_collectdConfigFactory.getCollectdConfig()).andReturn(m_collectdConfiguration).anyTimes();
    EasyMock.expect(m_collectdConfiguration.getCollectors()).andReturn(Collections.singletonList(collector)).anyTimes();
    EasyMock.expect(m_collectdConfiguration.getThreads()).andReturn(1).anyTimes();
    m_ifaceDao = m_mockUtils.createMock(IpInterfaceDao.class);
    m_nodeDao = m_mockUtils.createMock(NodeDao.class);
    m_collectd = new Collectd() {

        @Override
        protected void handleInsufficientInfo(InsufficientInformationException e) {
            fail("Invalid event received: " + e.getMessage());
        }
    };
    OnmsServiceType snmp = new OnmsServiceType("SNMP");
    NetworkBuilder netBuilder = new NetworkBuilder();
    NodeBuilder nodeBuilder = netBuilder.addNode("node1").setId(1);
    InterfaceBuilder ifaceBlder = netBuilder.addInterface("192.168.1.1").setId(2).setIsSnmpPrimary("P");
    ifaceBlder.addSnmpInterface(1);
    OnmsMonitoredService svc = netBuilder.addService(snmp);
    List<OnmsIpInterface> initialIfs = Collections.emptyList();
    EasyMock.expect(m_ifaceDao.findByServiceType(snmp.getName())).andReturn(initialIfs).anyTimes();
    m_filterDao.flushActiveIpAddressListCache();
    EasyMock.expect(m_nodeDao.load(1)).andReturn(nodeBuilder.getNode()).anyTimes();
    createGetPackagesExpectation(svc);
    EasyMock.expect(m_ifaceDao.load(2)).andReturn(ifaceBlder.getInterface()).anyTimes();
    m_mockUtils.replayAll();
    final MockTransactionTemplate transTemplate = new MockTransactionTemplate();
    transTemplate.afterPropertiesSet();
    m_collectd.setCollectdConfigFactory(m_collectdConfigFactory);
    m_collectd.setEventIpcManager(m_eventIpcManager);
    m_collectd.setTransactionTemplate(transTemplate);
    m_collectd.setIpInterfaceDao(m_ifaceDao);
    m_collectd.setNodeDao(m_nodeDao);
    m_collectd.setFilterDao(m_filterDao);
    m_collectd.setPersisterFactory(new MockPersisterFactory());
    m_collectd.setServiceCollectorRegistry(new DefaultServiceCollectorRegistry());
    m_collectd.setLocationAwareCollectorClient(CollectorTestUtils.createLocationAwareCollectorClient());
    // Inits the class
    m_collectd.afterPropertiesSet();
//assertNotNull(m_serviceCollector);
}
Also used : DefaultServiceCollectorRegistry(org.opennms.netmgt.collection.support.DefaultServiceCollectorRegistry) MockEventIpcManager(org.opennms.netmgt.dao.mock.MockEventIpcManager) InsufficientInformationException(org.opennms.core.utils.InsufficientInformationException) EasyMockUtils(org.opennms.test.mock.EasyMockUtils) NodeBuilder(org.opennms.netmgt.model.NetworkBuilder.NodeBuilder) NodeDao(org.opennms.netmgt.dao.api.NodeDao) CollectdConfiguration(org.opennms.netmgt.config.collectd.CollectdConfiguration) NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) Collector(org.opennms.netmgt.config.collectd.Collector) MockPersisterFactory(org.opennms.netmgt.mock.MockPersisterFactory) PollOutagesConfigFactory(org.opennms.netmgt.config.PollOutagesConfigFactory) Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource) CollectdConfigFactory(org.opennms.netmgt.config.CollectdConfigFactory) InterfaceBuilder(org.opennms.netmgt.model.NetworkBuilder.InterfaceBuilder) MockTransactionTemplate(org.opennms.netmgt.dao.mock.MockTransactionTemplate) ClassPathResource(org.springframework.core.io.ClassPathResource) IpInterfaceDao(org.opennms.netmgt.dao.api.IpInterfaceDao) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) FilterDao(org.opennms.netmgt.filter.api.FilterDao) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) Parameter(org.opennms.netmgt.config.collectd.Parameter) File(java.io.File) ThresholdingConfigFactory(org.opennms.netmgt.config.ThresholdingConfigFactory) Before(org.junit.Before)

Example 4 with PollOutagesConfigFactory

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

the class DuplicatePrimaryAddressIT method initialize.

/**
     * Initialize.
     *
     * @param scheduleExistingNodes true, to emulate having data on the database
     * @throws Exception the exception
     */
private void initialize(boolean scheduleExistingNodes) throws Exception {
    MockLogAppender.setupLogging();
    m_eventIpcManager = new MockEventIpcManager();
    EventIpcManagerFactory.setIpcManager(m_eventIpcManager);
    m_mockUtils = new EasyMockUtils();
    m_filterDao = m_mockUtils.createMock(FilterDao.class);
    FilterDaoFactory.setInstance(m_filterDao);
    Resource resource = new ClassPathResource("etc/poll-outages.xml");
    PollOutagesConfigFactory factory = new PollOutagesConfigFactory(resource);
    factory.afterPropertiesSet();
    PollOutagesConfigFactory.setInstance(factory);
    File homeDir = resource.getFile().getParentFile().getParentFile();
    System.setProperty("opennms.home", homeDir.getAbsolutePath());
    Collector collector = new Collector();
    collector.setService("SNMP");
    collector.setClassName(MockServiceCollector.class.getName());
    m_collectdConfigFactory = m_mockUtils.createMock(CollectdConfigFactory.class);
    m_collectdConfiguration = m_mockUtils.createMock(CollectdConfiguration.class);
    EasyMock.expect(m_collectdConfigFactory.getCollectdConfig()).andReturn(m_collectdConfiguration).anyTimes();
    EasyMock.expect(m_collectdConfiguration.getCollectors()).andReturn(Collections.singletonList(collector)).anyTimes();
    EasyMock.expect(m_collectdConfiguration.getThreads()).andReturn(2).anyTimes();
    m_ifaceDao = m_mockUtils.createMock(IpInterfaceDao.class);
    m_nodeDao = m_mockUtils.createMock(NodeDao.class);
    m_collectd = new Collectd() {

        @Override
        protected void handleInsufficientInfo(InsufficientInformationException e) {
            Assert.fail("Invalid event received: " + e.getMessage());
        }
    };
    OnmsServiceType snmp = new OnmsServiceType("SNMP");
    NetworkBuilder netBuilder = new NetworkBuilder();
    OnmsNode n1 = netBuilder.addNode("node1").setId(1).setForeignSource("TestA").setForeignId("node1").getNode();
    OnmsIpInterface ip1 = netBuilder.addSnmpInterface(1).addIpInterface("192.168.1.1").setId(2).setIsSnmpPrimary("P").getInterface();
    netBuilder.addService(snmp);
    OnmsNode n2 = netBuilder.addNode("node2").setId(3).setForeignSource("TestB").setForeignId("node2").getNode();
    OnmsIpInterface ip2 = netBuilder.addSnmpInterface(1).addIpInterface("192.168.1.1").setId(4).setIsSnmpPrimary("P").getInterface();
    netBuilder.addService(snmp);
    Assert.assertNotSame(ip1.getNode().getId(), ip2.getNode().getId());
    List<OnmsIpInterface> initialIfs = new ArrayList<OnmsIpInterface>();
    if (scheduleExistingNodes) {
        initialIfs.add(ip1);
        initialIfs.add(ip2);
    }
    EasyMock.expect(m_ifaceDao.findByServiceType(snmp.getName())).andReturn(initialIfs).anyTimes();
    m_filterDao.flushActiveIpAddressListCache();
    EasyMock.expectLastCall().anyTimes();
    EasyMock.expect(m_nodeDao.load(1)).andReturn(n1).anyTimes();
    EasyMock.expect(m_nodeDao.load(3)).andReturn(n2).anyTimes();
    createGetPackagesExpectation();
    EasyMock.expect(m_ifaceDao.load(2)).andReturn(ip1).anyTimes();
    EasyMock.expect(m_ifaceDao.load(4)).andReturn(ip2).anyTimes();
    m_mockUtils.replayAll();
    final MockTransactionTemplate transTemplate = new MockTransactionTemplate();
    transTemplate.afterPropertiesSet();
    m_collectd.setCollectdConfigFactory(m_collectdConfigFactory);
    m_collectd.setEventIpcManager(m_eventIpcManager);
    m_collectd.setTransactionTemplate(transTemplate);
    m_collectd.setIpInterfaceDao(m_ifaceDao);
    m_collectd.setNodeDao(m_nodeDao);
    m_collectd.setFilterDao(m_filterDao);
    m_collectd.setPersisterFactory(new MockPersisterFactory());
    m_collectd.setServiceCollectorRegistry(new DefaultServiceCollectorRegistry());
    m_collectd.setLocationAwareCollectorClient(CollectorTestUtils.createLocationAwareCollectorClient());
    m_collectd.afterPropertiesSet();
    m_collectd.start();
}
Also used : DefaultServiceCollectorRegistry(org.opennms.netmgt.collection.support.DefaultServiceCollectorRegistry) MockEventIpcManager(org.opennms.netmgt.dao.mock.MockEventIpcManager) InsufficientInformationException(org.opennms.core.utils.InsufficientInformationException) ArrayList(java.util.ArrayList) EasyMockUtils(org.opennms.test.mock.EasyMockUtils) NodeDao(org.opennms.netmgt.dao.api.NodeDao) CollectdConfiguration(org.opennms.netmgt.config.collectd.CollectdConfiguration) NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) Collector(org.opennms.netmgt.config.collectd.Collector) MockPersisterFactory(org.opennms.netmgt.mock.MockPersisterFactory) OnmsNode(org.opennms.netmgt.model.OnmsNode) PollOutagesConfigFactory(org.opennms.netmgt.config.PollOutagesConfigFactory) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) CollectdConfigFactory(org.opennms.netmgt.config.CollectdConfigFactory) MockTransactionTemplate(org.opennms.netmgt.dao.mock.MockTransactionTemplate) ClassPathResource(org.springframework.core.io.ClassPathResource) IpInterfaceDao(org.opennms.netmgt.dao.api.IpInterfaceDao) FilterDao(org.opennms.netmgt.filter.api.FilterDao) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) File(java.io.File)

Example 5 with PollOutagesConfigFactory

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

the class CollectdTest method setUp.

@Before
public void setUp() throws Exception {
    EventIpcManager m_eventIpcManager;
    NodeDao m_nodeDao;
    MockLogAppender.setupLogging();
    Resource threshdResource = new ClassPathResource("/etc/thresholds.xml");
    File homeDir = threshdResource.getFile().getParentFile().getParentFile();
    System.setProperty("opennms.home", homeDir.getAbsolutePath());
    // Test setup
    m_eventIpcManager = m_easyMockUtils.createMock(EventIpcManager.class);
    EventIpcManagerFactory.setIpcManager(m_eventIpcManager);
    m_nodeDao = m_easyMockUtils.createMock(NodeDao.class);
    m_ipIfDao = m_easyMockUtils.createMock(IpInterfaceDao.class);
    m_scheduler = new MockScheduler();
    m_eventIpcManager.addEventListener(isA(EventListener.class));
    expectLastCall().anyTimes();
    m_eventIpcManager.addEventListener(isA(EventListener.class), isACollection(String.class));
    expectLastCall().anyTimes();
    m_eventIpcManager.addEventListener(isA(EventListener.class), isA(String.class));
    expectLastCall().anyTimes();
    m_eventIpcManager.removeEventListener(isA(EventListener.class));
    expectLastCall().anyTimes();
    // Mock the FilterDao without using EasyMockUtils so that it can be verified separately
    m_filterDao = EasyMock.createMock(FilterDao.class);
    List<InetAddress> allIps = new ArrayList<InetAddress>();
    allIps.add(addr("192.168.1.1"));
    allIps.add(addr("192.168.1.2"));
    allIps.add(addr("192.168.1.3"));
    allIps.add(addr("192.168.1.4"));
    allIps.add(addr("192.168.1.5"));
    expect(m_filterDao.getActiveIPAddressList("IPADDR IPLIKE *.*.*.*")).andReturn(allIps).anyTimes();
    expect(m_filterDao.getActiveIPAddressList("IPADDR IPLIKE 1.1.1.1")).andReturn(new ArrayList<InetAddress>(0)).anyTimes();
    EasyMock.replay(m_filterDao);
    FilterDaoFactory.setInstance(m_filterDao);
    // This call will also ensure that the poll-outages.xml file can parse IPv4
    // and IPv6 addresses.
    Resource resource = new ClassPathResource("etc/poll-outages.xml");
    PollOutagesConfigFactory factory = new PollOutagesConfigFactory(resource);
    factory.afterPropertiesSet();
    PollOutagesConfigFactory.setInstance(factory);
    final MockTransactionTemplate transTemplate = new MockTransactionTemplate();
    transTemplate.afterPropertiesSet();
    m_collectd = new Collectd();
    m_collectd.setEventIpcManager(m_eventIpcManager);
    m_collectd.setNodeDao(m_nodeDao);
    m_collectd.setIpInterfaceDao(m_ipIfDao);
    m_collectd.setFilterDao(m_filterDao);
    m_collectd.setScheduler(m_scheduler);
    m_collectd.setTransactionTemplate(transTemplate);
    m_collectd.setPersisterFactory(new MockPersisterFactory());
    m_collectd.setServiceCollectorRegistry(new DefaultServiceCollectorRegistry());
    m_collectd.setLocationAwareCollectorClient(CollectorTestUtils.createLocationAwareCollectorClient());
    ThresholdingConfigFactory.setInstance(new ThresholdingConfigFactory(ConfigurationTestUtils.getInputStreamForConfigFile("thresholds.xml")));
}
Also used : MockScheduler(org.opennms.netmgt.poller.mock.MockScheduler) DefaultServiceCollectorRegistry(org.opennms.netmgt.collection.support.DefaultServiceCollectorRegistry) PollOutagesConfigFactory(org.opennms.netmgt.config.PollOutagesConfigFactory) Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource) ArrayList(java.util.ArrayList) MockTransactionTemplate(org.opennms.netmgt.dao.mock.MockTransactionTemplate) ClassPathResource(org.springframework.core.io.ClassPathResource) IpInterfaceDao(org.opennms.netmgt.dao.api.IpInterfaceDao) NodeDao(org.opennms.netmgt.dao.api.NodeDao) FilterDao(org.opennms.netmgt.filter.api.FilterDao) EventIpcManager(org.opennms.netmgt.events.api.EventIpcManager) EventListener(org.opennms.netmgt.events.api.EventListener) MockPersisterFactory(org.opennms.netmgt.mock.MockPersisterFactory) File(java.io.File) InetAddress(java.net.InetAddress) ThresholdingConfigFactory(org.opennms.netmgt.config.ThresholdingConfigFactory) Before(org.junit.Before)

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