@Override protected ThresholdingEventProxy initialValue() { return new ThresholdingEventProxy(); } };
/** * Apply threshold for specific resource (and required attributes). * Send thresholds events (if exists). */ @Override public void completeResource(CollectionResource resource) { List<Event> eventList = m_thresholdingSet.applyThresholds(resource, m_attributesMap, m_collectionTimestamp); ThresholdingEventProxy proxy = ThresholdingEventProxyFactory.getFactory().getProxy(); proxy.add(eventList); proxy.sendAllEvents(); }
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); } }
/** {@inheritDoc} */ @Override public void send(Event event) throws EventProxyException { add(event); }
ThresholdingEventProxyFactory.getFactory().getProxy().removeAllEvents(); ThresholdingEventProxyFactory.getFactory().getProxy().sendAllEvents();
/** * <p>sendAllEvents</p> */ public void sendAllEvents() { if (m_events.size() > 0) { try { Log log = new Log(); Events events = new Events(); for (Event e : m_events) { events.addEvent(e); } log.setEvents(events); EventIpcManagerFactory.getIpcManager().sendNow(log); } catch (Throwable e) { LOG.info("sendAllEvents: Failed sending threshold events", e); } removeAllEvents(); } }
@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); }
/** * <p>send</p> * * @param eventLog a {@link org.opennms.netmgt.xml.event.Log} object. * @throws org.opennms.netmgt.events.api.EventProxyException if any. */ @Override public void send(Log eventLog) throws EventProxyException { for (Event e : eventLog.getEvents().getEventCollection()) { add(e); } }
@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); }
private void sendRearmForTriggeredStates() { for (String instance : m_thresholdEvaluatorStates.keySet()) { for (ThresholdEvaluatorState state : m_thresholdEvaluatorStates.get(instance)) { if (state.isTriggered()) { Event e = state.getEventForState(Status.RE_ARMED, new Date(), Double.NaN, null); Parm p = new Parm(); p.setParmName("reason"); Value v = new Value(); v.setContent("Configuration has been changed"); p.setValue(v); e.addParm(p); LOG.info("sendRearmForTriggeredStates: sending rearm for {}", e); ThresholdingEventProxyFactory.getFactory().getProxy().add(e); state.clearState(); } } } }
ThresholdingEventProxy proxy = new ThresholdingEventProxy(); proxy.add(triggerEvents); proxy.add(rearmEvents); proxy.sendAllEvents(); verifyEvents(0);