Search in sources :

Example 1 with InterfaceBuilder

use of org.opennms.netmgt.model.NetworkBuilder.InterfaceBuilder in project opennms by OpenNMS.

the class NetworkBuilderTest method testIpInterface.

@Test
public void testIpInterface() {
    final NetworkBuilder builder = new NetworkBuilder();
    builder.addNode("node1");
    final InterfaceBuilder ib = builder.addSnmpInterface(1).addIpInterface("192.168.1.1");
    final OnmsIpInterface iface = ib.getInterface();
    assertEquals(1, iface.getIfIndex().intValue());
}
Also used : InterfaceBuilder(org.opennms.netmgt.model.NetworkBuilder.InterfaceBuilder) Test(org.junit.Test)

Example 2 with InterfaceBuilder

use of org.opennms.netmgt.model.NetworkBuilder.InterfaceBuilder in project opennms by OpenNMS.

the class TcaCollectorIT method setUp.

/**
 * Sets the up.
 *
 * @throws Exception the exception
 */
@Before
public void setUp() throws Exception {
    MockLogAppender.setupLogging();
    m_tempFolder.newFolder("snmp");
    m_resourceStorageDao.setRrdDirectory(m_tempFolder.getRoot());
    OnmsIpInterface iface = null;
    OnmsNode testNode = null;
    Collection<OnmsNode> testNodes = m_nodeDao.findByLabel(TEST_NODE_LABEL);
    if (testNodes == null || testNodes.size() < 1) {
        NetworkBuilder builder = new NetworkBuilder();
        builder.addNode(TEST_NODE_LABEL).setId(1).setSysObjectId(".1.3.6.1.4.1.1588.2.1.1.1");
        InterfaceBuilder ifBldr = builder.addInterface(TEST_NODE_IP).setIsSnmpPrimary("P");
        ifBldr.addSnmpInterface(6).setIfName("fw0").setPhysAddr("44:33:22:11:00").setIfType(144).setCollectionEnabled(true);
        testNode = builder.getCurrentNode();
        Assert.assertNotNull(testNode);
        m_nodeDao.save(testNode);
        m_nodeDao.flush();
    } else {
        testNode = testNodes.iterator().next();
    }
    Set<OnmsIpInterface> ifaces = testNode.getIpInterfaces();
    Assert.assertEquals(1, ifaces.size());
    iface = ifaces.iterator().next();
    SnmpPeerFactory.setInstance(m_snmpPeerFactory);
    m_collectionAgent = DefaultSnmpCollectionAgent.create(iface.getId(), m_ipInterfaceDao, m_transactionManager);
    TcaRrd rrd = new TcaRrd();
    rrd.addRra("RRA:AVERAGE:0.5:1:3600");
    rrd.addRra("RRA:AVERAGE:0.5:300:288");
    rrd.addRra("RRA:MIN:0.5:300:288");
    rrd.addRra("RRA:MAX:0.5:300:288");
    rrd.addRra("RRA:AVERAGE:0.5:900:2880");
    rrd.addRra("RRA:MIN:0.5:900:2880");
    rrd.addRra("RRA:MAX:0.5:900:2880");
    rrd.addRra("RRA:AVERAGE:0.5:3600:4300");
    rrd.addRra("RRA:MIN:0.5:3600:4300");
    rrd.addRra("RRA:MAX:0.5:3600:4300");
    TcaDataCollection tcadc = new TcaDataCollection();
    tcadc.setName("default");
    tcadc.setRrd(rrd);
    TcaDataCollectionConfig tcadcc = new TcaDataCollectionConfig();
    tcadcc.addDataCollection(tcadc);
    tcadcc.setRrdRepository(getSnmpRoot().getAbsolutePath());
    EasyMock.expect(m_configDao.getConfig()).andReturn(tcadcc).atLeastOnce();
    EasyMock.replay(m_configDao);
    // Define the resource type
    ResourceType resourceType = getJuniperTcaEntryResourceType();
    m_resourceTypesDao = EasyMock.createMock(ResourceTypesDao.class);
    EasyMock.expect(m_resourceTypesDao.getResourceTypeByName(TcaCollectionHandler.RESOURCE_TYPE_NAME)).andReturn(resourceType).anyTimes();
    EasyMock.replay(m_resourceTypesDao);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) TcaRrd(org.opennms.netmgt.collectd.tca.config.TcaRrd) ResourceTypesDao(org.opennms.netmgt.config.api.ResourceTypesDao) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) InterfaceBuilder(org.opennms.netmgt.model.NetworkBuilder.InterfaceBuilder) TcaDataCollection(org.opennms.netmgt.collectd.tca.config.TcaDataCollection) TcaDataCollectionConfig(org.opennms.netmgt.collectd.tca.config.TcaDataCollectionConfig) Before(org.junit.Before)

Example 3 with InterfaceBuilder

use of org.opennms.netmgt.model.NetworkBuilder.InterfaceBuilder 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)

Example 4 with InterfaceBuilder

