📄 pollerconfigfactory.java
字号:
filterRules.append('\"'); filterRules.append(")"); } if (log.isDebugEnabled()) log.debug("createPackageIpMap: package is " + pkg.getName() + ". filer rules are " + filterRules.toString()); List ipList = filter.getIPList(filterRules.toString()); if (log.isDebugEnabled()) log.debug("createPackageIpMap: package " + pkg.getName() + ": ipList size = " + ipList.size()); if (ipList.size() > 0) { if (log.isDebugEnabled()) log.debug("createPackageIpMap: package " + pkg.getName() + ". IpList size is " + ipList.size()); m_pkgIpMap.put(pkg, ipList); } } catch (Throwable t) { if (log.isEnabledFor(Priority.ERROR)) { log.error("createPackageIpMap: failed to map package: " + pkg.getName() + " to an IP List", t); } } } } /** * This method is used to rebuild the package agaist iplist mapping when * needed. When a node gained service event occurs, poller has to determine * which package the ip/service combination is in, but if the interface is a * newly added one, the package iplist should be rebuilt so that poller * could know which package this ip/service pair is in. */ public synchronized void rebuildPackageIpListMap() { createPackageIpListMap(); } /** * 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.poller.Package pkg) { Category log = ThreadCategory.getInstance(this.getClass()); boolean filterPassed = false; // get list of IPs in this package java.util.List ipList = (java.util.List) m_pkgIpMap.get(pkg); if (ipList != null && ipList.size() > 0) { filterPassed = ipList.contains(iface); } if (log.isDebugEnabled()) log.debug("interfaceInPackage: Interface " + iface + " passed filter for package " + pkg.getName() + "?: " + filterPassed); 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; long addr = IPSorter.convertToLong(iface); Enumeration eincs = pkg.enumerateIncludeRange(); while (!has_range_include && eincs.hasMoreElements()) { IncludeRange rng = (IncludeRange) eincs.nextElement(); long start = IPSorter.convertToLong(rng.getBegin()); if (addr > start) { long end = IPSorter.convertToLong(rng.getEnd()); if (addr <= end) { has_range_include = true; } } else if (addr == start) { has_range_include = true; } } Enumeration espec = pkg.enumerateSpecific(); while (!has_specific && espec.hasMoreElements()) { long speca = IPSorter.convertToLong(espec.nextElement().toString()); if (speca == addr) has_specific = true; } Enumeration eurl = pkg.enumerateIncludeUrl(); while (!has_specific && eurl.hasMoreElements()) { has_specific = interfaceInUrl(iface, (String) eurl.nextElement()); } Enumeration eex = pkg.enumerateExcludeRange(); while (!has_range_exclude && !has_specific && eex.hasMoreElements()) { ExcludeRange rng = (ExcludeRange) eex.nextElement(); long start = IPSorter.convertToLong(rng.getBegin()); if (addr > start) { long end = IPSorter.convertToLong(rng.getEnd()); if (addr <= end) { has_range_exclude = true; } } else if (addr == start) { has_range_exclude = true; } } return has_specific || (has_range_include && !has_range_exclude); } /** * Returns true if the service is part of the package and the status of the * service is set to "on". Returns false if the service is not in the * package or it is but the status of the service is set to "off". * * @param svcName * The service name to lookup. * @param pkg * The package to lookup up service. */ public synchronized boolean serviceInPackageAndEnabled(String svcName, org.opennms.netmgt.config.poller.Package pkg) { Category log = ThreadCategory.getInstance(this.getClass()); if (pkg == null) { log.warn("serviceInPackageAndEnabled: pkg argument is NULL!!"); return false; } else { if (log.isDebugEnabled()) log.debug("serviceInPackageAndEnabled: svcName=" + svcName + " pkg=" + pkg.getName()); } boolean result = false; Enumeration esvcs = pkg.enumerateService(); while (result == false && esvcs.hasMoreElements()) { Service tsvc = (Service) esvcs.nextElement(); if (tsvc.getName().equalsIgnoreCase(svcName)) { // Ok its in the package. Now check the // status of the service String status = tsvc.getStatus(); if (status.equals("on")) result = true; } } return result; } /** * Returns true if the service has a monitor configured, false otherwise. * * @param svcName * The service name to lookup. */ public synchronized boolean serviceMonitored(String svcName) { boolean result = false; Enumeration monitorEnum = m_config.enumerateMonitor(); while (monitorEnum.hasMoreElements()) { Monitor monitor = (Monitor) monitorEnum.nextElement(); if (monitor.getService().equals(svcName)) { result = true; break; } } return result; } /** * Returns the first package that the ip belongs to, null if none. * * <strong>Note: </strong>Evaluation of the interface against a package * filter will only work if the IP is alrady in the database. * * @param ipaddr * the interface to check * * @return the first package that the ip belongs to, null if none */ public synchronized org.opennms.netmgt.config.poller.Package getFirstPackageMatch(String ipaddr) { Enumeration pkgEnum = m_config.enumeratePackage(); while (pkgEnum.hasMoreElements()) { org.opennms.netmgt.config.poller.Package pkg = (org.opennms.netmgt.config.poller.Package) pkgEnum.nextElement(); boolean inPkg = interfaceInPackage(ipaddr, pkg); if (inPkg) return pkg; } return null; } /** * Returns a list of package names that the ip belongs to, null if none. * * <strong>Note: </strong>Evaluation of the interface against a package * filter will only work if the IP is alrady in the database. * * @param ipaddr * the interface to check * * @return a list of package names that the ip belongs to, null if none */ public synchronized List getAllPackageMatches(String ipaddr) { Category log = ThreadCategory.getInstance(getClass()); Enumeration pkgEnum = m_config.enumeratePackage(); List matchingPkgs = new ArrayList(); while (pkgEnum.hasMoreElements()) { org.opennms.netmgt.config.poller.Package pkg = (org.opennms.netmgt.config.poller.Package) pkgEnum.nextElement(); String pkgName = pkg.getName(); boolean inPkg = interfaceInPackage(ipaddr, pkg); if (inPkg) { matchingPkgs.add(pkgName); } } return matchingPkgs; } /** * Returns true if the ip is part of atleast one package. * * <strong>Note: </strong>Evaluation of the interface against a package * filter will only work if the IP is alrady in the database. * * @param ipaddr * the interface to check * * @return true if the ip is part of atleast one package, false otherwise */ public synchronized boolean isPolled(String ipaddr) { Enumeration pkgEnum = m_config.enumeratePackage(); while (pkgEnum.hasMoreElements()) { org.opennms.netmgt.config.poller.Package pkg = (org.opennms.netmgt.config.poller.Package) pkgEnum.nextElement(); boolean inPkg = interfaceInPackage(ipaddr, pkg); if (inPkg) return true; } return false; } /** * Returns true if this package has the service enabled and if there is a * monitor for this service. * * <strong>Note: </strong>Evaluation of the interface against a package * filter will only work if the IP is alrady in the database. * * @param svcName * the service to check * @param pkg * the package to check * * @return true if the ip is part of atleast one package and the service is * enabled in this package and monitored, false otherwise */ public synchronized boolean isPolled(String svcName, org.opennms.netmgt.config.poller.Package pkg) { // Check if the service is enabled for this package and // if there is a monitor for that service // boolean svcInPkg = serviceInPackageAndEnabled(svcName, pkg); if (svcInPkg) { return serviceMonitored(svcName); } return false; } /** * Returns true if the ip is part of atleast one package and if this package * has the service enabled and if there is a monitor for this service. * * <strong>Note: </strong>Evaluation of the interface against a package * filter will only work if the IP is alrady in the database. * * @param ipaddr * the interface to check * @param svcName * the service to check * * @return true if the ip is part of atleast one package and the service is * enabled in this package and monitored, false otherwise */ public synchronized boolean isPolled(String ipaddr, String svcName) { // First make sure there is a service monitor for this service! if (!serviceMonitored(svcName)) { return false; } Enumeration pkgEnum = m_config.enumeratePackage(); while (pkgEnum.hasMoreElements()) { org.opennms.netmgt.config.poller.Package pkg = (org.opennms.netmgt.config.poller.Package) pkgEnum.nextElement(); // // Check if interface is in a package and if the service // is enabled for that package // boolean ipInPkg = interfaceInPackage(ipaddr, pkg); if (ipInPkg) { boolean svcInPkg = serviceInPackageAndEnabled(svcName, pkg); if (svcInPkg) { return true; } } } return false; } /** * Retrieves configured RRD step size. * * @param pkg * Name of the data collection * * @return RRD step size for the specified collection */ public int getStep(org.opennms.netmgt.config.poller.Package pkg) { return pkg.getRrd().getStep(); } /** * Retrieves configured list of RoundRobin Archive statements. * * @param pkg * Name of the data collection * * @return list of RRA strings. */ public List getRRAList(org.opennms.netmgt.config.poller.Package pkg) { return (List) pkg.getRrd().getRraCollection(); } public Enumeration enumeratePackage() { return getConfiguration().enumeratePackage(); } public Enumeration enumerateMonitor() { return getConfiguration().enumerateMonitor(); } public int getThreads() { return getConfiguration().getThreads(); } /** * @param poller * @return */ private void createServiceMonitors() { Category log = ThreadCategory.getInstance(getClass()); // Load up an instance of each monitor from the config // so that the event processor will have them for // new incomming events to create pollable service objects. // log.debug("start: Loading monitors"); Enumeration eiter = enumerateMonitor(); while (eiter.hasMoreElements()) { Monitor monitor = (Monitor) eiter.nextElement(); try { if (log.isDebugEnabled()) { log.debug("start: Loading monitor " + monitor.getService() + ", classname " + monitor.getClassName()); } Class mc = Class.forName(monitor.getClassName()); ServiceMonitor sm = (ServiceMonitor) mc.newInstance(); // Attempt to initialize the service monitor // Map properties = null; // properties not currently used sm.initialize(this, properties); m_svcMonitors.put(monitor.getService(), sm); } catch (Throwable t) { if (log.isEnabledFor(Priority.WARN)) { log.warn("start: Failed to load monitor " + monitor.getClassName() + " for service " + monitor.getService(), t); } } } } public Map getServiceMonitors() { return m_svcMonitors; } public ServiceMonitor getServiceMonitor(String svcName) { return (ServiceMonitor) getServiceMonitors().get(svcName); } public String getNextOutageIdSql() { return m_config.getNextOutageId(); } public void update() throws IOException, MarshalException, ValidationException { File cfgFile = ConfigFileConstants.getFile(ConfigFileConstants.POLLER_CONFIG_FILE_NAME); ThreadCategory.getInstance(PollerConfigFactory.class).debug("init: config file path: " + cfgFile.getPath()); reloadXML(OpennmsServerConfigFactory.getInstance(), new FileReader(cfgFile)); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -