Search in sources :

Example 6 with RrdPersisterFactory

use of org.opennms.netmgt.collection.persistence.rrd.RrdPersisterFactory in project opennms by OpenNMS.

the class AbstractVTDXmlCollectorTest method setUp.

/**
 * Sets the up.
 *
 * @throws Exception the exception
 */
@Before
public void setUp() throws Exception {
    MockLogAppender.setupLogging();
    m_rrdStrategy = new JRobinRrdStrategy();
    m_resourceStorageDao = new FilesystemResourceStorageDao();
    m_resourceStorageDao.setRrdDirectory(m_temporaryFolder.getRoot());
    m_temporaryFolder.newFolder("snmp");
    m_persisterFactory = new RrdPersisterFactory();
    m_persisterFactory.setResourceStorageDao(m_resourceStorageDao);
    m_persisterFactory.setRrdStrategy(m_rrdStrategy);
    m_collectionAgent = new MockCollectionAgent(1, "mynode.local", InetAddrUtils.addr("127.0.0.1"));
    m_eventProxy = EasyMock.createMock(EventProxy.class);
    m_xmlCollectionDao = new XmlDataCollectionConfigDaoJaxb();
    Resource resource = new FileSystemResource(getXmlConfigFileName());
    m_xmlCollectionDao.setConfigResource(resource);
    m_xmlCollectionDao.afterPropertiesSet();
    MockDocumentBuilder.setXmlFileName(getXmlSampleFileName());
    EasyMock.replay(m_eventProxy);
}
Also used : FilesystemResourceStorageDao(org.opennms.netmgt.dao.support.FilesystemResourceStorageDao) Resource(org.springframework.core.io.Resource) FileSystemResource(org.springframework.core.io.FileSystemResource) RrdPersisterFactory(org.opennms.netmgt.collection.persistence.rrd.RrdPersisterFactory) MockCollectionAgent(org.opennms.core.collection.test.MockCollectionAgent) FileSystemResource(org.springframework.core.io.FileSystemResource) JRobinRrdStrategy(org.opennms.netmgt.rrd.jrobin.JRobinRrdStrategy) XmlDataCollectionConfigDaoJaxb(org.opennms.protocols.xml.dao.jaxb.XmlDataCollectionConfigDaoJaxb) EventProxy(org.opennms.netmgt.events.api.EventProxy) Before(org.junit.Before)

Example 7 with RrdPersisterFactory

use of org.opennms.netmgt.collection.persistence.rrd.RrdPersisterFactory in project opennms by OpenNMS.

the class CollectableServiceTest method createCollectableService.

private void createCollectableService() throws CollectionInitializationException, IOException {
    // Mock it all!
    OnmsIpInterface iface = mock(OnmsIpInterface.class, RETURNS_DEEP_STUBS);
    IpInterfaceDao ifaceDao = mock(IpInterfaceDao.class);
    spec = mock(CollectionSpecification.class);
    scheduler = mock(Scheduler.class);
    SchedulingCompletedFlag schedulingCompletedFlag = mock(SchedulingCompletedFlag.class);
    PlatformTransactionManager transMgr = mock(PlatformTransactionManager.class);
    RrdPersisterFactory persisterFactory = new RrdPersisterFactory();
    persisterFactory.setRrdStrategy(rrdStrategy);
    ResourceStorageDao resourceStorageDao = mock(ResourceStorageDao.class);
    // Disable thresholding
    Map<String, Object> paramsMap = new HashMap<>();
    paramsMap.put("thresholding-enabled", Boolean.FALSE.toString());
    ServiceParameters params = new ServiceParameters(paramsMap);
    when(iface.getNode().getId()).thenReturn(1);
    when(spec.getServiceParameters()).thenReturn(params);
    when(spec.getRrdRepository(any())).thenReturn(createRrdRepository());
    when(ifaceDao.load(any())).thenReturn(iface);
    when(iface.getIpAddress()).thenReturn(InetAddrUtils.getLocalHostAddress());
    service = new CollectableService(iface, ifaceDao, spec, scheduler, schedulingCompletedFlag, transMgr, persisterFactory, resourceStorageDao);
}
Also used : ResourceStorageDao(org.opennms.netmgt.dao.api.ResourceStorageDao) HashMap(java.util.HashMap) Scheduler(org.opennms.netmgt.scheduler.Scheduler) CollectionSpecification(org.opennms.netmgt.collection.core.CollectionSpecification) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) IpInterfaceDao(org.opennms.netmgt.dao.api.IpInterfaceDao) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) RrdPersisterFactory(org.opennms.netmgt.collection.persistence.rrd.RrdPersisterFactory) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) SchedulingCompletedFlag(org.opennms.netmgt.collectd.Collectd.SchedulingCompletedFlag)