use of org.opennms.netmgt.model.NetworkBuilder.InterfaceBuilder in project opennms by OpenNMS.

the class SnmpCollectorMinMaxValIT method setUp.

@Before
public void setUp() throws Exception {
    final Properties p = new Properties();
    p.setProperty("log4j.logger.org.opennms.netmgt.snmp.SnmpUtils", "DEBUG");
    MockLogAppender.setupLogging(p);
    assertTrue(m_snmpPeerFactory instanceof ProxySnmpAgentConfigFactory);
    SnmpPeerFactory.setInstance(m_snmpPeerFactory);
    m_agentConfig = m_snmpPeerFactory.getAgentConfig(InetAddressUtils.addr(TEST_HOST_ADDRESS));
    m_rrdStrategy = new JRobinRrdStrategy();
    m_resourceStorageDao = new FilesystemResourceStorageDao();
    File snmpRrdDirectory = (File) m_context.getAttribute("rrdDirectory");
    m_resourceStorageDao.setRrdDirectory(snmpRrdDirectory.getParentFile());
    OnmsIpInterface iface = null;
    OnmsNode testNode = null;
    Collection<OnmsNode> testNodes = m_nodeDao.findByLabel(TEST_NODE_LABEL);
    if (testNodes == null || testNodes.size() < 1) {
        NetworkBuilder builder = new NetworkBuilder();
        builder.addNode(TEST_NODE_LABEL).setId(1).setSysObjectId(".1.3.6.1.4.1.1588.2.1.1.1");
        builder.addSnmpInterface(1).setIfName("lo0").setPhysAddr("00:11:22:33:44");
        builder.addSnmpInterface(2).setIfName("gif0").setPhysAddr("00:11:22:33:45").setIfType(55);
        builder.addSnmpInterface(3).setIfName("stf0").setPhysAddr("00:11:22:33:46").setIfType(57);
        InterfaceBuilder ifBldr = builder.addInterface(TEST_HOST_ADDRESS).setIsSnmpPrimary("P");
        ifBldr.addSnmpInterface(6).setIfName("fw0").setPhysAddr("44:33:22:11:00").setIfType(144).setCollectionEnabled(true);
        testNode = builder.getCurrentNode();
        assertNotNull(testNode);
        m_nodeDao.save(testNode);
        m_nodeDao.flush();
    } else {
        testNode = testNodes.iterator().next();
    }
    final Set<OnmsIpInterface> ifaces = testNode.getIpInterfaces();
    assertEquals(1, ifaces.size());
    iface = ifaces.iterator().next();
    LOG.debug("iface = {}", iface);
    final SnmpCollector collector = new SnmpCollector();
    collector.initialize();
    m_collectionSpecification = CollectorTestUtils.createCollectionSpec("SNMP", collector, "default");
    m_collectionAgent = DefaultSnmpCollectionAgent.create(iface.getId(), m_ipInterfaceDao, m_transactionManager);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) FilesystemResourceStorageDao(org.opennms.netmgt.dao.support.FilesystemResourceStorageDao) InterfaceBuilder(org.opennms.netmgt.model.NetworkBuilder.InterfaceBuilder) Properties(java.util.Properties) JRobinRrdStrategy(org.opennms.netmgt.rrd.jrobin.JRobinRrdStrategy) File(java.io.File) ProxySnmpAgentConfigFactory(org.opennms.core.test.snmp.ProxySnmpAgentConfigFactory) Before(org.junit.Before)

Aggregations

InterfaceBuilder (org.opennms.netmgt.model.NetworkBuilder.InterfaceBuilder)4 Before (org.junit.Before)3 NetworkBuilder (org.opennms.netmgt.model.NetworkBuilder)3 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)3 File (java.io.File)2 OnmsNode (org.opennms.netmgt.model.OnmsNode)2 Properties (java.util.Properties)1 Test (org.junit.Test)1 ProxySnmpAgentConfigFactory (org.opennms.core.test.snmp.ProxySnmpAgentConfigFactory)1 InsufficientInformationException (org.opennms.core.utils.InsufficientInformationException)1 TcaDataCollection (org.opennms.netmgt.collectd.tca.config.TcaDataCollection)1 TcaDataCollectionConfig (org.opennms.netmgt.collectd.tca.config.TcaDataCollectionConfig)1 TcaRrd (org.opennms.netmgt.collectd.tca.config.TcaRrd)1 DefaultServiceCollectorRegistry (org.opennms.netmgt.collection.support.DefaultServiceCollectorRegistry)1 CollectdConfigFactory (org.opennms.netmgt.config.CollectdConfigFactory)1 PollOutagesConfigFactory (org.opennms.netmgt.config.PollOutagesConfigFactory)1 ThresholdingConfigFactory (org.opennms.netmgt.config.ThresholdingConfigFactory)1 ResourceTypesDao (org.opennms.netmgt.config.api.ResourceTypesDao)1 CollectdConfiguration (org.opennms.netmgt.config.collectd.CollectdConfiguration)1 Collector (org.opennms.netmgt.config.collectd.Collector)1