Search in sources :

Example 1 with Package

use of org.opennms.netmgt.config.threshd.Package in project opennms by OpenNMS.

the class ThreshdConfigManager method createPackageIpListMap.

/**
     * This method is used to establish package against an iplist iplist mapping,
     * with which, the iplist is selected per package via the configured filter
     * rules from the database.
     */
protected void createPackageIpListMap() {
    m_pkgIpMap = new HashMap<Package, List<InetAddress>>();
    for (final org.opennms.netmgt.config.threshd.Package pkg : m_config.getPackages()) {
        //
        // Get a list of ipaddress per package agaist the filter rules from
        // database and populate the package, IP list map.
        //
        final StringBuffer filterRules = new StringBuffer();
        if (pkg.getFilter().getContent().isPresent()) {
            filterRules.append(pkg.getFilter().getContent().get());
        }
        try {
            if (m_verifyServer) {
                if (filterRules.length() > 0) {
                    filterRules.append(" & ");
                }
                filterRules.append("(serverName == ");
                filterRules.append('\"');
                filterRules.append(m_localServer);
                filterRules.append('\"');
                filterRules.append(")");
            }
            LOG.debug("createPackageIpMap: package is {}. filer rules are {}", filterRules, pkg.getName());
            FilterDaoFactory.getInstance().flushActiveIpAddressListCache();
            List<InetAddress> ipList = FilterDaoFactory.getInstance().getActiveIPAddressList(filterRules.toString());
            if (ipList.size() > 0) {
                m_pkgIpMap.put(pkg, ipList);
            }
        } catch (Throwable t) {
            LOG.error("createPackageIpMap: failed to map package: {} to an IP List with filter \"{}\"", pkg.getName(), pkg.getFilter().getContent(), t);
        }
    }
}
Also used : Package(org.opennms.netmgt.config.threshd.Package) List(java.util.List) Package(org.opennms.netmgt.config.threshd.Package) InetAddress(java.net.InetAddress)

Example 2 with Package

use of org.opennms.netmgt.config.threshd.Package 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());
}
Also used : Service(org.opennms.netmgt.config.threshd.Service) Parameter(org.opennms.netmgt.config.threshd.Parameter) Package(org.opennms.netmgt.config.threshd.Package) Service(org.opennms.netmgt.config.threshd.Service) Parameter(org.opennms.netmgt.config.threshd.Parameter) Package(org.opennms.netmgt.config.threshd.Package) ThreshdConfigManager(org.opennms.netmgt.config.ThreshdConfigManager) Test(org.junit.Test)

Aggregations

Package (org.opennms.netmgt.config.threshd.Package)2 InetAddress (java.net.InetAddress)1 List (java.util.List)1 Test (org.junit.Test)1 ThreshdConfigManager (org.opennms.netmgt.config.ThreshdConfigManager)1 Parameter (org.opennms.netmgt.config.threshd.Parameter)1 Service (org.opennms.netmgt.config.threshd.Service)1