/** * <p>getPackage</p> * * @param name a {@link java.lang.String} object. * @return a {@link org.opennms.netmgt.config.collectd.Package} object. */ public Package getPackage(final String name) { synchronized (m_collectdConfigMutex) { for (Package pkg : m_collectdConfig.getPackages()) { if (pkg.getName().equals(name)) { return pkg; } } return null; } }
/** * For performance reasons, we only enable the {@link DomainResourceType} if * one or more packages use it. Here we iterator over all of defined packages, * return true if a package uses the domain types, and false otherwise. */ private boolean isDomainResourceTypeUsed() { for (Package pkg : m_collectdConfig.getCollectdConfig().getPackages()) { if ("true".equalsIgnoreCase(pkg.getStoreByIfAlias())) { return true; } } return false; } }
/** * Gets the service object. * * @param config the Collectd's configuration * @param service the service's name * @return the service object */ private Service getServiceObject(CollectdConfiguration config, String service) { for (Package pkg : config.getPackages()) { for (Service svc : pkg.getServices()) { if (svc.getName().equals(service)) { return svc; } } } return null; }
/** * Returns true if collection domain exists * * @param name * The domain name to check * @return True if the domain exists */ public boolean domainExists(final String name) { synchronized (m_collectdConfigMutex) { for (Package pkg : m_collectdConfig.getPackages()) { if ((pkg.getIfAliasDomain() != null) && pkg.getIfAliasDomain().equals(name)) { return true; } } return false; } }
public Filter getFilter(final String filterName) { final List<Filter> filters = new ArrayList<>(); for (final Package p : getPackages()) { final Filter filter = p.getFilter(); if (filterName.equals(filter.getName())) { filters.add(filter); } else if (filterName.equals(p.getName())) { filter.setName(p.getName()); filters.add(filter); } } if (filters.size() > 1) { throw new IllegalArgumentException("Filter name " + filterName + " matched more than one filter in collectd-configuration.xml!"); } else if (filters.size() == 1) { return filters.get(0); } else { return null; } }
/** * Returns true if the specified interface is included by at least one * package which has the specified service and that service is enabled (set * to "on"). * * @param iface * {@link OnmsIpInterface} to lookup * @param svcName * The service name to lookup * @return true if Collectd config contains a package which includes the * specified interface and has the specified service enabled. */ public boolean isServiceCollectionEnabled(final OnmsIpInterface iface, final String svcName) { for (Package wpkg : m_collectdConfig.getPackages()) { // Does the package include the interface? if (interfaceInPackage(iface, wpkg)) { // Yes, now see if package includes // the service and service is enabled // if (wpkg.serviceInPackageAndEnabled(svcName)) { // Thats all we need to know... return true; } } } return false; }
for (Package wpkg : m_collectdConfig.getPackages()) {
for(Package wpkg : collectdConfig.getPackages()) {
/** * Creates the get packages expectation. */ private void createGetPackagesExpectation() { final Package pkg = new Package(); pkg.setName("testPackage"); Filter filter = new Filter(); filter.setContent("ipaddr != '0.0.0.0'"); pkg.setFilter(filter); final Service collector = new Service(); collector.setName("SNMP"); collector.setStatus("on"); collector.setInterval(1000l); collector.addParameter("thresholding-enabled", "false"); pkg.addService(collector); EasyMock.expect(m_collectdConfiguration.getPackages()).andReturn(Collections.singletonList(pkg)).anyTimes(); EasyMock.expect(m_collectdConfigFactory.interfaceInPackage(anyObject(OnmsIpInterface.class), eq(pkg))).andReturn(true).anyTimes(); }
private void createGetPackagesExpectation(OnmsMonitoredService svc) { String rule = "ipaddr = '"+ str(svc.getIpAddress())+"'"; //EasyMock.expect(m_filterDao.getActiveIPAddressList(rule)).andReturn(Collections.singletonList(svc.getIpAddress())); final Package pkg = new Package(); pkg.setName("testPackage"); Filter filter = new Filter(); filter.setContent(rule); pkg.setFilter(filter); final Service collector = new Service(); collector.setName("SNMP"); collector.setStatus("on"); collector.setInterval(3000l); Parameter parm = new Parameter(); parm.setKey(TEST_KEY_PARM_NAME); parm.setValue(m_key); collector.setParameters(Collections.singletonList(parm)); pkg.addService(collector); EasyMock.expect(m_collectdConfiguration.getPackages()).andReturn(Collections.singletonList(pkg)); EasyMock.expect(m_collectdConfigFactory.interfaceInPackage(anyObject(OnmsIpInterface.class), eq(pkg))).andReturn(true); }
@Test public void testOneMatchingSpec() throws Exception { OnmsIpInterface iface = getInterface(); setupCollector("SNMP"); setupInterface(iface); setupTransactionManager(); expect(m_collectdConfig.getPackages()).andReturn(Collections.singletonList(getCollectionPackageThatMatchesSNMP())); expect(m_collectdConfigFactory.interfaceInPackage(iface, getCollectionPackageThatMatchesSNMP())).andReturn(true); m_easyMockUtils.replayAll(); assertEquals("scheduler entry count", 0, m_scheduler.getEntryCount()); m_collectd.afterPropertiesSet(); m_collectd.start(); m_scheduler.next(); assertEquals("scheduler entry count", 1, m_scheduler.getEntryCount()); m_scheduler.next(); m_collectd.stop(); m_easyMockUtils.verifyAll(); }
/** * NMS-9413: Verifies that collectd does not schedule interfaces when the * {@link ServiceCollector} throws a {@link CollectionInitializationException} * while validating the agent. */ @SuppressWarnings("unchecked") @Test public void testInterfaceIsNotScheduledWhenValidationFails() throws Exception { ServiceCollector svcCollector = m_easyMockUtils.createMock(ServiceCollector.class); svcCollector.initialize(); svcCollector.validateAgent(isA(CollectionAgent.class), isA(Map.class)); expectLastCall().andThrow(new CollectionInitializationException("No!")).once(); setupCollector("SNMP", svcCollector); OnmsIpInterface iface = getInterface(); setupInterface(iface); setupTransactionManager(); expect(m_collectdConfig.getPackages()).andReturn(Collections.singletonList(getCollectionPackageThatMatchesSNMP())); expect(m_collectdConfigFactory.interfaceInPackage(iface, getCollectionPackageThatMatchesSNMP())).andReturn(true); m_easyMockUtils.replayAll(); assertEquals("scheduler entry count", 0, m_scheduler.getEntryCount()); m_collectd.afterPropertiesSet(); m_collectd.start(); m_scheduler.next(); assertEquals("scheduler entry count", 0, m_scheduler.getEntryCount()); m_collectd.stop(); m_easyMockUtils.verifyAll(); }