use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.
the class MonitoringLocationListCellRenderer method getListCellRendererComponent.
/**
* {@inheritDoc}
*/
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
OnmsMonitoringLocation location = (OnmsMonitoringLocation) value;
final StringBuilder stringValue = new StringBuilder();
if (location != null) {
stringValue.append(location.getMonitoringArea());
stringValue.append(" - ");
stringValue.append(location.getLocationName());
} else {
stringValue.append("[null]");
}
return super.getListCellRendererComponent(list, stringValue.toString(), index, isSelected, cellHasFocus);
}
use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.
the class DefaultPollerBackEnd method registerLocationMonitor.
/**
* {@inheritDoc}
*/
@Override
public String registerLocationMonitor(final String monitoringLocationId) {
final OnmsMonitoringLocation def = m_monitoringLocationDao.get(monitoringLocationId);
if (def == null) {
throw new ObjectRetrievalFailureException(OnmsMonitoringLocation.class, monitoringLocationId, "Location monitor definition with the id '" + monitoringLocationId + "' not found", null);
}
final OnmsLocationMonitor mon = new OnmsLocationMonitor();
mon.setId(UUID.randomUUID().toString());
mon.setLocation(def.getLocationName());
mon.setStatus(MonitorStatus.REGISTERED);
m_locMonDao.save(mon);
sendMonitorRegisteredEvent(mon);
return mon.getId();
}
use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.
the class SnmpHardwareInventoryProvisioningAdapter method synchronizeInventory.
/**
* Synchronize inventory.
* <p>Obtain the ENTITY-MIB and vendor attributes from the target node through SNMP.</p>
* <p>If the node has a hardware inventory data on the database, this is going to be overridden only,
* if the gathered data differs from the data at the database, otherwise the gathered data will be
* discarded.</p>
*
* @param nodeId the node id
*/
private void synchronizeInventory(int nodeId) {
final OnmsNode node = m_nodeDao.get(nodeId);
if (node == null) {
throw new ProvisioningAdapterException("Failed to return node for given nodeId: " + nodeId);
}
final OnmsIpInterface intf = node.getPrimaryInterface();
if (intf == null) {
throw new ProvisioningAdapterException("Can't find the SNMP Primary IP address for nodeId: " + nodeId);
}
final InetAddress ipAddress = intf.getIpAddress();
EventBuilder ebldr = null;
try {
if (node.getSysObjectId() == null) {
LOG.warn("Skiping hardware discover because the node {} doesn't support SNMP", nodeId);
return;
}
OnmsMonitoringLocation location = node.getLocation();
String locationName = (location == null) ? null : location.getLocationName();
SnmpAgentConfig agentConfig = m_snmpConfigDao.getAgentConfig(ipAddress, locationName);
final OnmsHwEntity newRoot = getRootEntity(agentConfig, node);
newRoot.setNode(node);
final OnmsHwEntity currentRoot = m_hwEntityDao.findRootByNodeId(node.getId());
if (newRoot.equals(currentRoot)) {
LOG.info("No changes detected on the hardware inventory for nodeId {}", nodeId);
return;
}
if (currentRoot == null) {
LOG.info("Saving hardware inventory for nodeId {}", nodeId);
} else {
LOG.info("Updating hardware inventory for nodeId {}", nodeId);
m_hwEntityDao.delete(currentRoot);
m_hwEntityDao.flush();
}
m_hwEntityDao.saveOrUpdate(newRoot);
ebldr = new EventBuilder(EventConstants.HARDWARE_INVENTORY_SUCCESSFUL_UEI, PREFIX + NAME);
} catch (Throwable e) {
ebldr = new EventBuilder(EventConstants.HARDWARE_INVENTORY_FAILED_UEI, PREFIX + NAME);
ebldr.addParam(EventConstants.PARM_REASON, e.getMessage());
}
if (ebldr != null) {
ebldr.setNodeid(nodeId);
ebldr.setInterface(ipAddress);
getEventForwarder().sendNow(ebldr.getEvent());
}
}
use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.
the class DefaultProvisionService method createUndiscoveredNode.
/**
* {@inheritDoc}
*/
@Transactional
@Override
public OnmsNode createUndiscoveredNode(final String ipAddress, final String foreignSource, final String locationString) {
final String effectiveForeignSource = foreignSource == null ? FOREIGN_SOURCE_FOR_DISCOVERED_NODES : foreignSource;
final String effectiveLocationName = MonitoringLocationUtils.isDefaultLocationName(locationString) ? null : locationString;
final OnmsNode node = new UpsertTemplate<OnmsNode, NodeDao>(m_transactionManager, m_nodeDao) {
@Override
protected OnmsNode query() {
// Find all of the nodes in the target requisition with the given IP address
return m_nodeDao.findByForeignSourceAndIpAddress(effectiveForeignSource, ipAddress).stream().filter(n -> {
// Now filter the nodes by location
final String existingLocationName = MonitoringLocationUtils.getLocationNameOrNullIfDefault(n);
return Objects.equals(existingLocationName, effectiveLocationName);
}).findFirst().orElse(null);
}
@Override
protected OnmsNode doUpdate(OnmsNode existingNode) {
// we found an existing node so exit by returning null;
return null;
}
@Override
protected OnmsNode doInsert() {
final Date now = new Date();
OnmsMonitoringLocation location = createLocationIfNecessary(locationString);
// Associate the location with the node
final OnmsNode node = new OnmsNode(location);
final String hostname = getHostnameResolver().getHostname(addr(ipAddress), locationString);
if (hostname == null || ipAddress.equals(hostname)) {
node.setLabel(ipAddress);
node.setLabelSource(NodeLabelSource.ADDRESS);
} else {
node.setLabel(hostname);
node.setLabelSource(NodeLabelSource.HOSTNAME);
}
node.setForeignSource(effectiveForeignSource);
node.setType(NodeType.ACTIVE);
node.setLastCapsdPoll(now);
final OnmsIpInterface iface = new OnmsIpInterface(InetAddressUtils.addr(ipAddress), node);
iface.setIsManaged("M");
iface.setIpHostName(hostname);
iface.setIsSnmpPrimary(PrimaryType.NOT_ELIGIBLE);
iface.setIpLastCapsdPoll(now);
m_nodeDao.save(node);
m_nodeDao.flush();
return node;
}
}.execute();
if (node != null) {
if (effectiveForeignSource != null) {
node.setForeignId(node.getNodeId());
createUpdateRequistion(ipAddress, node, effectiveLocationName, effectiveForeignSource);
}
// we do this here rather than in the doInsert method because
// the doInsert may abort
node.visit(new AddEventVisitor(m_eventForwarder));
}
return node;
}
use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.
the class EnLinkdIT method testLoadFourLevelTopology.
/*
* 1400=
* [1544, 1534]
* 1534=
* [1364, 405, 1310]}
* 1364=
* [2965, 5022]
*/
@Test
public void testLoadFourLevelTopology() {
final OnmsMonitoringLocation location = new OnmsMonitoringLocation(MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID, MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID);
OnmsNode lnode1400 = new OnmsNode();
lnode1400.setId(1400);
lnode1400.setForeignSource("linkd");
lnode1400.setForeignId("lnode1400");
lnode1400.setLabel("lnode1400");
lnode1400.setLocation(location);
OnmsNode lnode1544 = new OnmsNode();
lnode1544.setId(1544);
lnode1544.setForeignSource("linkd");
lnode1544.setForeignId("lnode1544");
lnode1544.setLabel("lnode1544");
lnode1544.setLocation(location);
OnmsNode lnode1534 = new OnmsNode();
lnode1534.setId(1534);
lnode1534.setForeignSource("linkd");
lnode1534.setForeignId("lnode1534");
lnode1534.setLabel("lnode1534");
lnode1534.setLocation(location);
OnmsNode lnode1364 = new OnmsNode();
lnode1364.setId(1364);
lnode1364.setForeignSource("linkd");
lnode1364.setForeignId("lnode1364");
lnode1364.setLabel("lnode1364");
lnode1364.setLocation(location);
OnmsNode lnode1310 = new OnmsNode();
lnode1310.setId(1310);
lnode1310.setForeignSource("linkd");
lnode1310.setForeignId("lnode1310");
lnode1310.setLabel("lnode1310");
lnode1310.setLocation(location);
OnmsNode lnode405 = new OnmsNode();
lnode405.setId(405);
lnode405.setForeignSource("linkd");
lnode405.setForeignId("lnode405");
lnode405.setLabel("lnode405");
lnode405.setLocation(location);
OnmsNode lnode2965 = new OnmsNode();
lnode2965.setId(2965);
lnode2965.setForeignSource("linkd");
lnode2965.setForeignId("lnode2965");
lnode2965.setLabel("lnode2965");
lnode2965.setLocation(location);
OnmsNode lnode5022 = new OnmsNode();
lnode5022.setId(5022);
lnode5022.setForeignSource("linkd");
lnode5022.setForeignId("lnode5022");
lnode5022.setLabel("lnode5022");
lnode5022.setLocation(location);
m_nodeDao.save(lnode1400);
m_nodeDao.save(lnode1544);
m_nodeDao.save(lnode1534);
m_nodeDao.save(lnode1364);
m_nodeDao.save(lnode1310);
m_nodeDao.save(lnode405);
m_nodeDao.save(lnode2965);
m_nodeDao.save(lnode5022);
OnmsNode node1400 = m_nodeDao.findByForeignId("linkd", "lnode1400");
OnmsNode node1544 = m_nodeDao.findByForeignId("linkd", "lnode1544");
OnmsNode node1534 = m_nodeDao.findByForeignId("linkd", "lnode1534");
OnmsNode node1364 = m_nodeDao.findByForeignId("linkd", "lnode1364");
OnmsNode node1310 = m_nodeDao.findByForeignId("linkd", "lnode1310");
OnmsNode node405 = m_nodeDao.findByForeignId("linkd", "lnode405");
OnmsNode node2965 = m_nodeDao.findByForeignId("linkd", "lnode2965");
OnmsNode node5022 = m_nodeDao.findByForeignId("linkd", "lnode5022");
BridgeBridgeLink link7 = new BridgeBridgeLink();
link7.setNode(node5022);
link7.setBridgePort(4);
link7.setDesignatedNode(node2965);
link7.setDesignatedPort(5);
link7.setBridgeBridgeLinkLastPollTime(link7.getBridgeBridgeLinkCreateTime());
m_bridgeBridgeLinkDao.save(link7);
m_bridgeBridgeLinkDao.flush();
BridgeBridgeLink link1 = new BridgeBridgeLink();
link1.setNode(node1544);
link1.setBridgePort(15);
link1.setDesignatedNode(node1400);
link1.setDesignatedPort(1);
link1.setBridgeBridgeLinkLastPollTime(link1.getBridgeBridgeLinkCreateTime());
m_bridgeBridgeLinkDao.save(link1);
m_bridgeBridgeLinkDao.flush();
BridgeBridgeLink link3 = new BridgeBridgeLink();
link3.setNode(node1310);
link3.setBridgePort(1);
link3.setDesignatedNode(node1534);
link3.setDesignatedPort(1);
link3.setBridgeBridgeLinkLastPollTime(link3.getBridgeBridgeLinkCreateTime());
m_bridgeBridgeLinkDao.save(link3);
m_bridgeBridgeLinkDao.flush();
BridgeBridgeLink link4 = new BridgeBridgeLink();
link4.setNode(node1364);
link4.setBridgePort(24);
link4.setDesignatedNode(node1534);
link4.setDesignatedPort(4);
link4.setBridgeBridgeLinkLastPollTime(link4.getBridgeBridgeLinkCreateTime());
m_bridgeBridgeLinkDao.save(link4);
m_bridgeBridgeLinkDao.flush();
BridgeBridgeLink link2 = new BridgeBridgeLink();
link2.setNode(node1534);
link2.setBridgePort(11);
link2.setDesignatedNode(node1400);
link2.setDesignatedPort(11);
link2.setBridgeBridgeLinkLastPollTime(link2.getBridgeBridgeLinkCreateTime());
m_bridgeBridgeLinkDao.save(link2);
m_bridgeBridgeLinkDao.flush();
BridgeBridgeLink link6 = new BridgeBridgeLink();
link6.setNode(node2965);
link6.setBridgePort(2);
link6.setDesignatedNode(node1364);
link6.setDesignatedPort(5);
link6.setBridgeBridgeLinkLastPollTime(link6.getBridgeBridgeLinkCreateTime());
m_bridgeBridgeLinkDao.save(link6);
m_bridgeBridgeLinkDao.flush();
BridgeBridgeLink link5 = new BridgeBridgeLink();
link5.setNode(node405);
link5.setBridgePort(1);
link5.setDesignatedNode(node1534);
link5.setDesignatedPort(1);
link5.setBridgeBridgeLinkLastPollTime(link5.getBridgeBridgeLinkCreateTime());
m_bridgeBridgeLinkDao.save(link5);
m_bridgeBridgeLinkDao.flush();
assertEquals(0, m_bridgeMacLinkDao.countAll());
assertEquals(7, m_bridgeBridgeLinkDao.countAll());
assertNotNull(m_bridgeTopologyDao);
m_linkd.getQueryManager().loadBridgeTopology();
assertEquals(1, m_linkd.getQueryManager().getAllBroadcastDomains().size());
BroadcastDomain fourlevelDomain = m_linkd.getQueryManager().getAllBroadcastDomains().iterator().next();
assertEquals(8, fourlevelDomain.getBridgeNodesOnDomain().size());
System.err.println(fourlevelDomain.printTopology());
}
Aggregations