use of org.opennms.netmgt.mock.MockNetwork in project opennms by OpenNMS.
the class CollectionResourceWrapperIT method testInterfaceResource.
@Test
public void testInterfaceResource() throws Exception {
// Set Defaults
String ipAddress = "10.0.0.1";
String ifName = "eth0";
int ifIndex = 2;
// Initialize Database
MockNetwork network = new MockNetwork();
network.setCriticalService("ICMP");
network.addNode(1, "testNode");
network.addInterface(ipAddress);
network.setIfAlias(ifName);
network.setIfIndex(ifIndex);
network.addService("ICMP");
network.addService("SNMP");
network.addService("HTTP");
MockDatabase db = new MockDatabase();
db.populate(network);
DataSourceFactory.setInstance(db);
// Create Mock Collection Agent
SnmpCollectionAgent agent = createCollectionAgent();
// Create SnmpIfData
OnmsNode node = new OnmsNode();
node.setId(agent.getNodeId());
node.setLabel("testNode");
node.setForeignSource(agent.getForeignSource());
node.setForeignId(agent.getForeignId());
OnmsSnmpInterface snmpIface = new OnmsSnmpInterface(node, ifIndex);
snmpIface.setIfDescr(ifName);
snmpIface.setIfName(ifName);
snmpIface.setIfAlias(ifName);
snmpIface.setIfSpeed(10000000l);
snmpIface.setPhysAddr("001122334455");
SnmpIfData ifData = new SnmpIfData(snmpIface);
// Creating IfResourceType
MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig();
OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient);
IfResourceType resourceType = new IfResourceType(agent, collection);
// Creating Resource
SnmpCollectionResource resource = new IfInfo(resourceType, agent, ifData);
SnmpAttribute attribute = addAttributeToCollectionResource(resource, "ifInOctets", AttributeType.COUNTER, "ifIndex", "5000");
Map<String, CollectionAttribute> attributes = new HashMap<String, CollectionAttribute>();
attributes.put(attribute.getName(), attribute);
// Create Wrapper
CollectionResourceWrapper wrapper = createWrapper(resource, attributes);
// Validations
Assert.assertEquals(node.getId().intValue(), wrapper.getNodeId());
// Should be the address of the SNMP Agent (Bug 3808)
Assert.assertEquals("127.0.0.1", wrapper.getHostAddress());
Assert.assertEquals("eth0-001122334455", wrapper.getIfLabel());
Assert.assertEquals("if", wrapper.getResourceTypeName());
Assert.assertEquals("SNMP", wrapper.getServiceName());
Assert.assertEquals(true, wrapper.isAnInterfaceResource());
Assert.assertEquals(Integer.toString(ifIndex), wrapper.getInstance());
Assert.assertEquals(Integer.toString(ifIndex), wrapper.getIfIndex());
// IfLabel is called only once
Assert.assertEquals(Integer.toString(ifIndex), wrapper.getIfIndex());
// IfLabel is called only once
Assert.assertEquals(Integer.toString(ifIndex), wrapper.getIfIndex());
// IfLabel is called only once
Assert.assertEquals("eth0", wrapper.getIfInfoValue("snmpifname"));
Assert.assertEquals("eth0-001122334455", wrapper.getInstanceLabel());
Assert.assertEquals("nodeSource[JUnit:T001].interfaceSnmp[eth0-001122334455]", wrapper.getResourceId().toString());
}
use of org.opennms.netmgt.mock.MockNetwork in project opennms by OpenNMS.
the class LatencyThresholdingSetIT method setupSnmpInterfaceDatabase.
private void setupSnmpInterfaceDatabase(MockDatabase db, String ipAddress, String ifName) throws Exception {
MockNetwork network = new MockNetwork();
network.setCriticalService("ICMP");
network.addNode(1, "testNode");
network.addInterface(ipAddress);
network.setIfIndex(1);
if (ifName != null) {
network.setIfAlias(ifName);
}
network.addService("ICMP");
network.addService("SNMP");
network.addService("HTTP");
network.addPathOutage(1, InetAddressUtils.addr("192.168.1.1"), "ICMP");
db.populate(network);
assertEquals(new Integer(1), m_jdbcTemplate.queryForObject("select count(*) from node where nodeid = '1' and nodelabel = 'testNode'", Integer.class));
assertEquals(new Integer(1), m_jdbcTemplate.queryForObject("select count(*) from ipinterface where nodeid = '1' and ipaddr = '" + ipAddress + "'", Integer.class));
if (ifName == null) {
assertEquals(new Integer(1), m_jdbcTemplate.queryForObject("select count(*) from snmpInterface where id = '1' and nodeid = '1' and snmpifIndex = '1'", Integer.class));
} else {
assertEquals(new Integer(1), m_jdbcTemplate.queryForObject("select count(*) from snmpInterface where id = '1' and nodeid = '1' and snmpifIndex = '1' and snmpifalias = '" + ifName + "' and snmpifdescr = '" + ifName + "'", Integer.class));
}
}
use of org.opennms.netmgt.mock.MockNetwork in project opennms by OpenNMS.
the class CategoryModelIT method setUp.
//
// SetUp and TearDown
//
@Before
public void setUp() throws Exception {
MockUtil.println("------------ Begin Test --------------------------");
MockLogAppender.setupLogging();
m_network = new MockNetwork();
m_network.setCriticalService("ICMP");
m_network.addNode(1, "Router");
m_network.addInterface("192.168.1.1");
m_network.addService("ICMP");
m_network.addPathOutage(1, InetAddressUtils.addr("192.168.1.1"), "ICMP");
m_network.addService("SMTP");
m_network.addService("SNMP");
m_network.addInterface("192.168.1.2");
m_network.addService("ICMP");
m_network.addService("SMTP");
m_network.addNode(2, "Server");
m_network.addInterface("192.168.1.3");
m_network.addService("ICMP");
m_network.addService("HTTP");
m_network.addService("SMTP");
m_network.addService("SNMP");
m_network.addNode(3, "Firewall");
m_network.addInterface("192.168.1.4");
m_network.addService("SMTP");
m_network.addPathOutage(3, InetAddressUtils.addr("192.168.1.4"), "SMTP");
m_network.addService("HTTP");
m_network.addInterface("192.168.1.5");
m_network.addService("SMTP");
m_network.addService("HTTP");
m_network.addNode(4, "DownNode");
m_network.addInterface("192.168.1.6");
m_network.addService("SNMP");
m_db.populate(m_network);
DataSourceFactory.setInstance(m_db);
}
use of org.opennms.netmgt.mock.MockNetwork in project opennms by OpenNMS.
the class SyslogdConfigFactoryIT method setUp.
@Before
public void setUp() throws Exception {
DaoTestConfigBean daoTestConfig = new DaoTestConfigBean();
daoTestConfig.setRelativeHomeDirectory("src/test/resources");
daoTestConfig.afterPropertiesSet();
MockNetwork network = new MockNetwork();
MockDatabase db = new MockDatabase();
db.populate(network);
DataSourceFactory.setInstance(db);
m_factory = new SyslogdConfigFactory(ConfigurationTestUtils.getInputStreamForResource(this, "/etc/syslogd-configuration.xml"));
}
use of org.opennms.netmgt.mock.MockNetwork in project opennms by OpenNMS.
the class PollContextIT method setUp.
@Before
public void setUp() throws Exception {
MockLogAppender.setupLogging();
m_mNetwork = new MockNetwork();
m_mNetwork.addNode(1, "Router");
m_mNetwork.addInterface("192.168.1.1");
m_mNetwork.addService("ICMP");
m_mNetwork.addService("SMTP");
m_mNetwork.addInterface("192.168.1.2");
m_mNetwork.addService("ICMP");
m_mNetwork.addService("SMTP");
m_mNetwork.addNode(2, "Server");
m_mNetwork.addInterface("192.168.1.3");
m_mNetwork.addService("ICMP");
m_mNetwork.addService("HTTP");
m_mNetwork.addNode(3, "Firewall");
m_mNetwork.addInterface("192.168.1.4");
m_mNetwork.addService("SMTP");
m_mNetwork.addService("HTTP");
m_mNetwork.addInterface("192.168.1.5");
m_mNetwork.addService("SMTP");
m_mNetwork.addService("HTTP");
m_mSvc = m_mNetwork.getService(1, "192.168.1.1", "ICMP");
m_db.populate(m_mNetwork);
m_pollerConfig = new MockPollerConfig(m_mNetwork);
m_pollerConfig.setNodeOutageProcessingEnabled(true);
m_pollerConfig.setCriticalService("ICMP");
m_pollerConfig.addPackage("TestPackage");
m_pollerConfig.addDowntime(1000L, 0L, -1L, false);
m_pollerConfig.setDefaultPollInterval(1000L);
m_pollerConfig.populatePackage(m_mNetwork);
m_pollerConfig.addPackage("TestPkg2");
m_pollerConfig.addDowntime(1000L, 0L, -1L, false);
m_pollerConfig.setDefaultPollInterval(2000L);
m_pollerConfig.addService(m_mNetwork.getService(2, "192.168.1.3", "HTTP"));
m_pollerConfig.setNextOutageIdSql(m_db.getNextOutageIdStatement());
m_outageAnticipator = new OutageAnticipator(m_db);
m_eventMgr = new MockEventIpcManager();
m_eventMgr.setEventWriter(m_db);
m_eventMgr.addEventListener(m_outageAnticipator);
m_locationAwarePingClient = mock(LocationAwarePingClient.class);
m_pollContext = new DefaultPollContext();
m_pollContext.setEventManager(m_eventMgr);
m_pollContext.setLocalHostName("localhost");
m_pollContext.setName("PollContextTest.DefaultPollContext");
m_pollContext.setPollerConfig(m_pollerConfig);
m_pollContext.setQueryManager(m_queryManager);
m_pollContext.setLocationAwarePingClient(m_locationAwarePingClient);
m_pNetwork = new PollableNetwork(m_pollContext);
m_pSvc = m_pNetwork.createService(1, "Router", null, InetAddressUtils.addr("192.168.1.1"), "ICMP");
}
Aggregations