private ThresholdingVisitor createVisitor(Map<String,Object> params) throws ThresholdInitializationException { ServiceParameters svcParams = new ServiceParameters(params); ThresholdingVisitor visitor = ThresholdingVisitor.create(1, "127.0.0.1", "SNMP", getRepository(), svcParams, m_resourceStorageDao); assertNotNull(visitor); return visitor; }
/** * This test uses this files from src/test/resources: * - threshd-configuration-outages.xml * - test-thresholds.xml */ @Test public void testBug4261_scheduledOutages() throws Exception { initFactories("/threshd-configuration-outages.xml","/test-thresholds.xml"); ThresholdingVisitor visitor = createVisitor(); Assert.assertEquals(1, visitor.getScheduledOutages().size()); Assert.assertTrue("is node on outage", visitor.isNodeInOutage()); }
/** * <p>reinitializeThresholding</p> */ /* * TODO Re-create or merge ? * * The reason of doing a merge is to keep and update the threshold states. * * It is extremely more easy to just recreate the thresholding visitor to avoid complex * operations. But, the cost of doing this is that all the states will be lost, and * some alarms will become orphans. * * Other idea is to create two methods to get and set the states, and detect orphan * states. That way, we can decide what to do with orphans (like clear the alarm, or * send an auto-rearm), and also it can be used to persist the states across restarts. */ public void reinitializeThresholding() { if(m_thresholdVisitor!=null) { LOG.debug("reinitializeThresholding on {}", this); m_thresholdVisitor.reload(); } }
for (int i=1; i<=5; i++) { String ipAddress = baseIpAddress + i; ThresholdingVisitor visitor = ThresholdingVisitor.create(i, ipAddress, "SNMP", getRepository(), svcParams, m_resourceStorageDao); assertNotNull(visitor); visitors.add(visitor); if (i == 5) { ThresholdingVisitor httpVisitor = ThresholdingVisitor.create(i, ipAddress, "HTTP", getRepository(), svcParams, m_resourceStorageDao); assertNotNull(httpVisitor); visitors.add(httpVisitor); assertTrue(visitors.get(i).hasThresholds()); assertEquals(1, visitors.get(i).getThresholdGroups().size()); assertFalse(visitors.get(i).hasThresholds()); assertEquals(0, visitors.get(i).getThresholdGroups().size()); visitor.reload(); assertTrue(visitors.get(i).hasThresholds()); assertEquals(1, visitors.get(i).getThresholdGroups().size()); if (i == 5) { assertEquals("web-services", visitors.get(i).getThresholdGroups().get(0).getName());
if (m_thresholdVisitor.isNodeInOutage()) { LOG.info("run: the threshold processing will be skipped because the node {} is on a scheduled outage.", m_nodeId); } else if (m_thresholdVisitor.hasThresholds()) { m_thresholdVisitor.setCounterReset(result.ignorePersist()); // Required to reinitialize the counters. result.visit(m_thresholdVisitor);
System.err.println("----------------------------------------------------------------------------------- visitor #" + i); String ipAddress = baseIpAddress + i; ThresholdingVisitor visitor = ThresholdingVisitor.create(1, ipAddress, "SNMP", getRepository(), svcParams, m_resourceStorageDao); assertNotNull(visitor); assertEquals(4, visitor.getThresholdGroups().size()); // mib2, cisco, ciscoIPRA, ciscoNAS
private void runInterfaceResource(ThresholdingVisitor visitor, String ipAddress, String ifName, Long ifSpeed, Integer ifIndex, long v1, long v2) { SnmpIfData ifData = createSnmpIfData(ipAddress, ifName, ifSpeed, ifIndex, true); SnmpCollectionAgent agent = createCollectionAgent(); IfResourceType resourceType = createInterfaceResourceType(agent); // Step 1 visitor.visitCollectionSet(createAnonymousCollectionSet(visitor.getCollectionTimestamp().getTime())); SnmpCollectionResource resource = new IfInfo(resourceType, agent, ifData); addAttributeToCollectionResource(resource, resourceType, "ifInOctets", "counter", "ifIndex", v1); addAttributeToCollectionResource(resource, resourceType, "ifOutOctets", "counter", "ifIndex", v1); resource.visit(visitor); // Step 2 - Increment Counters visitor.visitCollectionSet(createAnonymousCollectionSet(visitor.getCollectionTimestamp().getTime()+300000)); resource = new IfInfo(resourceType, agent, ifData); addAttributeToCollectionResource(resource, resourceType, "ifInOctets", "counter", "ifIndex", v2); addAttributeToCollectionResource(resource, resourceType, "ifOutOctets", "counter", "ifIndex", v2); resource.visit(visitor); EasyMock.verify(agent); }
/** * Uses the existing package name to try and re-obtain the package from the collectd config factory. * Should be called when the collect config has been reloaded. * * @param collectorConfigDao a {@link org.opennms.netmgt.config.CollectdConfigFactory} object. * @throws CollectionInitializationException */ public void refreshPackage(CollectdConfigFactory collectorConfigDao) throws CollectionInitializationException { m_spec.refresh(collectorConfigDao); if (m_thresholdVisitor != null) { try { m_thresholdVisitor.reloadScheduledOutages(); } catch (final ThresholdInitializationException e) { throw new CollectionInitializationException("Failed to reload scheduled outages after refreshing package.", e); } } }
/** * Static method create must be used to create new ThresholdingVisitor instance. * Is static because successful creation depends on thresholding-enabled parameter. * * @param nodeId a int. * @param hostAddress a {@link java.lang.String} object. * @param serviceName a {@link java.lang.String} object. * @param repo a {@link org.opennms.netmgt.rrd.RrdRepository} object. * @param svcParams a {@link org.opennms.netmgt.collection.api.ServiceParameters} object. * @return a {@link org.opennms.netmgt.threshd.ThresholdingVisitor} object. * @throws ThresholdInitializationException */ public static ThresholdingVisitor create(int nodeId, String hostAddress, String serviceName, RrdRepository repo, ServiceParameters svcParams, ResourceStorageDao resourceStorageDao) throws ThresholdInitializationException { String enabled = ParameterMap.getKeyedString(svcParams.getParameters(), "thresholding-enabled", null); if (enabled != null && !"true".equals(enabled)) { LOG.info("create: Thresholds processing is not enabled. Check thresholding-enabled param on collectd package"); return null; } CollectorThresholdingSet thresholdingSet = new CollectorThresholdingSet(nodeId, hostAddress, serviceName, repo, svcParams, resourceStorageDao); if (!thresholdingSet.hasThresholds()) { LOG.warn("create: the ipaddress/service {}/{} on node {} has no configured thresholds.", hostAddress, serviceName, nodeId); } return new ThresholdingVisitor(thresholdingSet); }
@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()); }
@Test public void testBug5764() throws Exception { ThresholdingVisitor visitor = createVisitor(); initFactories("/threshd-configuration.xml","/test-thresholds-bug5764.xml"); visitor.reload(); }
m_thresholdVisitor = ThresholdingVisitor.create(m_nodeId, getHostAddress(), m_spec.getServiceName(), m_repository, m_params, m_resourceStorageDao); } catch (final ThresholdInitializationException e) { throw new CollectionInitializationException("Failed to initialize thresholding visitor.", e);
@Test public void testBug3146_unrelatedChange() throws Exception { ThresholdingVisitor visitor = createVisitor(); // Add Events addHighThresholdEvent(1, 10000, 5000, 12000, "node", "node", "freeMem", null, null); addHighRearmEvent(1, 10000, 5000, 1000, "node", "node", "freeMem", null, null); // Step 1: Trigger threshold runGaugeDataTest(visitor, 12000); // Step 2: Reload Configuration (changes are not related to triggered threshold) visitor.reload(); // Step 3: Send Rearmed event runGaugeDataTest(visitor, 1000); // Verify Events verifyEvents(0); }
@Test public void testBug3146_replaceThreshold() throws Exception { ThresholdingVisitor visitor = createVisitor(); // Add Events String lowThresholdUei = EventConstants.LOW_THRESHOLD_EVENT_UEI; String highExpression = "(((hrStorageAllocUnits*hrStorageUsed)/(hrStorageAllocUnits*hrStorageSize))*100)"; String lowExpression = "(100-((hrStorageAllocUnits*hrStorageUsed)/(hrStorageAllocUnits*hrStorageSize))*100)"; addHighThresholdEvent(1, 30, 25, 50, "/opt", "1", highExpression, null, null); addHighRearmEvent(1, 30, 25, Double.NaN, "/opt", "1", highExpression, null, null); addEvent(lowThresholdUei, "127.0.0.1", "SNMP", 1, 10.0, 20.0, 5.0, "/opt", "1", lowExpression, null, null, m_anticipator, m_anticipatedEvents); // Step 1: Trigger threshold runFileSystemDataTest(visitor, 1, "/opt", 500, 1000); // Step 2: Reload Configuration (merge). Threshold definition was replaced. initFactories("/threshd-configuration.xml","/test-thresholds-4.xml"); visitor.reload(); // Step 3: Must trigger only one low threshold exceeded runFileSystemDataTest(visitor, 1, "/opt", 950, 1000); verifyEvents(0); }
@Test public void testReloadThresholdsConfig() throws Exception { ThresholdingVisitor visitor = createVisitor(); // Step 1: No events addHighThresholdEvent(1, 10000, 5000, 4500, "node", "node", "freeMem", null, null); runGaugeDataTest(visitor, 4500); verifyEvents(1); // Step 2: Change configuration initFactories("/threshd-configuration.xml","/test-thresholds-2.xml"); visitor.reload(); resetAnticipator(); // Step 3: Trigger threshold with new configuration values addHighThresholdEvent(1, 4000, 2000, 4500, "node", "node", "freeMem", null, null); runGaugeDataTest(visitor, 4500); verifyEvents(0); }
/** * This test uses this files from src/test/resources: * - threshd-configuration.xml * - test-thresholds-bug5258-a.xml * - test-thresholds-bug5258-b.xml */ @Test public void testBug5258() throws Exception { initFactories("/threshd-configuration.xml","/test-thresholds-bug5258-a.xml"); ThresholdingVisitor visitor = createVisitor(); // Define Main Events addEvent(EventConstants.HIGH_THRESHOLD_EVENT_UEI, "127.0.0.1", "SNMP", 1, 50.0, 45.0, 65.0, "/opt", "1", "hrStorageUsed", null, null, m_anticipator, m_anticipatedEvents); addEvent(EventConstants.HIGH_THRESHOLD_EVENT_UEI, "127.0.0.1", "SNMP", 1, 50.0, 45.0, 70.0, "/var", "1", "hrStorageUsed", null, null, m_anticipator, m_anticipatedEvents); // Define Rearm Event - This is because the configuration of an already triggered threshold has been changed. addEvent(EventConstants.HIGH_THRESHOLD_REARM_EVENT_UEI, "127.0.0.1", "SNMP", 1, 50.0, 45.0, Double.NaN, "/opt", "1", "hrStorageUsed", null, null, m_anticipator, m_anticipatedEvents); // Trigger high Threshold for /opt runFileSystemDataTest(visitor, 1, "/opt", 65, 100); // Change the filter initFactories("/threshd-configuration.xml","/test-thresholds-bug5258-b.xml"); visitor.reload(); // Trigger high Threshold for /var runFileSystemDataTest(visitor, 1, "/var", 70, 100); // Verify Events verifyEvents(0); }
@Test public void testBug3146_reduceTrigger() throws Exception { ThresholdingVisitor visitor = createVisitor(); // Add Events addHighThresholdEvent(1, 10000, 5000, 12000, "node", "node", "freeMem", null, null); addHighRearmEvent(1, 10000, 5000, Double.NaN, "node", "node", "freeMem", null, null); addHighThresholdEvent(1, 4000, 2000, 5000, "node", "node", "freeMem", null, null); addHighRearmEvent(1, 4000, 2000, 1000, "node", "node", "freeMem", null, null); // Step 1: Trigger threshold runGaugeDataTest(visitor, 12000); // Step 2: Change Configuration (reducing value for already triggered threshold) initFactories("/threshd-configuration.xml","/test-thresholds-2.xml"); // Step 3: Execute Merge Configuration visitor.reload(); // Step 4: Trigger threshold (with new value) runGaugeDataTest(visitor, 5000); // Step 5: Send Rearmed event (with new value) runGaugeDataTest(visitor, 1000); // Verify Events verifyEvents(0); }
@Test public void testBug3146_inceaseTrigger() throws Exception { ThresholdingVisitor visitor = createVisitor(); // Add Events addHighThresholdEvent(1, 10000, 5000, 12000, "node", "node", "freeMem", null, null); addHighRearmEvent(1, 10000, 5000, Double.NaN, "node", "node", "freeMem", null, null); // Step 1: Trigger threshold runGaugeDataTest(visitor, 12000); // Step 2: Change Configuration (increasing value for already triggered threshold) initFactories("/threshd-configuration.xml","/test-thresholds-3.xml"); // Step 3: Execute Merge Configuration (Rearmed Event must be sent). visitor.reload(); verifyEvents(0); // Step 4: New collected data is not above the new threshold value. No Events generated resetAnticipator(); addHighThresholdEvent(1, 15000, 14000, 13000, "node", "node", "freeMem", null, null); runGaugeDataTest(visitor, 13000); verifyEvents(1); // Step 5: Trigger and rearm a threshold using new configuration resetAnticipator(); addHighThresholdEvent(1, 15000, 14000, 16000, "node", "node", "freeMem", null, null); addHighRearmEvent(1, 15000, 14000, 1000, "node", "node", "freeMem", null, null); runGaugeDataTest(visitor, 16000); runGaugeDataTest(visitor, 1000); verifyEvents(0); }