Search in sources :

Example 1 with CollectdConfiguration

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

the class CollectionConfigurationResource method getCollectdConfigurationForLocation.

@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
public Response getCollectdConfigurationForLocation(@PathParam("location") final String location) throws ConfigurationResourceException {
    final OnmsMonitoringLocation def = m_monitoringLocationDao.get(location);
    if (def == null) {
        LOG.warn("Unable to find monitoring location {}", location);
        return Response.status(Response.Status.NOT_FOUND).build();
    }
    final List<String> collectionPackageNames = def.getCollectionPackageNames();
    if (collectionPackageNames != null && collectionPackageNames.size() > 0) {
        final CollectdConfiguration collectdConfig = m_collectdConfigResource.get().getCollectdConfigurationForPackages(collectionPackageNames);
        return Response.ok(collectdConfig).build();
    }
    LOG.warn("Monitoring location {} does not have a collection package defined.", location);
    return Response.status(Response.Status.NOT_FOUND).build();
}
Also used : CollectdConfiguration(org.opennms.netmgt.config.collectd.CollectdConfiguration) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with CollectdConfiguration

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

the class JaxbResourceConfigurationTest method testFileSystemResourceDoesNotExist.

@Test(expected = org.opennms.core.config.api.ConfigurationResourceException.class)
public void testFileSystemResourceDoesNotExist() throws ConfigurationResourceException {
    final File configFile = new File("target/test-classes/collectd-configuration.x");
    final ConfigurationResource<CollectdConfiguration> collectd = new JaxbResourceConfiguration<CollectdConfiguration>(CollectdConfiguration.class, new FileSystemResource(configFile));
    assertNotNull(collectd);
    collectd.get();
}
Also used : CollectdConfiguration(org.opennms.netmgt.config.collectd.CollectdConfiguration) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) Test(org.junit.Test)

Example 3 with CollectdConfiguration

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

the class JaxbResourceConfigurationTest method testSave.

@Test
public void testSave() throws ConfigurationResourceException, IOException {
    final File configFile = getConfigFile();
    final ConfigurationResource<CollectdConfiguration> collectd = new JaxbResourceConfiguration<CollectdConfiguration>(CollectdConfiguration.class, new FileSystemResource(configFile));
    assertNotNull(collectd);
    CollectdConfiguration config = collectd.get();
    assertNotNull(config);
    assertEquals(5, config.getPackages().size());
    config.removePackage(config.getPackages().get(0));
    assertEquals("vmware4", config.getPackages().get(0).getName());
    assertEquals(4, config.getPackages().size());
    collectd.save(config);
    config = collectd.get();
    assertNotNull(config);
    assertEquals(4, config.getPackages().size());
    assertEquals("vmware4", config.getPackages().get(0).getName());
}
Also used : CollectdConfiguration(org.opennms.netmgt.config.collectd.CollectdConfiguration) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) Test(org.junit.Test)

Example 4 with CollectdConfiguration

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

the class JaxbResourceConfigurationTest method testFileSystemResourceExists.

@Test
public void testFileSystemResourceExists() throws ConfigurationResourceException, IOException {
    final File configFile = getConfigFile();
    final ConfigurationResource<CollectdConfiguration> collectd = new JaxbResourceConfiguration<CollectdConfiguration>(CollectdConfiguration.class, new FileSystemResource(configFile));
    assertNotNull(collectd);
    final CollectdConfiguration config = collectd.get();
    assertNotNull(config);
    assertEquals(5, config.getPackages().size());
    assertEquals("vmware3", config.getPackages().get(0).getName());
}
Also used : CollectdConfiguration(org.opennms.netmgt.config.collectd.CollectdConfiguration) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) Test(org.junit.Test)

Example 5 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)

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 CollectionSpecification (org.opennms.netmgt.collection.core.CollectionSpecification)1