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 = DefaultSnmpCollectionAgent.create(m_iface.getId(), m_ifaceDao, new MockPlatformTransactionManager());
}
use of org.opennms.netmgt.model.OnmsSnmpInterface in project opennms by OpenNMS.
the class PollableSnmpInterface method setSnmpinterfaces.
/**
* <p>setSnmpinterfaces</p>
*
* @param snmpinterfaces a {@link java.util.List} object.
*/
public void setSnmpinterfaces(List<OnmsSnmpInterface> snmpinterfaces) {
if (snmpinterfaces == null) {
LOG.debug("setting snmpinterfaces: got null, thread instantiated but at moment no interface found");
return;
}
// ifIndex -> operstatus
final Map<Integer, Integer> oldStatuses = new HashMap<Integer, Integer>();
for (final Integer ifIndex : m_snmpinterfaces.keySet()) {
final OnmsSnmpInterface iface = m_snmpinterfaces.get(ifIndex);
if (iface != null && iface.getIfOperStatus() != null) {
oldStatuses.put(ifIndex, iface.getIfOperStatus());
}
}
m_snmpinterfaces.clear();
for (OnmsSnmpInterface iface : snmpinterfaces) {
LOG.debug("setting snmpinterface:", iface.toString());
if (iface != null && iface.getIfIndex() != null && iface.getIfIndex() > 0) {
final Integer oldStatus = oldStatuses.get(iface.getIfIndex());
LOG.debug("setting snmpinterface (oldStatus={}):{}", oldStatus, iface.toString());
// Note: If OpenNMS is restarted, the event is going to be sent no matter if it was sent before, if the current status of the interface is down.
m_snmpinterfaces.put(iface.getIfIndex(), iface);
if (iface.getIfAdminStatus() != null && iface.getIfAdminStatus().equals(SnmpMinimalPollInterface.IF_UP) && iface.getIfOperStatus() != null && iface.getIfOperStatus().equals(SnmpMinimalPollInterface.IF_DOWN) && (oldStatus == null || (iface.getIfOperStatus().intValue() != oldStatus.intValue()))) {
sendOperDownEvent(iface);
}
}
}
}
use of org.opennms.netmgt.model.OnmsSnmpInterface in project opennms by OpenNMS.
the class DefaultSnmpCollectionAgentService method getSnmpInterfaces.
private Set<OnmsSnmpInterface> getSnmpInterfaces() {
OnmsNode node = getNode();
Set<OnmsSnmpInterface> snmpIfs = node.getSnmpInterfaces();
if (snmpIfs.size() == 0) {
LOG.debug("no known SNMP interfaces for node {}", node);
}
return snmpIfs;
}
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 OnmsSnmpInterfaceResource method getSnmpInterface.
/**
* <p>getSnmpInterface</p>
*
* @param nodeCriteria a {@link java.lang.String} object.
* @param ifIndex a int.
* @return a {@link org.opennms.netmgt.model.OnmsSnmpInterface} object.
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("{ifIndex}")
public OnmsSnmpInterface getSnmpInterface(@PathParam("nodeCriteria") final String nodeCriteria, @PathParam("ifIndex") final int ifIndex) {
final OnmsNode node = m_nodeDao.get(nodeCriteria);
if (node == null) {
throw getException(Status.BAD_REQUEST, "Node {} was not found.", nodeCriteria);
}
final OnmsSnmpInterface iface = node.getSnmpInterfaceWithIfIndex(ifIndex);
if (iface == null) {
throw getException(Status.NOT_FOUND, "SNMP Interface {} was not found on node {}.", Integer.toString(ifIndex), nodeCriteria);
}
return iface;
}
Aggregations