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