use of org.opennms.netmgt.config.ThreshdConfigManager in project opennms by OpenNMS.
the class ThresholdingVisitorIT method testBug3390.
/*
* This test uses this files from src/test/resources:
* - threshd-configuration-bug3390.xml
* - test-thresholds-bug3390.xml
*
* The idea is to define many threshold-group parameters on a service inside a package
*/
@Test
public void testBug3390() throws Exception {
initFactories("/threshd-configuration-bug3390.xml", "/test-thresholds-bug3390.xml");
// Validating threshd-configuration.xml
ThreshdConfigManager configManager = ThreshdConfigFactory.getInstance();
final List<Package> packages = configManager.getConfiguration().getPackages();
assertEquals(1, packages.size());
org.opennms.netmgt.config.threshd.Package pkg = packages.get(0);
final List<Service> services = pkg.getServices();
assertEquals(1, services.size());
org.opennms.netmgt.config.threshd.Service svc = services.get(0);
final List<Parameter> parameters = svc.getParameters();
assertEquals(5, parameters.size());
int count = 0;
for (org.opennms.netmgt.config.threshd.Parameter parameter : parameters) {
if (parameter.getKey().equals("thresholding-group"))
count++;
}
assertEquals(5, count);
// Validating Thresholding Set
ThresholdingVisitor visitor = createVisitor();
assertEquals(5, visitor.getThresholdGroups().size());
}
use of org.opennms.netmgt.config.ThreshdConfigManager in project opennms by OpenNMS.
the class ThresholdingSet method getThresholdGroupNames.
/*
* The next code was extracted from Threshd.scheduleService.
*
* - Search for packages defined on threshd-configuration.xml.
* - Compare interface/service pair against each Threshd package.
* - For each match, create new ThresholdableService object and schedule it for collection
*/
private static final List<String> getThresholdGroupNames(int nodeId, String hostAddress, String serviceName) {
ThreshdConfigManager configManager = ThreshdConfigFactory.getInstance();
List<String> groupNameList = new LinkedList<>();
for (org.opennms.netmgt.config.threshd.Package pkg : configManager.getConfiguration().getPackages()) {
// Make certain the the current service is in the package and enabled!
if (!configManager.serviceInPackageAndEnabled(serviceName, pkg)) {
LOG.debug("getThresholdGroupNames: address/service: {}/{} not scheduled, service is not enabled or does not exist in package: {}", hostAddress, serviceName, pkg.getName());
continue;
}
// Is the interface in the package?
LOG.debug("getThresholdGroupNames: checking ipaddress {} for inclusion in pkg {}", hostAddress, pkg.getName());
if (!configManager.interfaceInPackage(hostAddress, pkg)) {
LOG.debug("getThresholdGroupNames: address/service: {}/{} not scheduled, interface does not belong to package: {}", hostAddress, serviceName, pkg.getName());
continue;
}
// Getting thresholding-group for selected service and adding to groupNameList
for (org.opennms.netmgt.config.threshd.Service svc : pkg.getServices()) {
if (svc.getName().equals(serviceName)) {
for (org.opennms.netmgt.config.threshd.Parameter parameter : svc.getParameters()) {
if (parameter.getKey().equals("thresholding-group")) {
String groupName = parameter.getValue();
groupNameList.add(groupName);
LOG.debug("getThresholdGroupNames: address/service: {}/{}. Adding Group {}", hostAddress, serviceName, groupName);
}
}
}
}
}
return groupNameList;
}
use of org.opennms.netmgt.config.ThreshdConfigManager in project opennms by OpenNMS.
the class ThresholdingSet method updateScheduledOutages.
protected void updateScheduledOutages() {
synchronized (m_scheduledOutages) {
m_scheduledOutages.clear();
ThreshdConfigManager configManager = ThreshdConfigFactory.getInstance();
for (org.opennms.netmgt.config.threshd.Package pkg : configManager.getConfiguration().getPackages()) {
for (String outageCal : pkg.getOutageCalendars()) {
LOG.info("updateScheduledOutages[node={}]: checking scheduled outage '{}'", m_nodeId, outageCal);
try {
Outage outage = PollOutagesConfigFactory.getInstance().getOutage(outageCal);
if (outage == null) {
LOG.info("updateScheduledOutages[node={}]: scheduled outage '{}' is not defined.", m_nodeId, outageCal);
} else {
LOG.debug("updateScheduledOutages[node={}]: outage calendar '{}' found on package '{}'", m_nodeId, outage.getName(), pkg.getName());
m_scheduledOutages.add(outageCal);
}
} catch (Exception e) {
LOG.info("updateScheduledOutages[node={}]: scheduled outage '{}' does not exist.", m_nodeId, outageCal);
}
}
}
}
}
Aggregations