use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class NetworkElementFactory method getInterfaceArray.
private Interface[] getInterfaceArray(List<OnmsIpInterface> ipIfaces) {
List<Interface> intfs = new LinkedList<>();
for (OnmsIpInterface iface : ipIfaces) {
intfs.add(new Interface(iface));
}
Collections.sort(intfs, INTERFACE_COMPARATOR);
return intfs.toArray(new Interface[intfs.size()]);
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class EnLinkdElementFactory method getNodeLinks.
@Override
public Collection<NodeLinkBridge> getNodeLinks(int nodeId) {
Map<String, Set<InetAddress>> mactoIpMap = new HashMap<String, Set<InetAddress>>();
for (OnmsIpInterface ip : m_ipInterfaceDao.findByNodeId(nodeId)) {
for (IpNetToMedia ipnetomedia : m_ipNetToMediaDao.findByNetAddress(ip.getIpAddress())) {
if (!mactoIpMap.containsKey(ipnetomedia.getPhysAddress()))
mactoIpMap.put(ipnetomedia.getPhysAddress(), new HashSet<InetAddress>());
mactoIpMap.get(ipnetomedia.getPhysAddress()).add(ip.getIpAddress());
}
}
List<NodeLinkBridge> nodelinks = new ArrayList<NodeLinkBridge>();
for (String mac : mactoIpMap.keySet()) {
SharedSegment segment = m_bridgetopologyDao.getHostSharedSegment(mac);
if (segment.isEmpty())
continue;
if (!segment.containsMac(mac))
continue;
nodelinks.add(convertFromModel(mac, segment, getNodePortString(mactoIpMap.get(mac), mac)));
}
Collections.sort(nodelinks);
return nodelinks;
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class Collectd method handleReinitializePrimarySnmpInterface.
/**
* Process the event. This event is generated when a managed node which
* supports SNMP gains a new interface. In this situation the
* CollectableService object representing the primary SNMP interface of
* the node must be reinitialized. The CollectableService object
* associated with the primary SNMP interface for the node will be marked
* for reinitialization. Reinitializing the CollectableService object
* consists of calling the ServiceCollector.release() method followed by
* the ServiceCollector.initialize() method which will refresh attributes
* such as the interface key list and number of interfaces (both of which
* most likely have changed). Reinitialization will take place the next
* time the CollectableService is popped from an interval queue for
* collection. If any errors occur scheduling the service no error is
* returned.
*
* @param event
* The event to process.
* @throws InsufficientInformationException
*/
private void handleReinitializePrimarySnmpInterface(Event event) throws InsufficientInformationException {
EventUtils.checkNodeId(event);
EventUtils.checkInterface(event);
Long nodeid = event.getNodeid();
String ipAddress = event.getInterface();
// Mark the primary SNMP interface for reinitialization in
// order to update any modified attributes associated with
// the collectable service..
//
// Iterate over the CollectableService objects in the
// updates map and mark any which have the same interface
// address for reinitialization
//
OnmsIpInterface iface = null;
synchronized (getCollectableServices()) {
Iterator<CollectableService> iter = getCollectableServices().iterator();
while (iter.hasNext()) {
CollectableService cSvc = iter.next();
final InetAddress addr = (InetAddress) cSvc.getAddress();
final String addrString = str(addr);
LOG.debug("Comparing CollectableService ip address = {} and event ip interface = {}", addrString, ipAddress);
if (addrString != null && addrString.equals(ipAddress) && cSvc.getNodeId() == nodeid.intValue()) {
synchronized (cSvc) {
if (iface == null) {
iface = getIpInterface(nodeid.intValue(), ipAddress);
}
// Got a match! Retrieve the CollectorUpdates object
// associated
// with this CollectableService.
CollectorUpdates updates = cSvc.getCollectorUpdates();
// Now set the reinitialization flag
updates.markForReinitialization(iface);
LOG.debug("reinitializePrimarySnmpInterfaceHandler: marking {} for reinitialization for service SNMP.", ipAddress);
}
}
}
}
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class DefaultProvisionService method addMonitoredService.
/**
* {@inheritDoc}
*/
@Transactional
@Override
public OnmsMonitoredService addMonitoredService(final Integer nodeId, final String ipAddress, final String svcName) {
final OnmsIpInterface iface = m_ipInterfaceDao.findByNodeIdAndIpAddress(nodeId, ipAddress);
assertNotNull(iface, "could not find interface with nodeid %d and ipAddr %s", nodeId, ipAddress);
return addMonitoredService(iface, svcName);
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class ForceRescanScan method scanExistingNode.
/**
* <p>scanExistingNode</p>
*
* @param phase a {@link org.opennms.core.tasks.BatchTask} object.
*/
protected void scanExistingNode(final BatchTask phase) {
LOG.info("Attempting to re-scan node with Id {}", m_nodeId);
final OnmsNode node = m_provisionService.getNode(m_nodeId);
if (node != null) {
OnmsIpInterface iface = m_provisionService.getPrimaryInterfaceForNode(node);
if (iface == null) {
// NMS-6380, a discovered node added with wrong SNMP settings doesn't have a primary interface yet.
iface = node.getIpInterfaces().isEmpty() ? null : node.getIpInterfaces().iterator().next();
} else {
LOG.info("The node with ID OP does not have a primary interface", m_nodeId);
}
if (iface == null) {
LOG.info("The node with ID {} does not have any IP addresses", m_nodeId);
} else {
phase.getBuilder().addSequence(new NodeInfoScan(node, iface.getIpAddress(), node.getForeignSource(), node.getLocation(), createScanProgress(), m_agentConfigFactory, m_provisionService, node.getId()), new IpInterfaceScan(node.getId(), iface.getIpAddress(), node.getForeignSource(), node.getLocation(), m_provisionService), new NodeScan(node.getId(), node.getForeignSource(), node.getForeignId(), node.getLocation(), m_provisionService, m_eventForwarder, m_agentConfigFactory, m_taskCoordinator));
}
} else {
LOG.info("Can't find node with ID {}", m_nodeId);
}
}
Aggregations