Example 8 with RrdPersisterFactory

use of org.opennms.netmgt.collection.persistence.rrd.RrdPersisterFactory in project opennms by OpenNMS.

the class SnmpAttributeTest method testPersisting.

@Ignore
private void testPersisting(String matchValue, SnmpValue snmpValue) throws Exception {
    OnmsNode node = new OnmsNode();
    node.setId(3);
    OnmsIpInterface ipInterface = new OnmsIpInterface();
    ipInterface.setId(1);
    ipInterface.setNode(node);
    ipInterface.setIpAddress(InetAddressUtils.addr("192.168.1.1"));
    // It used to be 3, but I think it is more correct to use getStoreDir from DefaultCollectionAgentService on DefaultCollectionAgent (NMS-7516)
    expect(m_ipInterfaceDao.load(1)).andReturn(ipInterface).times(5);
    expect(m_rrdStrategy.getDefaultFileExtension()).andReturn(".myLittleEasyMockedStrategyAndMe").anyTimes();
    expect(m_rrdStrategy.createDefinition(isA(String.class), isA(String.class), isA(String.class), anyInt(), isAList(RrdDataSource.class), isAList(String.class))).andReturn(new Object());
    m_rrdStrategy.createFile(isA(Object.class));
    expect(m_rrdStrategy.openFile(isA(String.class))).andReturn(new Object());
    m_rrdStrategy.updateFile(isA(Object.class), isA(String.class), matches(".*:" + matchValue));
    m_rrdStrategy.closeFile(isA(Object.class));
    m_mocks.replayAll();
    SnmpCollectionAgent agent = DefaultSnmpCollectionAgent.create(ipInterface.getId(), m_ipInterfaceDao, new MockPlatformTransactionManager());
    OnmsSnmpCollection snmpCollection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), new MockDataCollectionConfig(), m_locationAwareSnmpClient);
    NodeResourceType resourceType = new NodeResourceType(agent, snmpCollection);
    NodeInfo nodeInfo = resourceType.getNodeInfo();
    MibObject mibObject = new MibObject();
    mibObject.setOid(".1.3.6.1.4.1.12238.55.9997.4.1.2.9.116.101.109.112.95.117.108.107.111");
    mibObject.setInstance("1");
    mibObject.setAlias("temp_ulko");
    mibObject.setType("gauge");
    NumericAttributeType attributeType = new NumericAttributeType(resourceType, snmpCollection.getName(), mibObject, new AttributeGroupType("foo", AttributeGroupType.IF_TYPE_IGNORE));
    attributeType.storeResult(new SnmpCollectionSet(agent, snmpCollection, m_locationAwareSnmpClient), null, new SnmpResult(mibObject.getSnmpObjId(), new SnmpInstId(mibObject.getInstance()), snmpValue));
    RrdRepository repository = createRrdRepository();
    repository.setRraList(Collections.singletonList("RRA:AVERAGE:0.5:1:2016"));
    RrdPersisterFactory persisterFactory = new RrdPersisterFactory();
    persisterFactory.setRrdStrategy(m_rrdStrategy);
    persisterFactory.setResourceStorageDao(m_resourceStorageDao);
    CollectionSetVisitor persister = persisterFactory.createPersister(new ServiceParameters(Collections.emptyMap()), repository);
    final AtomicInteger count = new AtomicInteger(0);
    nodeInfo.visit(new CollectionSetVisitorWrapper(persister) {

        @Override
        public void visitAttribute(CollectionAttribute attribute) {
            super.visitAttribute(attribute);
            count.incrementAndGet();
        }
    });
    assertEquals(1, count.get());
}
Also used : HashMap(java.util.HashMap) CollectionSetVisitor(org.opennms.netmgt.collection.api.CollectionSetVisitor) MockDataCollectionConfig(org.opennms.netmgt.mock.MockDataCollectionConfig) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) RrdPersisterFactory(org.opennms.netmgt.collection.persistence.rrd.RrdPersisterFactory) RrdDataSource(org.opennms.netmgt.rrd.RrdDataSource) MockPlatformTransactionManager(org.opennms.core.test.MockPlatformTransactionManager) CollectionSetVisitorWrapper(org.opennms.netmgt.collection.support.CollectionSetVisitorWrapper) SnmpResult(org.opennms.netmgt.snmp.SnmpResult) OnmsNode(org.opennms.netmgt.model.OnmsNode) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AttributeGroupType(org.opennms.netmgt.collection.api.AttributeGroupType) MibObject(org.opennms.netmgt.config.datacollection.MibObject) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) MibObject(org.opennms.netmgt.config.datacollection.MibObject) Ignore(org.junit.Ignore)

