/** * Gets the value of a service property. * * @param svc the service's name * @param propertyName the property name * @return the service property value */ private String getSvcPropertyValue(Service svc, String propertyName) { if (svc.getParameters() == null) { return null; } for (org.opennms.netmgt.config.collectd.Parameter p : svc.getParameters()) { if (p.getKey().equals(propertyName)) { return p.getValue(); } } return null; }
/** * Returns true if the service is part of the package and the status of the * service is set to "on". Returns false if the service is not in the * package or it is but the status of the service is set to "off". * * @param svcName * The service name to lookup. * @return a boolean. */ public boolean serviceInPackageAndEnabled(final String svcName) { for (final Service service : getServices()) { if (service.getName().equalsIgnoreCase(svcName)) { // OK it's in the package. Now check the status of the service. if ("on".equals(service.getStatus())) return true; } } return false; }
/** * <p>getInterval</p> * * @return a long. */ public long getInterval() { return getService().getInterval(); }
Service service = new Service(); service.setName(getServiceName()); service.setInterval(300000L); service.setUserDefined(Boolean.TRUE.toString()); service.setStatus("on"); service.addParameter(createParameter("url", getServiceConfig().getConnection())); service.addParameter(createParameter("retry", "2")); service.addParameter(createParameter("timeout", "3000")); service.addParameter(createParameter("rrd-base-name", "java")); service.addParameter(createParameter("ds-name", getServiceName())); service.addParameter(createParameter("friendly-name", getServiceName())); service.addParameter(createParameter("collection", getServiceName())); service.addParameter(createParameter("thresholding-enabled", Boolean.TRUE.toString())); service.addParameter(createParameter("factory", "PASSWORD-CLEAR")); service.addParameter(createParameter("username", getServiceConfig().getUser())); service.addParameter(createParameter("password", getServiceConfig().getPassword()));
public static CollectionSpecification createCollectionSpec(String svcName, ServiceCollector svcCollector, String collectionName) { Package pkg = new Package(); Filter filter = new Filter(); filter.setContent("IPADDR IPLIKE *.*.*.*"); pkg.setFilter(filter); Service service = new Service(); service.setName(svcName); Parameter collectionParm = new Parameter(); collectionParm.setKey("collection"); collectionParm.setValue(collectionName); service.addParameter(collectionParm); pkg.addService(service); CollectionSpecification spec = new CollectionSpecification(pkg, svcName, svcCollector, new DefaultCollectdInstrumentation(), createLocationAwareCollectorClient()); return spec; }
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); }
filter.setContent("IPADDR != '0.0.0.0'"); pkg.setFilter(filter); Service service = new Service(); service.setName("SNMP"); pkg.addService(service); Map<String, Object> map = new TreeMap<String, Object>(); List<org.opennms.netmgt.config.collectd.Parameter> params = pkg.getService("SNMP").getParameters(); for (org.opennms.netmgt.config.collectd.Parameter p : params) { map.put(p.getKey(), p.getValue());
private void initializeParameters() { final Map<String, Object> m = new TreeMap<String, Object>(); m.put(ParameterName.SERVICE.toString(), m_svcName); m.put(ParameterName.SERVICE_INTERVAL.toString(), getService().getInterval().toString()); StringBuilder sb; Collection<Parameter> params = getService().getParameters(); for (Parameter p : params) { if (LOG.isDebugEnabled()) {
public Service getService(final String svcName) { final List<Service> pkgSvcs = getServices(); for (final Service svc : pkgSvcs) { if (svc.getName().equalsIgnoreCase(svcName)) return svc; } throw new IllegalArgumentException("Service name not part of package!"); }
Service service = new Service(); service.setName(getServiceName()); service.setInterval(300000L); service.setUserDefined(Boolean.TRUE.toString()); service.setStatus("on"); service.addParameter(createParameter("url", getServiceConfig().getConnection())); service.addParameter(createParameter("retry", "2")); service.addParameter(createParameter("timeout", "3000")); service.addParameter(createParameter("rrd-base-name", "java")); service.addParameter(createParameter("ds-name", getServiceName())); service.addParameter(createParameter("friendly-name", getServiceName())); service.addParameter(createParameter("collection", getServiceName())); service.addParameter(createParameter("thresholding-enabled", Boolean.TRUE.toString())); service.addParameter(createParameter("factory", "PASSWORD-CLEAR")); service.addParameter(createParameter("username", getServiceConfig().getUser())); service.addParameter(createParameter("password", getServiceConfig().getPassword()));
public static CollectionSpecification createCollectionSpec(String svcName, ServiceCollector svcCollector, String collectionName) { Package pkg = new Package(); Filter filter = new Filter(); filter.setContent("IPADDR IPLIKE *.*.*.*"); pkg.setFilter(filter); Service service = new Service(); service.setName(svcName); Parameter collectionParm = new Parameter(); collectionParm.setKey("collection"); collectionParm.setValue(collectionName); service.addParameter(collectionParm); pkg.addService(service); CollectionSpecification spec = new CollectionSpecification(pkg, svcName, svcCollector, new DefaultCollectdInstrumentation(), createLocationAwareCollectorClient()); return spec; }
private void initializeParameters() { final Map<String, Object> m = new TreeMap<String, Object>(); m.put(ParameterName.SERVICE.toString(), m_svcName); m.put(ParameterName.SERVICE_INTERVAL.toString(), getService().getInterval().toString()); StringBuilder sb; Collection<Parameter> params = getService().getParameters(); for (Parameter p : params) { if (LOG.isDebugEnabled()) {
/** * 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; }
/** * 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(); }
public final void doTestNMS4886(String svcName) throws Exception { HttpCollector collector = new HttpCollector(); Map<String, String> parameters = new HashMap<String, String>(); parameters.put("http-collection", "default"); parameters.put("port", "10342"); collector.initialize(); Package pkg = new Package(); Filter filter = new Filter(); filter.setContent("IPADDR IPLIKE *.*.*.*"); pkg.setFilter(filter); Service service = new Service(); service.setName(svcName); Parameter collectionParm = new Parameter(); collectionParm.setKey("http-collection"); collectionParm.setValue("default"); service.addParameter(collectionParm); Parameter portParm = new Parameter(); portParm.setKey("port"); portParm.setValue("10342"); service.addParameter(portParm); pkg.addService(service); CollectionSpecification collectionSpecification = new CollectionSpecification(pkg, svcName, collector, new DefaultCollectdInstrumentation(), CollectorTestUtils.createLocationAwareCollectorClient()); CollectionSet collectionSet = collectionSpecification.collect(m_collectionAgent); assertEquals("collection status", CollectionStatus.SUCCEEDED, collectionSet.getStatus()); CollectorTestUtils.persistCollectionSet(m_rrdStrategy, m_resourceStorageDao, collectionSpecification, collectionSet); }
public CollectdConfiguration getCollectdConfigurationForPackages(List<String> collectionPackageNames) { if (collectionPackageNames == null || collectionPackageNames.size() < 1) return null; final Set<String> seenCollectors = new HashSet<>(); final CollectdConfiguration newConfig = new CollectdConfiguration(); newConfig.setThreads(getThreads()); // Add all requested polling packages to the config boolean foundPackage = false; for (String packageName : collectionPackageNames) { final Package pkg = getPackage(packageName); if (pkg != null) { newConfig.addPackage(pkg); foundPackage = true; for (final Service service : pkg.getServices()) { seenCollectors.add(service.getName()); } } } // If the list of polling packages doesn't match anything, then return null if (!foundPackage) return null; for (final Collector collector : getCollectors()) { if (seenCollectors.contains(collector.getService())) { newConfig.addCollector(collector); } } return newConfig; }
/** * <p>getInterval</p> * * @return a long. */ public long getInterval() { return getService().getInterval(); }
private static Package getCollectionPackageThatMatchesSNMP() { Package pkg = new Package(); pkg.setName("pkg"); Filter filter = new Filter(); filter.setContent("IPADDR IPLIKE *.*.*.*"); pkg.setFilter(filter); Service svc = new Service(); pkg.addService(svc); svc.setName("SNMP"); svc.setStatus("on"); Parameter parm = new Parameter(); parm.setKey("collection"); parm.setValue("default"); svc.addParameter(parm); parm = new Parameter(); parm.setKey("thresholding-enabled"); parm.setValue("true"); svc.addParameter(parm); svc.setStatus("on"); return pkg; }
.withCollector(getCollector()) .withTimeToLive(getService().getInterval()) .execute() .get();
.withCollector(getCollector()) .withTimeToLive(getService().getInterval()) .execute() .get();