Search in sources :

Example 6 with CollectdConfiguration

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

the class Collectd method getSpecificationsForInterface.

/**
     * <p>getSpecificationsForInterface</p>
     *
     * @param iface a {@link org.opennms.netmgt.model.OnmsIpInterface} object.
     * @param svcName a {@link java.lang.String} object.
     * @return a {@link java.util.Collection} object.
     */
public Collection<CollectionSpecification> getSpecificationsForInterface(OnmsIpInterface iface, String svcName) {
    Collection<CollectionSpecification> matchingPkgs = new LinkedList<CollectionSpecification>();
    CollectdConfiguration collectdConfig = m_collectdConfigFactory.getCollectdConfig();
    /*
         * Compare interface/service pair against each collectd package
         * For each match, create new SnmpCollector object and
         * schedule it for collection
         */
    for (Package wpkg : collectdConfig.getPackages()) {
        /*
             * Make certain the the current service is in the package
             * and enabled!
             */
        if (!wpkg.serviceInPackageAndEnabled(svcName)) {
            LOG.debug("getSpecificationsForInterface: address/service: {}/{} not scheduled, service is not enabled or does not exist in package: {}", iface, svcName, wpkg.getName());
            continue;
        }
        // Ensure that the package is not a remote package
        if (wpkg.isRemote()) {
            LOG.debug("getSpecificationsForInterface: address/service: {}/{} not scheduled, package {} is a remote package.", iface, svcName, wpkg.getName());
            continue;
        }
        // Is the interface in the package?
        if (!m_collectdConfigFactory.interfaceInPackage(iface, wpkg)) {
            LOG.debug("getSpecificationsForInterface: address/service: {}/{} not scheduled, interface does not belong to package: {}", iface, svcName, wpkg.getName());
            continue;
        }
        LOG.debug("getSpecificationsForInterface: address/service: {}/{} scheduled, interface does belong to package: {}", iface, svcName, wpkg.getName());
        matchingPkgs.add(new CollectionSpecification(wpkg, svcName, getServiceCollector(svcName), instrumentation(), m_locationAwareCollectorClient));
    }
    return matchingPkgs;
}
Also used : CollectdConfiguration(org.opennms.netmgt.config.collectd.CollectdConfiguration) Package(org.opennms.netmgt.config.collectd.Package) LinkedList(java.util.LinkedList)

Example 7 with CollectdConfiguration

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

the class CollectdConfigFactory method saveCurrent.

/**
     * Saves the current in-memory configuration to disk and reloads
     *
     * @throws java.io.IOException if any.
     */
public void saveCurrent() throws IOException {
    File cfgFile = ConfigFileConstants.getFile(ConfigFileConstants.COLLECTD_CONFIG_FILE_NAME);
    CollectdConfiguration config = null;
    synchronized (m_collectdConfigMutex) {
        config = m_collectdConfig;
    }
    FileWriter writer = null;
    try {
        writer = new FileWriter(cfgFile);
        JaxbUtils.marshal(config, writer);
    } finally {
        IOUtils.closeQuietly(writer);
    }
    reload();
}
Also used : CollectdConfiguration(org.opennms.netmgt.config.collectd.CollectdConfiguration) FileWriter(java.io.FileWriter) File(java.io.File)

Example 8 with CollectdConfiguration

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

the class CollectdConfigFactory method init.

/**
     * <p>Constructor for CollectdConfigFactory.</p>
     *
     * @param stream a {@link java.io.InputStream} object.
     * @param localServer a {@link java.lang.String} object.
     * @param verifyServer a boolean.
     * @throws IOException 
     */
private void init(final InputStream stream, final String localServer, boolean verifyServer) throws IOException {
    InputStreamReader isr = null;
    try {
        isr = new InputStreamReader(stream);
        CollectdConfiguration config = JaxbUtils.unmarshal(CollectdConfiguration.class, isr);
        synchronized (m_collectdConfigMutex) {
            m_collectdConfig = config;
        }
    } finally {
        IOUtils.closeQuietly(isr);
    }
}
Also used : CollectdConfiguration(org.opennms.netmgt.config.collectd.CollectdConfiguration) InputStreamReader(java.io.InputStreamReader)

Example 9 with CollectdConfiguration

use of org.opennms.netmgt.config.collectd.CollectdConfiguration 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<File>();
        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<String>();
        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 10 with CollectdConfiguration

use of org.opennms.netmgt.config.collectd.CollectdConfiguration 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)

Aggregations

CollectdConfiguration (org.opennms.netmgt.config.collectd.CollectdConfiguration)12 File (java.io.File)5 Test (org.junit.Test)4 Service (org.opennms.netmgt.config.collectd.Service)3 FileSystemResource (org.springframework.core.io.FileSystemResource)3 ArrayList (java.util.ArrayList)2 Collector (org.opennms.netmgt.config.collectd.Collector)2 Package (org.opennms.netmgt.config.collectd.Package)2 OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)2 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 InetAddress (java.net.InetAddress)1 LinkedList (java.util.LinkedList)1 TreeMap (java.util.TreeMap)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)1 CollectdConfigFactory (org.opennms.netmgt.config.CollectdConfigFactory)1