use of org.opennms.core.criteria.restrictions.NeRestriction in project opennms by OpenNMS.
the class QueryManagerDaoImpl method getNodeServices.
@Override
public List<String[]> getNodeServices(int nodeId) {
final LinkedList<String[]> servicemap = new LinkedList<>();
Criteria criteria = new Criteria(OnmsMonitoredService.class);
criteria.setAliases(Arrays.asList(new Alias[] { new Alias("ipInterface", "ipInterface", JoinType.LEFT_JOIN), new Alias("ipInterface.node", "node", JoinType.LEFT_JOIN) }));
criteria.addRestriction(new EqRestriction("node.id", nodeId));
// Ignore forced-unmanaged
criteria.addRestriction(new NeRestriction("status", "F"));
for (OnmsMonitoredService service : m_monitoredServiceDao.findMatching(criteria)) {
servicemap.add(new String[] { service.getIpAddressAsString(), service.getServiceName() });
}
return servicemap;
}
use of org.opennms.core.criteria.restrictions.NeRestriction in project opennms by OpenNMS.
the class LinkdEdgeStatusProvider method getLinkdEdgeDownAlarms.
protected List<OnmsAlarm> getLinkdEdgeDownAlarms() {
org.opennms.core.criteria.Criteria criteria = new org.opennms.core.criteria.Criteria(OnmsAlarm.class);
criteria.addRestriction(new EqRestriction("uei", EventConstants.TOPOLOGY_LINK_DOWN_EVENT_UEI));
criteria.addRestriction(new NeRestriction("severity", OnmsSeverity.CLEARED));
return getAlarmDao().findMatching(criteria);
}
use of org.opennms.core.criteria.restrictions.NeRestriction in project opennms by OpenNMS.
the class NodeLabelDaoImpl method computeLabel.
/**
* This method determines what label should be associated with a particular
* node.
*
* Algorithm for determining a node's label is as follows: 1) If node has a
* NetBIOS name associated with it, the NetBIOS name is used as the node's
* label. 2) If no NetBIOS name available, retrieve all the 'ipinterface'
* table entries associated with the node with an 'isManaged' field value of
* 'M' 3) Find the primary interface where "primary" is defined as the
* managed interface with the smallest IP address (each IP address is
* converted to an integer value -- the IP address with the smallest integer
* value wins). 4) IF the primary interface's IP host name is known it
* becomes the node's label. ELSE IF the node's MIB-II sysName value is
* known it becomes the node's label ELSE the primary interface's IP address
* becomes the node's label.
*
* NOTE: If for some reason a node has no "managed" interfaces null is
* returned for the NodeLabel.
*
* @param nodeID
* Unique identifier of the node to be updated.
* @param dbConnection
* SQL database connection
* @return NodeLabel Object containing label and source values or null if
* node does not have a primary interface.
* @throws java.sql.SQLException if any.
*/
@Override
public NodeLabel computeLabel(final int nodeID) throws SQLException {
OnmsNode node = nodeDao.get(nodeID);
if (node == null) {
return null;
}
// Retrieve NetBIOS name associated with the node
String netbiosName = node.getNetBiosName();
if (netbiosName != null) {
// Truncate sysName if it exceeds max node label length
if (netbiosName.length() > MAX_NODE_LABEL_LENGTH) {
netbiosName = netbiosName.substring(0, MAX_NODE_LABEL_LENGTH);
}
LOG.debug("NodeLabel.computeLabel: returning NetBIOS name as nodeLabel: {}", netbiosName);
return new NodeLabelDaoImpl(netbiosName, NodeLabelSource.NETBIOS);
}
// OK, if we get this far the node has no NetBIOS name associated with it so,
// retrieve the primary interface select method property which indicates
// the method to use for determining which interface on a multi-interface
// system is to be deemed the primary interface. The primary interface
// will then determine what the node's label is.
String method = System.getProperty(PROP_PRIMARY_INTERFACE_SELECT_METHOD);
if (method == null) {
method = DEFAULT_SELECT_METHOD;
}
if (!method.equals(SELECT_METHOD_MIN) && !method.equals(SELECT_METHOD_MAX)) {
LOG.warn("Interface selection method is '{}'. Valid values are 'min' & 'max'. Will use default value: {}", method, DEFAULT_SELECT_METHOD);
method = DEFAULT_SELECT_METHOD;
}
List<InetAddress> ipv4AddrList = new ArrayList<>();
List<String> ipHostNameList = new ArrayList<>();
final org.opennms.core.criteria.Criteria criteria = new org.opennms.core.criteria.Criteria(OnmsIpInterface.class).setAliases(Arrays.asList(new Alias[] { new Alias("node", "node", JoinType.LEFT_JOIN) })).addRestriction(new EqRestriction("node.id", nodeID)).addRestriction(new EqRestriction("isManaged", "M"));
List<OnmsIpInterface> ints = ipInterfaceDao.findMatching(criteria);
for (OnmsIpInterface iface : ints) {
InetAddress inetAddr = iface.getIpAddress();
ipv4AddrList.add(inetAddr);
String hostName = iface.getIpHostName();
if (hostName == null || hostName.equals(inetAddr.toString())) {
ipHostNameList.add("");
} else {
ipHostNameList.add(hostName);
}
}
InetAddress primaryAddr = selectPrimaryAddress(ipv4AddrList, method);
// and select the primary interface from them.
if (primaryAddr == null) {
LOG.debug("NodeLabel.computeLabel: unable to find a primary address for node {}, returning null", nodeID);
ipv4AddrList.clear();
ipHostNameList.clear();
final org.opennms.core.criteria.Criteria crit = new org.opennms.core.criteria.Criteria(OnmsIpInterface.class).setAliases(Arrays.asList(new Alias[] { new Alias("node", "node", JoinType.LEFT_JOIN) })).addRestriction(new EqRestriction("node.id", nodeID)).addRestriction(new NeRestriction("isManaged", "M"));
List<OnmsIpInterface> sec = ipInterfaceDao.findMatching(crit);
for (OnmsIpInterface iface : sec) {
InetAddress inetAddr = iface.getIpAddress();
ipv4AddrList.add(inetAddr);
String hostName = iface.getIpHostName();
if (hostName == null || hostName.equals(inetAddr.toString())) {
ipHostNameList.add("");
} else {
ipHostNameList.add(hostName);
}
}
primaryAddr = selectPrimaryAddress(ipv4AddrList, method);
}
if (primaryAddr == null) {
LOG.warn("Could not find primary interface for node {}, cannot compute nodelabel", nodeID);
return new NodeLabelDaoImpl("Unknown", NodeLabelSource.UNKNOWN);
}
// We now know the IP address of the primary interface so
// now see if it has a IP host name
int index = ipv4AddrList.indexOf(primaryAddr);
String primaryHostName = ipHostNameList.get(index);
// If length of string is > 0 then the primary interface has a hostname
if (primaryHostName.length() != 0) {
// Truncate host name if it exceeds max node label length
if (primaryHostName.length() > MAX_NODE_LABEL_LENGTH) {
primaryHostName = primaryHostName.substring(0, MAX_NODE_LABEL_LENGTH);
}
return new NodeLabelDaoImpl(primaryHostName, NodeLabelSource.HOSTNAME);
}
// If we get this far either the primary interface does not have
// a host name or the node does not have a primary interface...
// so we need to use the node's sysName if available...
// retrieve sysName for the node
String primarySysName = node.getSysName();
if (primarySysName != null && primarySysName.length() > 0) {
// Truncate sysName if it exceeds max node label length
if (primarySysName.length() > MAX_NODE_LABEL_LENGTH) {
primarySysName = primarySysName.substring(0, MAX_NODE_LABEL_LENGTH);
}
return new NodeLabelDaoImpl(primarySysName, NodeLabelSource.SYSNAME);
}
// use the ipAddress as the nodeLabel
return new NodeLabelDaoImpl(InetAddressUtils.str(primaryAddr), NodeLabelSource.ADDRESS);
}
Aggregations