@Override protected ThresholdingEventProxy initialValue() { return new ThresholdingEventProxy(); } };
private void applyThresholds(String rrdPath, MonitoredService service, String dsName, Map<String, Number> entries) { try { if (m_thresholdingSet == null) { RrdRepository repository = new RrdRepository(); repository.setRrdBaseDir(new File(rrdPath)); m_thresholdingSet = new LatencyThresholdingSet(service.getNodeId(), service.getIpAddr(), service.getSvcName(), service.getNodeLocation(), repository, m_resourceStorageDao); } LinkedHashMap<String, Double> attributes = new LinkedHashMap<String, Double>(); for (String ds : entries.keySet()) { Number sampleValue = entries.get(ds); if (sampleValue == null) { attributes.put(ds, Double.NaN); } else { attributes.put(ds, sampleValue.doubleValue()); } } if (m_thresholdingSet.isNodeInOutage()) { LOG.info("applyThresholds: the threshold processing will be skipped because the service {} is on a scheduled outage.", service); } else if (m_thresholdingSet.hasThresholds(attributes)) { List<Event> events = m_thresholdingSet.applyThresholds(dsName, attributes); if (events.size() > 0) { ThresholdingEventProxy proxy = new ThresholdingEventProxy(); proxy.add(events); proxy.sendAllEvents(); } } } catch(Throwable e) { LOG.error("Failed to threshold on {} for {} because of an exception", service, dsName, e); } }
@Test @JUnitTemporaryDatabase(tempDbClass=MockDatabase.class) public void testBug3488() throws Exception { String ipAddress = "127.0.0.1"; setupSnmpInterfaceDatabase(m_db, ipAddress, null); LatencyThresholdingSet thresholdingSet = new LatencyThresholdingSet(1, ipAddress, "HTTP", null, getRepository(), m_resourceStorageDao); assertTrue(thresholdingSet.hasThresholds()); // Global Test Map<String, Double> attributes = new HashMap<String, Double>(); attributes.put("http", 200.0); assertTrue(thresholdingSet.hasThresholds(attributes)); // Datasource Test List<Event> triggerEvents = new ArrayList<>(); for (int i=0; i<5; i++) triggerEvents.addAll(thresholdingSet.applyThresholds("http", attributes)); assertTrue(triggerEvents.size() == 1); addEvent(EventConstants.HIGH_THRESHOLD_EVENT_UEI, "127.0.0.1", "HTTP", 5, 100.0, 50.0, 200.0, IfLabel.NO_IFLABEL, "127.0.0.1[http]", "http", IfLabel.NO_IFLABEL, null, m_eventIpcManager.getEventAnticipator(), m_anticipatedEvents); ThresholdingEventProxy proxy = new ThresholdingEventProxy(); proxy.add(triggerEvents); proxy.sendAllEvents(); verifyEvents(0); }
@Test @JUnitTemporaryDatabase(tempDbClass=MockDatabase.class) public void testBug3575() throws Exception { initFactories("/threshd-configuration-bug3575.xml","/test-thresholds-bug3575.xml"); String ipAddress = "127.0.0.1"; String ifName = "eth0"; setupSnmpInterfaceDatabase(m_db, ipAddress, ifName); LatencyThresholdingSet thresholdingSet = new LatencyThresholdingSet(1, ipAddress, "StrafePing", null, getRepository(), m_resourceStorageDao); assertTrue(thresholdingSet.hasThresholds()); Map<String, Double> attributes = new HashMap<String, Double>(); for (double i=1; i<21; i++) { attributes.put("ping" + i, 2 * i); } attributes.put("loss", 60.0); attributes.put("median", 100.0); attributes.put(PollStatus.PROPERTY_RESPONSE_TIME, 100.0); assertTrue(thresholdingSet.hasThresholds(attributes)); List<Event> triggerEvents = thresholdingSet.applyThresholds("StrafePing", attributes); assertTrue(triggerEvents.size() == 1); addEvent(EventConstants.HIGH_THRESHOLD_EVENT_UEI, "127.0.0.1", "StrafePing", 1, 50.0, 25.0, 60.0, ifName, "127.0.0.1[StrafePing]", "loss", "eth0", null, m_eventIpcManager.getEventAnticipator(), m_anticipatedEvents); ThresholdingEventProxy proxy = new ThresholdingEventProxy(); proxy.add(triggerEvents); proxy.sendAllEvents(); verifyEvents(0); }
ThresholdingEventProxy proxy = new ThresholdingEventProxy(); proxy.add(triggerEvents); proxy.add(rearmEvents);