Search in sources :

Example 6 with Service

use of org.opennms.netmgt.config.collectd.Service in project opennms by OpenNMS.

the class JmxRrdMigratorOffline method getJmxResourceDirectories.

/**
 * Gets the JMX resource directories.
 *
 * @return the JMX resource directories
 * @throws OnmsUpgradeException the OpenNMS upgrade exception
 */
private List<File> getJmxResourceDirectories() throws OnmsUpgradeException {
    if (jmxResourceDirectories == null) {
        jmxResourceDirectories = new ArrayList<>();
        CollectdConfiguration config;
        try {
            config = new CollectdConfigFactory().getCollectdConfig();
        } catch (Exception e) {
            throw new OnmsUpgradeException("Can't upgrade the JRBs because " + e.getMessage(), e);
        }
        List<String> services = getJmxServices(config);
        log("JMX services found: %s\n", services);
        List<String> jmxFriendlyNames = new ArrayList<>();
        for (String service : services) {
            Service svc = getServiceObject(config, service);
            if (svc != null) {
                String friendlyName = getSvcPropertyValue(svc, "friendly-name");
                if (friendlyName == null) {
                    // According with JMXCollector, port will be used if there is no friendly-name.
                    friendlyName = getSvcPropertyValue(svc, "port");
                }
                if (friendlyName == null) {
                    log("Warning: there is no friendly-name or port parameter for service %s. The JRBs/RRDs for this service are not going to be updated.", service);
                } else {
                    jmxFriendlyNames.add(friendlyName);
                }
            } else {
                log("Warning: JMX service %s is defined but not used in any package definition. Skipping migration.\n", service);
            }
        }
        log("JMX friendly names found: %s\n", jmxFriendlyNames);
        File rrdDir = new File(jmxDataCollectionConfigDao.getRrdPath());
        findJmxDirectories(rrdDir, jmxFriendlyNames, jmxResourceDirectories);
        if (jmxResourceDirectories.isEmpty()) {
            log("Warning: no JMX directories found on %s\n", rrdDir);
        }
    }
    return jmxResourceDirectories;
}
Also used : CollectdConfiguration(org.opennms.netmgt.config.collectd.CollectdConfiguration) ArrayList(java.util.ArrayList) Service(org.opennms.netmgt.config.collectd.Service) CollectdConfigFactory(org.opennms.netmgt.config.CollectdConfigFactory) File(java.io.File) OnmsUpgradeException(org.opennms.upgrade.api.OnmsUpgradeException) IOException(java.io.IOException) OnmsUpgradeException(org.opennms.upgrade.api.OnmsUpgradeException)

Example 7 with Service

use of org.opennms.netmgt.config.collectd.Service in project opennms by OpenNMS.

the class CollectorTestUtils method createCollectionSpec.

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;
}
Also used : Filter(org.opennms.netmgt.config.collectd.Filter) CollectionSpecification(org.opennms.netmgt.collection.core.CollectionSpecification) Service(org.opennms.netmgt.config.collectd.Service) Parameter(org.opennms.netmgt.config.collectd.Parameter) Package(org.opennms.netmgt.config.collectd.Package) DefaultCollectdInstrumentation(org.opennms.netmgt.collection.core.DefaultCollectdInstrumentation)

Example 8 with Service

use of org.opennms.netmgt.config.collectd.Service in project opennms by OpenNMS.

the class UiModel method getCollectdConfiguration.

/**
 * Creates a CollectdConfiguration snippet depending on the data saved here.
 *
 * @return The CollecdConfiguration snippet depending on the data saved in
 *         this model.
 */
public CollectdConfiguration getCollectdConfiguration() {
    CollectdConfiguration config = new CollectdConfiguration();
    // set default package
    Package defaultPackage = new Package();
    defaultPackage.setName("default");
    // set service
    Service service = new Service();
    service.setName(getServiceName());
    service.setInterval(300000L);
    service.setUserDefined(Boolean.TRUE.toString());
    service.setStatus("on");
    // add parameters to service
    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()));
    // If we used credentials, we set them here as well
    if (getServiceConfig().isAuthenticate()) {
        service.addParameter(createParameter("factory", "PASSWORD-CLEAR"));
        service.addParameter(createParameter("username", getServiceConfig().getUser()));
        service.addParameter(createParameter("password", getServiceConfig().getPassword()));
    }
    // create Collector
    Collector collector = new Collector();
    collector.setService(getServiceName());
    collector.setClassName("org.opennms.netmgt.collectd.Jsr160Collector");
    // register service, package and collector to configuration
    config.addPackage(defaultPackage);
    config.addCollector(collector);
    defaultPackage.addService(service);
    return config;
}
Also used : CollectdConfiguration(org.opennms.netmgt.config.collectd.CollectdConfiguration) Collector(org.opennms.netmgt.config.collectd.Collector) Service(org.opennms.netmgt.config.collectd.Service) Package(org.opennms.netmgt.config.collectd.Package)

Example 9 with Service

use of org.opennms.netmgt.config.collectd.Service in project opennms by OpenNMS.

the class HttpCollectorIT method doTestNMS4886.

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);
}
Also used : HashMap(java.util.HashMap) Filter(org.opennms.netmgt.config.collectd.Filter) CollectionSpecification(org.opennms.netmgt.collection.core.CollectionSpecification) Service(org.opennms.netmgt.config.collectd.Service) Parameter(org.opennms.netmgt.config.collectd.Parameter) Package(org.opennms.netmgt.config.collectd.Package) DefaultCollectdInstrumentation(org.opennms.netmgt.collection.core.DefaultCollectdInstrumentation) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet)

Example 10 with Service