Example 9 with RrdPersisterFactory

use of org.opennms.netmgt.collection.persistence.rrd.RrdPersisterFactory in project opennms by OpenNMS.

the class HttpDataCollectionIT method setUp.

/**
 * Sets the up.
 *
 * @throws Exception the exception
 */
@Before
public void setUp() throws Exception {
    MockLogAppender.setupLogging();
    DefaultDataCollectionConfigDao dao = new DefaultDataCollectionConfigDao();
    dao.setConfigDirectory("src/test/resources/etc/datacollection");
    dao.setConfigResource(new FileSystemResource("src/test/resources/etc/datacollection-config.xml"));
    dao.afterPropertiesSet();
    DataCollectionConfigFactory.setInstance(dao);
    m_rrdStrategy = new JRobinRrdStrategy();
    m_resourceStorageDao = new FilesystemResourceStorageDao();
    m_resourceStorageDao.setRrdDirectory(m_temporaryFolder.getRoot());
    m_temporaryFolder.newFolder("snmp");
    m_persisterFactory = new RrdPersisterFactory();
    m_persisterFactory.setResourceStorageDao(m_resourceStorageDao);
    m_persisterFactory.setRrdStrategy(m_rrdStrategy);
    m_collectionAgent = new MockCollectionAgent(1, "mynode.local", InetAddrUtils.addr("127.0.0.1"));
    m_nodeDao = EasyMock.createMock(NodeDao.class);
    OnmsNode node = new OnmsNode();
    node.setId(1);
    node.setLabel("mynode.local");
    node.setAssetRecord(new OnmsAssetRecord());
    EasyMock.expect(m_nodeDao.get(1)).andReturn(node).anyTimes();
    EasyMock.replay(m_nodeDao);
}
Also used : NodeDao(org.opennms.netmgt.dao.api.NodeDao) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAssetRecord(org.opennms.netmgt.model.OnmsAssetRecord) FilesystemResourceStorageDao(org.opennms.netmgt.dao.support.FilesystemResourceStorageDao) RrdPersisterFactory(org.opennms.netmgt.collection.persistence.rrd.RrdPersisterFactory) MockCollectionAgent(org.opennms.core.collection.test.MockCollectionAgent) FileSystemResource(org.springframework.core.io.FileSystemResource) JRobinRrdStrategy(org.opennms.netmgt.rrd.jrobin.JRobinRrdStrategy) DefaultDataCollectionConfigDao(org.opennms.netmgt.config.DefaultDataCollectionConfigDao) Before(org.junit.Before)

