IspnAlertsServiceImpl implements AlertsService { @Override public Page<Alert> getAlerts(String tenantId, AlertsCriteria criteria, Pager pager) throws Exception { return getAlerts(Collections.singleton(tenantId), criteria, pager); }  void init(); void setAlertsEngine(AlertsEngine alertsEngine); void setDefinitionsService(DefinitionsService definitionsService); void setActionsService(ActionsService actionsService); void setIncomingDataManager(IncomingDataManager incomingDataManager); void setProperties(PropertiesService properties); @Override void ackAlerts(String tenantId, Collection<String> alertIds, String ackBy, String ackNotes); @Override void addAlerts(Collection<Alert> alerts); @Override void addAlertTags(String tenantId, Collection<String> alertIds, Map<String, String> tags); @Override void addEvents(Collection<Event> events); @Override void addEventTags(String tenantId, Collection<String> eventIds, Map<String, String> tags); @Override void persistEvents(Collection<Event> events); @Override void addNote(String tenantId, String alertId, String user, String text); @Override int deleteAlerts(String tenantId, AlertsCriteria criteria); @Override int deleteEvents(String tenantId, EventsCriteria criteria); @Override Alert getAlert(String tenantId, String alertId, boolean thin); @Override Page<Alert> getAlerts(String tenantId, AlertsCriteria criteria, Pager pager); @Override Page<Alert> getAlerts(Set<String> tenantIds, AlertsCriteria criteria, Pager pager); @Override Event getEvent(String tenantId, String eventId, boolean thin); @Override Page<Event> getEvents(String tenantId, EventsCriteria criteria, Pager pager); @Override Page<Event> getEvents(Set<String> tenantIds, EventsCriteria criteria, Pager pager); @Override void removeAlertTags(String tenantId, Collection<String> alertIds, Collection<String> tags); @Override void removeEventTags(String tenantId, Collection<String> eventIds, Collection<String> tags); @Override void resolveAlerts(String tenantId, Collection<String> alertIds, String resolvedBy, String resolvedNotes, List<Set<ConditionEval>> resolvedEvalSets); @Override void resolveAlertsForTrigger(String tenantId, String triggerId, String resolvedBy, String resolvedNotes, List<Set<ConditionEval>> resolvedEvalSets); @Override void sendData(Collection<Data> data); @Override void sendData(Collection<Data> data, boolean ignoreFiltering); @Override void sendEvents(Collection<Event> events); @Override void sendEvents(Collection<Event> events, boolean ignoreFiltering);  }
@Test public void queryAlertsByTriggerId() throws Exception { int numTenants = 2; int numTriggers = 5; int numAlerts = 5; createTestAlerts(numTenants, numTriggers, numAlerts); Set<String> tenantIds = new HashSet<>(); tenantIds.add("tenant0"); tenantIds.add("tenant1"); AlertsCriteria criteria = new AlertsCriteria(); criteria.setTriggerId("trigger0"); List<Alert> trigger0Alerts = alerts.getAlerts(tenantIds, criteria, null); assertEquals(10, trigger0Alerts.size()); criteria.setTriggerIds(Arrays.asList("trigger0", "trigger1", "trigger2")); List<Alert> trigger012Alerts = alerts.getAlerts(tenantIds, criteria, null); assertEquals(30, trigger012Alerts.size()); deleteTestAlerts(numTenants); }
@Test public void queryAlertsByCTime() throws Exception { int numTenants = 1; int numTriggers = 5; int numAlerts = 5; createTestAlerts(numTenants, numTriggers, numAlerts); Set<String> tenantIds = new HashSet<>(); tenantIds.add("tenant0"); AlertsCriteria criteria = new AlertsCriteria(); criteria.setStartTime(2L); criteria.setEndTime(2L); List<Alert> ctime2Alerts = alerts.getAlerts(tenantIds, criteria, null); assertEquals(5, ctime2Alerts.size()); criteria.setEndTime(null); List<Alert> ctimeGTE2Alerts = alerts.getAlerts(tenantIds, criteria, null); assertEquals(5 * 4, ctimeGTE2Alerts.size()); deleteTestAlerts(numTenants); }
@Test public void queryAlertsByResolvedTime() throws Exception { int numTenants = 1; int numTriggers = 5; int numAlerts = 5; createTestAlerts(numTenants, numTriggers, numAlerts); Set<String> tenantIds = new HashSet<>(); tenantIds.add("tenant0"); AlertsCriteria criteria = new AlertsCriteria(); criteria.setStartResolvedTime(1L); List<Alert> stimeGTE2Alerts = alerts.getAlerts(tenantIds, criteria, null); assertEquals(5 * 2, stimeGTE2Alerts.size()); deleteTestAlerts(numTenants); }
@Test public void queryAlertsByAcknowledgedTime() throws Exception { int numTenants = 1; int numTriggers = 5; int numAlerts = 5; createTestAlerts(numTenants, numTriggers, numAlerts); Set<String> tenantIds = new HashSet<>(); tenantIds.add("tenant0"); AlertsCriteria criteria = new AlertsCriteria(); criteria.setStartAckTime(1L); List<Alert> stimeGTE2Alerts = alerts.getAlerts(tenantIds, criteria, null); assertEquals(5 * 2, stimeGTE2Alerts.size()); deleteTestAlerts(numTenants); }
@Test public void queryAlertsByStatusTime() throws Exception { int numTenants = 1; int numTriggers = 5; int numAlerts = 5; createTestAlerts(numTenants, numTriggers, numAlerts); Set<String> tenantIds = new HashSet<>(); tenantIds.add("tenant0"); AlertsCriteria criteria = new AlertsCriteria(); criteria.setStartStatusTime(5L); criteria.setEndStatusTime(5L); List<Alert> stimeGTE5Alerts = alerts.getAlerts(tenantIds, criteria, null); assertEquals(5, stimeGTE5Alerts.size()); deleteTestAlerts(numTenants); }
@Test public void queryAlertsBySeverity() throws Exception { int numTenants = 1; int numTriggers = 5; int numAlerts = 5; createTestAlerts(numTenants, numTriggers, numAlerts); Set<String> tenantIds = new HashSet<>(); tenantIds.add("tenant0"); AlertsCriteria criteria = new AlertsCriteria(); criteria.setSeverities(Arrays.asList(Severity.LOW)); List<Alert> lowAlerts = alerts.getAlerts(tenantIds, criteria, null); assertEquals(5 * 2, lowAlerts.size()); criteria.setSeverities(Arrays.asList(Severity.CRITICAL)); List<Alert> criticalAlerts = alerts.getAlerts(tenantIds, criteria, null); assertEquals(5, criticalAlerts.size()); criteria.setSeverities(Arrays.asList(Severity.MEDIUM)); List<Alert> mediumAlerts = alerts.getAlerts(tenantIds, criteria, null); assertEquals(5 * 2, mediumAlerts.size()); criteria.setSeverities(Arrays.asList(Severity.MEDIUM, Severity.CRITICAL)); List<Alert> mediumCriticalAlerts = alerts.getAlerts(tenantIds, criteria, null); assertEquals(5 * 3, mediumCriticalAlerts.size()); deleteTestAlerts(numTenants); }
@Test public void queryAlertsByStatus() throws Exception { int numTenants = 1; int numTriggers = 5; int numAlerts = 5; createTestAlerts(numTenants, numTriggers, numAlerts); Set<String> tenantIds = new HashSet<>(); tenantIds.add("tenant0"); AlertsCriteria criteria = new AlertsCriteria(); criteria.setStatus(Alert.Status.OPEN); List<Alert> openAlerts = alerts.getAlerts(tenantIds, criteria, null); assertEquals(5, openAlerts.size()); criteria.setStatus(Alert.Status.ACKNOWLEDGED); List<Alert> acknowledgedAlerts = alerts.getAlerts(tenantIds, criteria, null); assertEquals(5 * 2, acknowledgedAlerts.size()); criteria.setStatus(Alert.Status.RESOLVED); List<Alert> resolvedAlerts = alerts.getAlerts(tenantIds, criteria, null); assertEquals(5 * 2, resolvedAlerts.size()); criteria.setStatusSet(Arrays.asList(Alert.Status.ACKNOWLEDGED, Alert.Status.RESOLVED)); List<Alert> ackResolvedAlerts = alerts.getAlerts(tenantIds, criteria, null); assertEquals(5 * 4, ackResolvedAlerts.size()); deleteTestAlerts(numTenants); }
@Test public void queryAlertsCombined() throws Exception { int numTenants = 1; int numTriggers = 5; int numAlerts = 5; createTestAlerts(numTenants, numTriggers, numAlerts); Set<String> tenantIds = new HashSet<>(); tenantIds.add("tenant0"); AlertsCriteria criteria = new AlertsCriteria(); criteria.setStatus(Alert.Status.RESOLVED); criteria.setTriggerId("trigger0"); criteria.setStartTime(3L); List<Alert> resolvedAlerts = alerts.getAlerts(tenantIds, criteria, null); assertEquals(1, resolvedAlerts.size()); deleteTestAlerts(numTenants); }