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