Example 10 with RrdPersisterFactory

use of org.opennms.netmgt.collection.persistence.rrd.RrdPersisterFactory in project opennms by OpenNMS.

the class NodeLevelDataOnMultipleNodesTest method setUp.

/**
 * Sets the up.
 *
 * @throws Exception the exception
 */
@Before
public void setUp() throws Exception {
    MockLogAppender.setupLogging();
    m_rrdStrategy = getRrdStrategy();
    m_resourceStorageDao = new FilesystemResourceStorageDao();
    m_resourceStorageDao.setRrdDirectory(m_temporaryFolder.getRoot());
    m_temporaryFolder.newFolder("snmp");
    m_persisterFactory = new RrdPersisterFactory();
    m_persisterFactory.setResourceStorageDao(m_resourceStorageDao);
    m_persisterFactory.setRrdStrategy(m_rrdStrategy);
    m_eventProxy = EasyMock.createMock(EventProxy.class);
    m_xmlCollectionDao = new XmlDataCollectionConfigDaoJaxb();
    Resource resource = new FileSystemResource(getXmlConfigFileName());
    m_xmlCollectionDao.setConfigResource(resource);
    m_xmlCollectionDao.afterPropertiesSet();
    m_collector = new XmlCollector();
    m_collector.setXmlCollectionDao(m_xmlCollectionDao);
    EasyMock.replay(m_eventProxy);
}
Also used : FilesystemResourceStorageDao(org.opennms.netmgt.dao.support.FilesystemResourceStorageDao) Resource(org.springframework.core.io.Resource) FileSystemResource(org.springframework.core.io.FileSystemResource) RrdPersisterFactory(org.opennms.netmgt.collection.persistence.rrd.RrdPersisterFactory) FileSystemResource(org.springframework.core.io.FileSystemResource) XmlDataCollectionConfigDaoJaxb(org.opennms.protocols.xml.dao.jaxb.XmlDataCollectionConfigDaoJaxb) EventProxy(org.opennms.netmgt.events.api.EventProxy) Before(org.junit.Before)

Aggregations

RrdPersisterFactory (org.opennms.netmgt.collection.persistence.rrd.RrdPersisterFactory)10 FilesystemResourceStorageDao (org.opennms.netmgt.dao.support.FilesystemResourceStorageDao)6 Before (org.junit.Before)5 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)4 JRobinRrdStrategy (org.opennms.netmgt.rrd.jrobin.JRobinRrdStrategy)4 FileSystemResource (org.springframework.core.io.FileSystemResource)4 MockCollectionAgent (org.opennms.core.collection.test.MockCollectionAgent)3 CollectionSetVisitor (org.opennms.netmgt.collection.api.CollectionSetVisitor)3 OnmsNode (org.opennms.netmgt.model.OnmsNode)3 RrdRepository (org.opennms.netmgt.rrd.RrdRepository)3 HashMap (java.util.HashMap)2 DefaultDataCollectionConfigDao (org.opennms.netmgt.config.DefaultDataCollectionConfigDao)2 NodeDao (org.opennms.netmgt.dao.api.NodeDao)2 EventProxy (org.opennms.netmgt.events.api.EventProxy)2 OnmsAssetRecord (org.opennms.netmgt.model.OnmsAssetRecord)2 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)2 XmlDataCollectionConfigDaoJaxb (org.opennms.protocols.xml.dao.jaxb.XmlDataCollectionConfigDaoJaxb)2 Resource (org.springframework.core.io.Resource)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Ignore (org.junit.Ignore)1