Search in sources :

Example 1 with Collector

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);
}
Also used : CollectdConfiguration(org.opennms.netmgt.config.collectd.CollectdConfiguration) Collector(org.opennms.netmgt.config.collectd.Collector)

Example 2 with Collector

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);
        }
    }
}
Also used : ServiceCollector(org.opennms.netmgt.collection.api.ServiceCollector) Collector(org.opennms.netmgt.config.collectd.Collector) ServiceCollector(org.opennms.netmgt.collection.api.ServiceCollector)

Example 3 with Collector

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);
    }
}
Also used : ServiceCollector(org.opennms.netmgt.collection.api.ServiceCollector) Collector(org.opennms.netmgt.config.collectd.Collector) ArrayList(java.util.ArrayList) ServiceCollector(org.opennms.netmgt.collection.api.ServiceCollector) HashSet(java.util.HashSet)

Example 4 with Collector

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

Example 5 with Collector

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);
}
Also used : DefaultServiceCollectorRegistry(org.opennms.netmgt.collection.support.DefaultServiceCollectorRegistry) MockEventIpcManager(org.opennms.netmgt.dao.mock.MockEventIpcManager) InsufficientInformationException(org.opennms.core.utils.InsufficientInformationException) EasyMockUtils(org.opennms.test.mock.EasyMockUtils) NodeBuilder(org.opennms.netmgt.model.NetworkBuilder.NodeBuilder) NodeDao(org.opennms.netmgt.dao.api.NodeDao) CollectdConfiguration(org.opennms.netmgt.config.collectd.CollectdConfiguration) NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) Collector(org.opennms.netmgt.config.collectd.Collector) MockPersisterFactory(org.opennms.netmgt.mock.MockPersisterFactory) PollOutagesConfigFactory(org.opennms.netmgt.config.PollOutagesConfigFactory) Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource) CollectdConfigFactory(org.opennms.netmgt.config.CollectdConfigFactory) InterfaceBuilder(org.opennms.netmgt.model.NetworkBuilder.InterfaceBuilder) MockTransactionTemplate(org.opennms.netmgt.dao.mock.MockTransactionTemplate) ClassPathResource(org.springframework.core.io.ClassPathResource) IpInterfaceDao(org.opennms.netmgt.dao.api.IpInterfaceDao) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) FilterDao(org.opennms.netmgt.filter.api.FilterDao) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) Parameter(org.opennms.netmgt.config.collectd.Parameter) File(java.io.File) ThresholdingConfigFactory(org.opennms.netmgt.config.ThresholdingConfigFactory) Before(org.junit.Before)

Aggregations

Collector (org.opennms.netmgt.config.collectd.Collector)7 CollectdConfiguration (org.opennms.netmgt.config.collectd.CollectdConfiguration)5 ServiceCollector (org.opennms.netmgt.collection.api.ServiceCollector)3 CollectdConfigFactory (org.opennms.netmgt.config.CollectdConfigFactory)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 InsufficientInformationException (org.opennms.core.utils.InsufficientInformationException)2 DefaultServiceCollectorRegistry (org.opennms.netmgt.collection.support.DefaultServiceCollectorRegistry)2 PollOutagesConfigFactory (org.opennms.netmgt.config.PollOutagesConfigFactory)2 IpInterfaceDao (org.opennms.netmgt.dao.api.IpInterfaceDao)2 NodeDao (org.opennms.netmgt.dao.api.NodeDao)2 MockEventIpcManager (org.opennms.netmgt.dao.mock.MockEventIpcManager)2 MockTransactionTemplate (org.opennms.netmgt.dao.mock.MockTransactionTemplate)2 FilterDao (org.opennms.netmgt.filter.api.FilterDao)2 MockPersisterFactory (org.opennms.netmgt.mock.MockPersisterFactory)2 NetworkBuilder (org.opennms.netmgt.model.NetworkBuilder)2 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)2 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)2 EasyMockUtils (org.opennms.test.mock.EasyMockUtils)2 ClassPathResource (org.springframework.core.io.ClassPathResource)2