use of org.opennms.netmgt.config.threshd.IncludeRange in project opennms by OpenNMS.
the class ThreshdConfigManager method interfaceInPackage.
/**
* This method is used to determine if the named interface is included in
* the passed package definition. If the interface belongs to the package
* then a value of true is returned. If the interface does not belong to the
* package a false value is returned.
*
* <strong>Note: </strong>Evaluation of the interface against a package
* filter will only work if the IP is already in the database.
*
* @param iface
* The interface to test against the package.
* @param pkg
* The package to check for the inclusion of the interface.
* @return True if the interface is included in the package, false
* otherwise.
*/
public synchronized boolean interfaceInPackage(String iface, org.opennms.netmgt.config.threshd.Package pkg) {
final InetAddress ifaceAddr = addr(iface);
boolean filterPassed = false;
// get list of IPs in this package
java.util.List<InetAddress> ipList = m_pkgIpMap.get(pkg);
if (ipList != null && ipList.size() > 0) {
filterPassed = ipList.contains(ifaceAddr);
}
LOG.debug("interfaceInPackage: Interface {} passed filter for package {}?: {}", filterPassed, iface, pkg.getName());
if (!filterPassed)
return false;
//
// Ensure that the interface is in the specific list or
// that it is in the include range and is not excluded
//
boolean has_specific = false;
boolean has_range_include = false;
boolean has_range_exclude = false;
has_range_include = pkg.getIncludeRanges().size() == 0 && pkg.getSpecifics().size() == 0;
for (IncludeRange rng : pkg.getIncludeRanges()) {
if (isInetAddressInRange(iface, rng.getBegin(), rng.getEnd())) {
has_range_include = true;
break;
}
}
byte[] addr = toIpAddrBytes(iface);
for (String spec : pkg.getSpecifics()) {
byte[] speca = toIpAddrBytes(spec);
if (new ByteArrayComparator().compare(speca, addr) == 0) {
has_specific = true;
break;
}
}
final Iterator<String> eurl = pkg.getIncludeUrls().iterator();
while (!has_specific && eurl.hasNext()) {
has_specific = interfaceInUrl(iface, eurl.next());
}
for (ExcludeRange rng : pkg.getExcludeRanges()) {
if (isInetAddressInRange(iface, rng.getBegin(), rng.getEnd())) {
has_range_exclude = true;
break;
}
}
return has_specific || (has_range_include && !has_range_exclude);
}
Aggregations