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();
}
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();
}
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());
}
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());
}
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();
}
Aggregations