Search in sources :

Example 6 with ThresholdingConfigFactory

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

the class ThresholdController method finishExpressionEdit.

private ModelAndView finishExpressionEdit(HttpServletRequest request) throws ServletException {
    ThresholdingConfigFactory configFactory = ThresholdingConfigFactory.getInstance();
    ModelAndView modelAndView;
    String groupName = request.getParameter("groupName");
    String submitAction = request.getParameter("submitAction");
    Group group = configFactory.getGroup(groupName);
    String expressionIndexString = request.getParameter("expressionIndex");
    if (expressionIndexString == null) {
        throw new ServletException("expressionIndex parameter required to modify or delete a threshold expression");
    }
    int expressionIndex = WebSecurityUtils.safeParseInt(expressionIndexString);
    Expression expression = group.getExpressions().get(expressionIndex);
    if (SAVE_BUTTON_TITLE.equals(submitAction)) {
        this.commonFinishEdit(request, expression);
        final String expDef = request.getParameter("expression");
        final String filterOperator = request.getParameter("filterOperator");
        if (expDef == null || expDef.equals("")) {
            throw new ServletException("expression content cannot be null or empty string");
        }
        expression.setExpression(expDef);
        expression.setFilterOperator(filterOperator == null ? null : FilterOperator.valueOf(filterOperator.toUpperCase()));
        saveChanges();
    } else if (CANCEL_BUTTON_TITLE.equals(submitAction)) {
        String isNew = request.getParameter("isNew");
        if ("true".equals(isNew)) {
            //It was a new Threshold, but the user hit cancel.  Remove the new threshold from the group
            group.removeExpression(expression);
        } else {
            List<ResourceFilter> filters = getFilterList(request, false);
            if (filters != null) {
                expression.setResourceFilters(filters);
            }
        }
    } else {
        return finishThresholdFilterEdit(request, expression);
    }
    // Remove Filters from Session
    setFilterList(request, null);
    //and got back to the editGroup page
    modelAndView = new ModelAndView("admin/thresholds/editGroup");
    modelAndView.addObject("group", configFactory.getGroup(groupName));
    return modelAndView;
}
Also used : ServletException(javax.servlet.ServletException) Group(org.opennms.netmgt.config.threshd.Group) Expression(org.opennms.netmgt.config.threshd.Expression) ModelAndView(org.springframework.web.servlet.ModelAndView) ArrayList(java.util.ArrayList) List(java.util.List) ThresholdingConfigFactory(org.opennms.netmgt.config.ThresholdingConfigFactory)

Example 7 with ThresholdingConfigFactory

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

the class ThresholdController method gotoEditExpression.

private ModelAndView gotoEditExpression(String expressionIndexString, String groupName) throws ServletException {
    ThresholdingConfigFactory configFactory = ThresholdingConfigFactory.getInstance();
    ModelAndView modelAndView;
    if (expressionIndexString == null) {
        throw new ServletException("expressionIndex parameter required to edit a threshold");
    }
    int expressionIndex = WebSecurityUtils.safeParseInt(expressionIndexString);
    Expression expression = configFactory.getGroup(groupName).getExpressions().get(expressionIndex);
    modelAndView = new ModelAndView("admin/thresholds/editExpression");
    modelAndView.addObject("expression", expression);
    modelAndView.addObject("expressionIndex", expressionIndex);
    modelAndView.addObject("groupName", groupName);
    modelAndView.addObject("isNew", false);
    addStandardEditingBits(modelAndView);
    return modelAndView;
}
Also used : ServletException(javax.servlet.ServletException) Expression(org.opennms.netmgt.config.threshd.Expression) ModelAndView(org.springframework.web.servlet.ModelAndView) ThresholdingConfigFactory(org.opennms.netmgt.config.ThresholdingConfigFactory)

Example 8 with ThresholdingConfigFactory

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

the class ThresholdController method gotoGroupList.

private ModelAndView gotoGroupList() throws ServletException {
    //Otherwise we'll be dealing with questions on the mailing lists for the rest of our lives
    try {
        ThresholdingConfigFactory.reload();
    } catch (Throwable e) {
        throw new ServletException("Could not reload ThresholdingConfigFactory because " + e.getMessage(), e);
    }
    ThresholdingConfigFactory configFactory = ThresholdingConfigFactory.getInstance();
    ModelAndView modelAndView = new ModelAndView("admin/thresholds/list");
    Map<String, Group> groupMap = new TreeMap<String, Group>();
    for (String aName : configFactory.getGroupNames()) {
        groupMap.put(aName, configFactory.getGroup(aName));
    }
    modelAndView.addObject("groupMap", groupMap);
    return modelAndView;
}
Also used : ServletException(javax.servlet.ServletException) Group(org.opennms.netmgt.config.threshd.Group) ModelAndView(org.springframework.web.servlet.ModelAndView) TreeMap(java.util.TreeMap) ThresholdingConfigFactory(org.opennms.netmgt.config.ThresholdingConfigFactory)

Example 9 with ThresholdingConfigFactory

use of org.opennms.netmgt.config.ThresholdingConfigFactory 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 10 with ThresholdingConfigFactory

use of org.opennms.netmgt.config.ThresholdingConfigFactory 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

ThresholdingConfigFactory (org.opennms.netmgt.config.ThresholdingConfigFactory)15 ModelAndView (org.springframework.web.servlet.ModelAndView)10 ServletException (javax.servlet.ServletException)8 Group (org.opennms.netmgt.config.threshd.Group)7 ArrayList (java.util.ArrayList)3 Expression (org.opennms.netmgt.config.threshd.Expression)3 Threshold (org.opennms.netmgt.config.threshd.Threshold)3 File (java.io.File)2 List (java.util.List)2 Before (org.junit.Before)2 DefaultServiceCollectorRegistry (org.opennms.netmgt.collection.support.DefaultServiceCollectorRegistry)2 PollOutagesConfigFactory (org.opennms.netmgt.config.PollOutagesConfigFactory)2 ThreshdConfigFactory (org.opennms.netmgt.config.ThreshdConfigFactory)2 IpInterfaceDao (org.opennms.netmgt.dao.api.IpInterfaceDao)2 NodeDao (org.opennms.netmgt.dao.api.NodeDao)2 MockTransactionTemplate (org.opennms.netmgt.dao.mock.MockTransactionTemplate)2 FilterDao (org.opennms.netmgt.filter.api.FilterDao)2 MockPersisterFactory (org.opennms.netmgt.mock.MockPersisterFactory)2 ClassPathResource (org.springframework.core.io.ClassPathResource)2 Resource (org.springframework.core.io.Resource)2