use of org.opennms.netmgt.model.OnmsSnmpInterface in project opennms by OpenNMS.
the class PollContextIT method testCriterias.
/*
* This test has been designed to verify the workaround for using the IP address on the SNMP
* Interface based Criteria, because in 1.8, the ipaddr was a valid column of the snmpinterface
* table, and that column has been removed in order to promote the usage of the ipinterface table.
*/
@Test
public void testCriterias() throws Exception {
Assert.assertNotNull(m_pollContext);
OnmsNode node = m_nodeDao.findByForeignId("linkd", "cisco2691");
Assert.assertNotNull(node);
List<OnmsIpInterface> ipInterfaces = m_pollContext.getPollableNodes();
Assert.assertNotNull(ipInterfaces);
Assert.assertEquals(2, ipInterfaces.size());
// Primary Interface
ipInterfaces = m_pollContext.getPollableNodesByIp("10.1.4.2");
Assert.assertNotNull(ipInterfaces);
Assert.assertEquals(1, ipInterfaces.size());
// Secondary Interface
ipInterfaces = m_pollContext.getPollableNodesByIp("10.1.5.1");
Assert.assertNotNull(ipInterfaces);
Assert.assertEquals(0, ipInterfaces.size());
// Because the criteria is an SQL restriction, the access to ipinterface table is through the
// internal alias created by hibernate, in this case ipinterfac1_.
String criteria = "snmpifdescr like '%Ethernet%' and ipinterfac1_.ipaddr like '10.1.5.%'";
List<OnmsSnmpInterface> snmpInterfaces = m_pollContext.get(node.getId(), criteria);
Assert.assertNotNull(snmpInterfaces);
Assert.assertEquals(1, snmpInterfaces.size());
}
use of org.opennms.netmgt.model.OnmsSnmpInterface 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.model.OnmsSnmpInterface in project opennms by OpenNMS.
the class InsAbstractSession method getIfAlias.
/**
* @param nodeid
* @param ifindex
* @return
*/
protected String getIfAlias(final int nodeid, final int ifindex) {
LOG.debug("getting ifalias for nodeid: {} and ifindex: {}", nodeid, ifindex);
setCriteria("nodeid = " + nodeid + " AND snmpifindex = " + ifindex);
BeanFactoryReference bf = BeanUtils.getBeanFactory("daoContext");
final SnmpInterfaceDao snmpInterfaceDao = BeanUtils.getBean(bf, "snmpInterfaceDao", SnmpInterfaceDao.class);
final TransactionTemplate transTemplate = BeanUtils.getBean(bf, "transactionTemplate", TransactionTemplate.class);
final OnmsSnmpInterface iface = transTemplate.execute(new TransactionCallback<OnmsSnmpInterface>() {
public OnmsSnmpInterface doInTransaction(final TransactionStatus status) {
return snmpInterfaceDao.findByNodeIdAndIfIndex(nodeid, ifindex);
}
});
if (iface == null) {
return "-1";
} else {
final String ifAlias = iface.getIfAlias();
LOG.debug("ifalias found: {}", ifAlias);
return ifAlias;
}
}
use of org.opennms.netmgt.model.OnmsSnmpInterface in project opennms by OpenNMS.
the class SnmpCollectorITCase method createAgent.
protected void createAgent(int ifIndex, PrimaryType ifCollType) {
m_node = new OnmsNode();
m_node.setSysObjectId(".1.2.3.4.5.6.7");
OnmsSnmpInterface snmpIface = new OnmsSnmpInterface(m_node, ifIndex);
m_iface = new OnmsIpInterface();
m_iface.setId(123);
m_iface.setIpAddress(myLocalHost());
m_iface.setIsSnmpPrimary(ifCollType);
m_iface.setSnmpInterface(snmpIface);
m_node.addIpInterface(m_iface);
EasyMock.expect(m_ifaceDao.load(m_iface.getId())).andReturn(m_iface).anyTimes();
m_easyMockUtils.replayAll();
m_agent = DefaultCollectionAgent.create(m_iface.getId(), m_ifaceDao, new MockPlatformTransactionManager());
}
use of org.opennms.netmgt.model.OnmsSnmpInterface in project opennms by OpenNMS.
the class SnmpIfCollectorIT method createSnmpInterface.
private OnmsEntity createSnmpInterface(final int ifIndex, final int ifType, final String ifName, final boolean collectionEnabled) {
final OnmsSnmpInterface m_snmpIface = new OnmsSnmpInterface();
m_snmpIface.setIfIndex(ifIndex);
m_snmpIface.setIfType(ifType);
m_snmpIface.setIfName(ifName);
m_snmpIface.setCollectionEnabled(collectionEnabled);
m_node.addSnmpInterface(m_snmpIface);
return m_snmpIface;
}
Aggregations