use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class ScanManager method updateSnmpData.
void updateSnmpData(final OnmsNode node) {
try {
m_systemGroup = new SystemGroup(m_address);
final Set<SnmpInstId> ipAddrs = new TreeSet<>();
final Set<InetAddress> ipAddresses = new HashSet<>();
for (final OnmsIpInterface iface : node.getIpInterfaces()) {
final InetAddress addr = iface.getIpAddress();
if (addr != null && addr instanceof Inet4Address) {
ipAddrs.add(new SnmpInstId(InetAddressUtils.toOid(addr)));
}
ipAddresses.add(addr);
}
m_ipAddrTable = new IpAddrTable(m_address, ipAddrs);
m_ipAddressTable = IpAddressTable.createTable(m_address, ipAddresses);
AggregateTracker tracker = new AggregateTracker(Lists.newArrayList(m_systemGroup, m_ipAddrTable, m_ipAddressTable));
final SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(m_address, MonitoringLocationUtils.getLocationNameOrNullIfDefault(node));
try {
m_locationAwareSnmpClient.walk(agentConfig, tracker).withDescription("system/ipAddrTable/ipAddressTable").withLocation(node.getLocation() == null ? null : node.getLocation().getLocationName()).execute().get();
} catch (ExecutionException e) {
// pass
}
final Set<SnmpInstId> ifIndices = new TreeSet<>();
for (final Integer ifIndex : m_ipAddrTable.getIfIndices()) {
ifIndices.add(new SnmpInstId(ifIndex));
}
m_ifTable = new IfTable(m_address, ifIndices);
m_ifXTable = new IfXTable(m_address, ifIndices);
tracker = new AggregateTracker(Lists.newArrayList(m_systemGroup, m_ifTable, m_ifXTable));
try {
m_locationAwareSnmpClient.walk(agentConfig, tracker).withDescription("ifTable/ifXTable").withLocation(node.getLocation() == null ? null : node.getLocation().getLocationName()).execute().get();
} catch (ExecutionException e) {
// pass
}
m_systemGroup.updateSnmpDataForNode(node);
for (final SnmpInstId ifIndex : ifIndices) {
m_ifTable.updateSnmpInterfaceData(node, ifIndex.toInt());
}
for (final SnmpInstId ifIndex : ifIndices) {
m_ifXTable.updateSnmpInterfaceData(node, ifIndex.toInt());
}
for (final SnmpInstId ipAddr : ipAddrs) {
m_ipAddrTable.updateIpInterfaceData(node, ipAddr.toString());
}
for (final InetAddress addr : ipAddresses) {
m_ipAddressTable.updateIpInterfaceData(node, InetAddressUtils.str(addr));
}
} catch (final InterruptedException e) {
LOG.info("thread interrupted while updating SNMP data", e);
Thread.currentThread().interrupt();
}
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class IpAddrTable method updateIpInterfaceData.
/**
* <p>updateIpInterfaceData</p>
*
* @param node a {@link org.opennms.netmgt.model.OnmsNode} object.
* @param ipAddr a {@link java.lang.String} object.
*/
public void updateIpInterfaceData(OnmsNode node, String ipAddr) {
OnmsIpInterface ipIf = node.getIpInterfaceByIpAddress(ipAddr);
if (ipIf == null) {
ipIf = new OnmsIpInterface(ipAddr, node);
}
InetAddress inetAddr = ipIf.getIpAddress();
Integer ifIndex = getIfIndex(inetAddr);
// if we've found an ifIndex for this interface
if (ifIndex != null) {
// first look to see if an snmpIf was created already
OnmsSnmpInterface snmpIf = node.getSnmpInterfaceWithIfIndex(ifIndex);
if (snmpIf == null) {
// if not then create one
snmpIf = new OnmsSnmpInterface(node, ifIndex);
}
final InetAddress mask = getNetMask(inetAddr);
if (mask != null) {
ipIf.setNetMask(mask);
}
snmpIf.setCollectionEnabled(true);
ipIf.setSnmpInterface(snmpIf);
}
ipIf.setIpHostName(ipAddr);
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class IpAddressTable method updateIpInterfaceData.
/**
* <p>updateIpInterfaceData</p>
*
* @param node a {@link org.opennms.netmgt.model.OnmsNode} object.
* @param ipAddr a {@link java.lang.String} object.
*/
public void updateIpInterfaceData(final OnmsNode node, final String ipAddr) {
OnmsIpInterface ipIf = node.getIpInterfaceByIpAddress(ipAddr);
if (ipIf == null) {
ipIf = new OnmsIpInterface(ipAddr, node);
}
final InetAddress inetAddr = ipIf.getIpAddress();
final Integer ifIndex = getIfIndex(inetAddr);
// if we've found an ifIndex for this interface
if (ifIndex != null) {
// first look to see if an snmpIf was created already
OnmsSnmpInterface snmpIf = node.getSnmpInterfaceWithIfIndex(ifIndex);
if (snmpIf == null) {
// if not then create one
snmpIf = new OnmsSnmpInterface(node, ifIndex);
}
final InetAddress mask = getNetMask(inetAddr);
if (mask != null) {
ipIf.setNetMask(mask);
}
snmpIf.setCollectionEnabled(true);
ipIf.setSnmpInterface(snmpIf);
}
ipIf.setIpHostName(ipAddr);
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class AddEventVisitor method createNodeGainedServiceEvent.
/**
* <p>createNodeGainedServiceEvent</p>
*
* @param monSvc a {@link org.opennms.netmgt.model.OnmsMonitoredService} object.
* @return a {@link org.opennms.netmgt.xml.event.Event} object.
*/
protected Event createNodeGainedServiceEvent(final OnmsMonitoredService monSvc) {
final OnmsIpInterface iface = monSvc.getIpInterface();
final OnmsNode node = iface.getNode();
LOG.debug("ipinterface = {}", iface);
LOG.debug("snmpinterface = {}", iface.getSnmpInterface());
LOG.debug("node = {}", node);
return EventUtils.createNodeGainedServiceEvent(m_eventSource, monSvc.getNodeId(), iface.getIpAddress(), monSvc.getServiceType().getName(), node.getLabel(), node.getLabelSource(), node.getSysName(), node.getSysDescription());
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class DefaultProvisionService method getPrimaryInterfaceForNode.
/**
* {@inheritDoc}
*/
@Transactional
@Override
public OnmsIpInterface getPrimaryInterfaceForNode(final OnmsNode node) {
final OnmsNode dbNode = getDbNode(node);
if (dbNode == null) {
return null;
} else {
final OnmsIpInterface primaryIface = dbNode.getPrimaryInterface();
if (primaryIface != null) {
m_ipInterfaceDao.initialize(primaryIface);
m_ipInterfaceDao.initialize(primaryIface.getMonitoredServices());
}
return primaryIface;
}
}
Aggregations