use of org.opennms.netmgt.config.collectd.Service in project opennms by OpenNMS.

the class AgentConfigurationResource method getResponses.

protected List<AgentResponse> getResponses(final String filterName, final String serviceName) throws ConfigurationResourceException {
    LOG.debug("getAgentsForService(): filterName={}, serviceName={}", filterName, serviceName);
    if (filterName == null || serviceName == null) {
        throw new WebApplicationException(Response.status(Status.BAD_REQUEST).type(MediaType.TEXT_PLAIN).entity("You must specify a filter name and service name!").build());
    }
    final Filter filter = m_collectdConfigurationResource.get().getFilter(filterName);
    if (filter == null) {
        LOG.warn("No filter matching {} could be found.", filterName);
        throw new WebApplicationException(Status.NOT_FOUND);
    }
    final List<InetAddress> addresses = m_filterDao.getActiveIPAddressList(filter.getContent());
    LOG.debug("Matched {} IP addresses for filter {}", addresses == null ? 0 : addresses.size(), filterName);
    if (addresses == null || addresses.size() == 0) {
        return Collections.emptyList();
    }
    final CriteriaBuilder builder = new CriteriaBuilder(OnmsMonitoredService.class);
    builder.createAlias("ipInterface", "iface");
    builder.createAlias("serviceType", "type");
    builder.createAlias("iface.node", "node");
    builder.in("iface.ipAddress", addresses);
    builder.eq("type.name", serviceName);
    final List<OnmsMonitoredService> services = m_monitoredServiceDao.findMatching(builder.toCriteria());
    int defaultPort = -1;
    // TODO: We shouldn't have to hardcode like this; what's the right way to know the port to return?
    final CollectdConfiguration collectdConfiguration = m_collectdConfigurationResource.get();
    org.opennms.netmgt.config.collectd.Package pack = collectdConfiguration.getPackage(filterName);
    if (pack == null) {
        for (final org.opennms.netmgt.config.collectd.Package p : collectdConfiguration.getPackages()) {
            if (filterName.equals(p.getFilter().getName())) {
                pack = p;
                break;
            }
        }
    }
    if (pack != null) {
        final Service svc = pack.getService(serviceName);
        final String port = svc.getParameter("port");
        if (port != null) {
            try {
                defaultPort = Integer.valueOf(port);
            } catch (final NumberFormatException e) {
                LOG.debug("Unable to turn port {} from service {} into a number.", port, serviceName);
            }
        }
    }
    final List<AgentResponse> responses = new ArrayList<>();
    for (final OnmsMonitoredService service : services) {
        final InetAddress ipAddress = service.getIpAddress();
        final OnmsIpInterface iface = service.getIpInterface();
        OnmsNode node = null;
        if (iface != null) {
            node = iface.getNode();
        }
        final Map<String, String> parameters = new TreeMap<String, String>();
        // all service parameters from collectd configuration to parameters map
        for (Parameter eachParameter : pack.getService(serviceName).getParameters()) {
            parameters.put(eachParameter.getKey(), eachParameter.getValue());
        }
        int port = defaultPort;
        if ("SNMP".equals(serviceName)) {
            final String sysObjectId = node == null ? null : node.getSysObjectId();
            if (sysObjectId != null) {
                parameters.put("sysObjectId", sysObjectId);
            }
            OnmsMonitoringLocation location = (node == null) ? null : node.getLocation();
            String locationName = (location == null) ? null : location.getLocationName();
            final SnmpAgentConfig config = m_agentConfigFactory.getAgentConfig(ipAddress, locationName);
            if (config != null) {
                port = config.getPort();
            }
        }
        if (node != null) {
            if (node.getNodeId() != null && !node.getNodeId().trim().isEmpty()) {
                parameters.put("nodeId", node.getNodeId());
            }
            if (node.getForeignSource() != null && !node.getForeignSource().trim().isEmpty()) {
                parameters.put("foreignSource", node.getForeignSource());
            }
            if (node.getForeignId() != null && !node.getForeignId().trim().isEmpty()) {
                parameters.put("foreignId", node.getForeignId());
            }
        }
        responses.add(new AgentResponse(ipAddress, port, service.getServiceName(), parameters));
    }
    return responses;
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) CollectdConfiguration(org.opennms.netmgt.config.collectd.CollectdConfiguration) AgentResponse(org.opennms.netmgt.config.agents.AgentResponse) CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) OnmsNode(org.opennms.netmgt.model.OnmsNode) Service(org.opennms.netmgt.config.collectd.Service) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) TreeMap(java.util.TreeMap) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Filter(org.opennms.netmgt.config.collectd.Filter) Parameter(org.opennms.netmgt.config.collectd.Parameter) InetAddress(java.net.InetAddress) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)

Aggregations

Service (org.opennms.netmgt.config.collectd.Service)10 Filter (org.opennms.netmgt.config.collectd.Filter)8 Package (org.opennms.netmgt.config.collectd.Package)8 Parameter (org.opennms.netmgt.config.collectd.Parameter)6 CollectdConfiguration (org.opennms.netmgt.config.collectd.CollectdConfiguration)3 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)3 ArrayList (java.util.ArrayList)2 TreeMap (java.util.TreeMap)2 CollectionSpecification (org.opennms.netmgt.collection.core.CollectionSpecification)2 DefaultCollectdInstrumentation (org.opennms.netmgt.collection.core.DefaultCollectdInstrumentation)2 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)2 OnmsNode (org.opennms.netmgt.model.OnmsNode)2 File (java.io.File)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 HashMap (java.util.HashMap)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Before (org.junit.Before)1 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)1 MockRpcClientFactory (org.opennms.core.rpc.mock.MockRpcClientFactory)1