use of org.opennms.netmgt.config.collectd.Collector in project opennms by OpenNMS.
the class CollectdConfigFile method visit.
/**
* <p>visit</p>
*
* @param visitor a {@link org.opennms.netmgt.dao.jaxb.collector.CollectdConfigVisitor} object.
*/
public void visit(CollectdConfigVisitor visitor) {
CollectdConfiguration collectdConfiguration = getCollectdConfiguration();
visitor.visitCollectdConfiguration(collectdConfiguration);
for (Iterator<Collector> it = collectdConfiguration.getCollectors().iterator(); it.hasNext(); ) {
Collector collector = it.next();
doVisit(collector, visitor);
}
visitor.completeCollectdConfiguration(collectdConfiguration);
}
use of org.opennms.netmgt.config.collectd.Collector in project opennms by OpenNMS.
the class Collectd method instantiateCollectors.
private void instantiateCollectors() {
LOG.debug("instantiateCollectors: Loading collectors");
/*
* Load up an instance of each collector from the config
* so that the event processor will have them for
* new incoming events to create collectable service objects.
*/
Collection<Collector> collectors = m_collectdConfigFactory.getCollectdConfig().getCollectors();
for (Collector collector : collectors) {
String svcName = collector.getService();
try {
LOG.debug("instantiateCollectors: Loading collector {}, classname {}", svcName, collector.getClassName());
final ServiceCollector sc = m_serviceCollectorRegistry.getCollectorByClassName(collector.getClassName());
if (sc == null) {
throw new IllegalArgumentException(String.format("No collector found with class name '%s'. Available collectors include: %s", collector.getClassName(), m_serviceCollectorRegistry.getCollectorClassNames()));
}
sc.initialize();
setServiceCollector(svcName, sc);
} catch (Throwable t) {
LOG.warn("instantiateCollectors: Failed to load collector {} for service {}", collector.getClassName(), svcName, t);
}
}
}
use of org.opennms.netmgt.config.collectd.Collector in project opennms by OpenNMS.
the class Collectd method rebuildScheduler.
private void rebuildScheduler() {
// Register new collectors if necessary
Set<String> configuredCollectors = new HashSet<String>();
for (Collector collector : m_collectdConfigFactory.getCollectdConfig().getCollectors()) {
String svcName = collector.getService();
configuredCollectors.add(svcName);
if (getServiceCollector(svcName) == null) {
try {
LOG.debug("rebuildScheduler: Loading collector {}, classname {}", svcName, collector.getClassName());
Class<?> cc = Class.forName(collector.getClassName());
ServiceCollector sc = (ServiceCollector) cc.newInstance();
sc.initialize();
setServiceCollector(svcName, sc);
} catch (Throwable t) {
LOG.warn("rebuildScheduler: Failed to load collector {} for service {}", collector.getClassName(), svcName, t);
}
}
}
// Removing unused collectors if necessary
List<String> blackList = new ArrayList<String>();
for (String collectorName : getCollectorNames()) {
if (!configuredCollectors.contains(collectorName)) {
blackList.add(collectorName);
}
}
for (String collectorName : blackList) {
LOG.info("rebuildScheduler: removing collector for {}, it is no longer required", collectorName);
m_collectors.remove(collectorName);
}
// Recreating all Collectable Services (using the nodeID list populated at the beginning)
Collection<Integer> nodeIds = m_nodeDao.getNodeIds();
m_filterDao.flushActiveIpAddressListCache();
for (Integer nodeId : nodeIds) {
unscheduleNodeAndMarkForDeletion(new Long(nodeId));
scheduleNode(nodeId, true);
}
}
use of org.opennms.netmgt.config.collectd.Collector 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;
}
use of org.opennms.netmgt.config.collectd.Collector in project opennms by OpenNMS.
the class CollectdIntegrationTest method setUp.
@Before
public void setUp() throws Exception {
m_eventIpcManager = new MockEventIpcManager();
EventIpcManagerFactory.setIpcManager(m_eventIpcManager);
m_mockUtils = new EasyMockUtils();
m_filterDao = m_mockUtils.createMock(FilterDao.class);
FilterDaoFactory.setInstance(m_filterDao);
// This call will also ensure that the poll-outages.xml file can parse IPv4
// and IPv6 addresses.
Resource resource = new ClassPathResource("etc/poll-outages.xml");
PollOutagesConfigFactory factory = new PollOutagesConfigFactory(resource);
factory.afterPropertiesSet();
PollOutagesConfigFactory.setInstance(factory);
File homeDir = resource.getFile().getParentFile().getParentFile();
System.setProperty("opennms.home", homeDir.getAbsolutePath());
resource = new ClassPathResource("/test-thresholds.xml");
ThresholdingConfigFactory.setInstance(new ThresholdingConfigFactory(resource.getInputStream()));
// set up test using a string key
m_key = m_testName.getMethodName() + System.nanoTime();
m_tests.put(m_key, this);
//create a collector definition
Collector collector = new Collector();
collector.setService("SNMP");
collector.setClassName(MockServiceCollector.class.getName());
// pass the key to the collector definition so it can look up the associated test
Parameter param = new Parameter();
param.setKey(TEST_KEY_PARM_NAME);
param.setValue(m_key);
collector.addParameter(param);
m_collectdConfigFactory = m_mockUtils.createMock(CollectdConfigFactory.class);
m_collectdConfiguration = m_mockUtils.createMock(CollectdConfiguration.class);
EasyMock.expect(m_collectdConfigFactory.getCollectdConfig()).andReturn(m_collectdConfiguration).anyTimes();
EasyMock.expect(m_collectdConfiguration.getCollectors()).andReturn(Collections.singletonList(collector)).anyTimes();
EasyMock.expect(m_collectdConfiguration.getThreads()).andReturn(1).anyTimes();
m_ifaceDao = m_mockUtils.createMock(IpInterfaceDao.class);
m_nodeDao = m_mockUtils.createMock(NodeDao.class);
m_collectd = new Collectd() {
@Override
protected void handleInsufficientInfo(InsufficientInformationException e) {
fail("Invalid event received: " + e.getMessage());
}
};
OnmsServiceType snmp = new OnmsServiceType("SNMP");
NetworkBuilder netBuilder = new NetworkBuilder();
NodeBuilder nodeBuilder = netBuilder.addNode("node1").setId(1);
InterfaceBuilder ifaceBlder = netBuilder.addInterface("192.168.1.1").setId(2).setIsSnmpPrimary("P");
ifaceBlder.addSnmpInterface(1);
OnmsMonitoredService svc = netBuilder.addService(snmp);
List<OnmsIpInterface> initialIfs = Collections.emptyList();
EasyMock.expect(m_ifaceDao.findByServiceType(snmp.getName())).andReturn(initialIfs).anyTimes();
m_filterDao.flushActiveIpAddressListCache();
EasyMock.expect(m_nodeDao.load(1)).andReturn(nodeBuilder.getNode()).anyTimes();
createGetPackagesExpectation(svc);
EasyMock.expect(m_ifaceDao.load(2)).andReturn(ifaceBlder.getInterface()).anyTimes();
m_mockUtils.replayAll();
final MockTransactionTemplate transTemplate = new MockTransactionTemplate();
transTemplate.afterPropertiesSet();
m_collectd.setCollectdConfigFactory(m_collectdConfigFactory);
m_collectd.setEventIpcManager(m_eventIpcManager);
m_collectd.setTransactionTemplate(transTemplate);
m_collectd.setIpInterfaceDao(m_ifaceDao);
m_collectd.setNodeDao(m_nodeDao);
m_collectd.setFilterDao(m_filterDao);
m_collectd.setPersisterFactory(new MockPersisterFactory());
m_collectd.setServiceCollectorRegistry(new DefaultServiceCollectorRegistry());
m_collectd.setLocationAwareCollectorClient(CollectorTestUtils.createLocationAwareCollectorClient());
// Inits the class
m_collectd.afterPropertiesSet();
//assertNotNull(m_serviceCollector);
}
Aggregations