Search in sources :

Example 6 with Parameter

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

the class CollectorTestUtils method createCollectionSpec.

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) Service(org.opennms.netmgt.config.collectd.Service) Parameter(org.opennms.netmgt.config.collectd.Parameter) Package(org.opennms.netmgt.config.collectd.Package)

Example 7 with Parameter

use of org.opennms.netmgt.config.collectd.Parameter 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<AgentResponse>();
    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)

Example 8 with Parameter

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

the class CollectionSpecification method initializeParameters.

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());
    StringBuffer sb;
    Collection<Parameter> params = getService().getParameters();
    for (Parameter p : params) {
        if (LOG.isDebugEnabled()) {
            sb = new StringBuffer();
            sb.append("initializeParameters: adding service: ");
            sb.append(getServiceName());
            sb.append(" parameter: ");
            sb.append(p.getKey());
            sb.append(" of value ");
            sb.append(p.getValue());
            LOG.debug(sb.toString());
        }
        m.put(p.getKey(), p.getValue());
    }
    if (storeByIfAlias() != null && isTrue(storeByIfAlias())) {
        m.put("storeByIfAlias", "true");
        if (storeByNodeId() != null) {
            if (isTrue(storeByNodeId())) {
                m.put("storeByNodeID", "true");
            } else if (isFalse(storeByNodeId())) {
                m.put("storeByNodeID", "false");
            } else {
                m.put("storeByNodeID", "normal");
            }
        }
        if (ifAliasDomain() != null) {
            m.put("domain", ifAliasDomain());
        } else {
            m.put("domain", getPackageName());
        }
        if (storeFlagOverride() != null && isTrue(storeFlagOverride())) {
            m.put("storFlagOverride", "true");
        }
        m.put("ifAliasComment", ifAliasComment());
        if (LOG.isDebugEnabled()) {
            sb = new StringBuffer();
            sb.append("ifAliasDomain = ");
            sb.append(ifAliasDomain());
            sb.append(", storeByIfAlias = ");
            sb.append(storeByIfAlias());
            sb.append(", storeByNodeID = ");
            sb.append(storeByNodeId());
            sb.append(", storFlagOverride = ");
            sb.append(storeFlagOverride());
            sb.append(", ifAliasComment = ");
            sb.append(ifAliasComment());
            LOG.debug(sb.toString());
        }
    }
    m.put("packageName", m_package.getName());
    m_parameters = m;
}
Also used : Parameter(org.opennms.netmgt.config.collectd.Parameter) TreeMap(java.util.TreeMap)

Aggregations

Parameter (org.opennms.netmgt.config.collectd.Parameter)8 Filter (org.opennms.netmgt.config.collectd.Filter)5 Service (org.opennms.netmgt.config.collectd.Service)5 Package (org.opennms.netmgt.config.collectd.Package)4 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)3 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)3 TreeMap (java.util.TreeMap)2 CollectdConfiguration (org.opennms.netmgt.config.collectd.CollectdConfiguration)2 File (java.io.File)1 InetAddress (java.net.InetAddress)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Before (org.junit.Before)1 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)1 InsufficientInformationException (org.opennms.core.utils.InsufficientInformationException)1 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)1 DefaultServiceCollectorRegistry (org.opennms.netmgt.collection.support.DefaultServiceCollectorRegistry)1 CollectdConfigFactory (org.opennms.netmgt.config.CollectdConfigFactory)1 PollOutagesConfigFactory (org.opennms.netmgt.config.PollOutagesConfigFactory)1