@Override
protected CheckResult runCheck() {
this.searchHits = Collections.emptyList();
try {
String filter = "streams:" + stream.getId();
CountResult result = searches.count("*", new RelativeRange(time * 60), filter);
long count = result.getCount();
LOG.debug("Alert check <{}> result: [{}]", id, count);
boolean triggered = false;
switch (thresholdType) {
case MORE:
triggered = count > threshold;
break;
case LESS:
triggered = count < threshold;
break;
}
if (triggered) {
Integer backlogSize = getBacklog();
if (backlogSize != null && backlogSize > 0) {
SearchResult backlogResult = searches.search("*", filter, new RelativeRange(time * 60), backlogSize, 0, new Sorting("timestamp", Sorting.Direction.DESC));
this.searchHits = Lists.newArrayList();
for (ResultMessage resultMessage : backlogResult.getResults()) {
searchHits.add(new Message(resultMessage.getMessage()));
}
}