diff --git a/src/main/java/org/elasticsearch/alerts/AlertManager.java b/src/main/java/org/elasticsearch/alerts/AlertManager.java index 51f39304754..c284d52718a 100644 --- a/src/main/java/org/elasticsearch/alerts/AlertManager.java +++ b/src/main/java/org/elasticsearch/alerts/AlertManager.java @@ -134,7 +134,6 @@ public class AlertManager extends AbstractComponent { throw new ElasticsearchException("Alert is not available"); } TriggerResult triggerResult = triggerManager.isTriggered(alert, entry.getScheduledTime(), entry.getFireTime()); - entry.setSearchRequest(triggerResult.getRequest()); entry.setSearchResponse(triggerResult.getResponse()); if (triggerResult.isTriggered()) { entry.setTriggered(true); diff --git a/src/main/java/org/elasticsearch/alerts/actions/AlertActionEntry.java b/src/main/java/org/elasticsearch/alerts/actions/AlertActionEntry.java index baa2bbadf06..dc22eb36ad3 100644 --- a/src/main/java/org/elasticsearch/alerts/actions/AlertActionEntry.java +++ b/src/main/java/org/elasticsearch/alerts/actions/AlertActionEntry.java @@ -31,9 +31,9 @@ public class AlertActionEntry implements ToXContent { private AlertTrigger trigger; private List actions; private AlertActionState entryState; + private SearchRequest searchRequest; /*Optional*/ - private SearchRequest searchRequest; private Map searchResponse; private boolean triggered; private String errorMsg; @@ -50,6 +50,7 @@ public class AlertActionEntry implements ToXContent { this.trigger = alert.trigger(); this.actions = alert.actions(); this.entryState = state; + this.searchRequest = alert.getSearchRequest(); } /** @@ -188,7 +189,10 @@ public class AlertActionEntry implements ToXContent { historyEntry.field("triggered", triggered); historyEntry.field("fire_time", fireTime.toDateTimeISO()); historyEntry.field(AlertActionManager.SCHEDULED_FIRE_TIME_FIELD, scheduledTime.toDateTimeISO()); - historyEntry.field("trigger", trigger, params); + historyEntry.field("trigger"); + historyEntry.startObject(); + historyEntry.field(trigger.getTriggerName(), trigger, params); + historyEntry.endObject(); historyEntry.field("request"); AlertUtils.writeSearchRequest(searchRequest, historyEntry, params); historyEntry.field("response", searchResponse); diff --git a/src/main/java/org/elasticsearch/alerts/actions/AlertActionManager.java b/src/main/java/org/elasticsearch/alerts/actions/AlertActionManager.java index 9d21d89b12b..98ec5c77802 100644 --- a/src/main/java/org/elasticsearch/alerts/actions/AlertActionManager.java +++ b/src/main/java/org/elasticsearch/alerts/actions/AlertActionManager.java @@ -196,6 +196,7 @@ public class AlertActionManager extends AbstractComponent { String currentFieldName = null; XContentParser.Token token = parser.nextToken(); assert token == XContentParser.Token.START_OBJECT; + logger.error("source [{}]",source.toUtf8()); while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); @@ -240,7 +241,11 @@ public class AlertActionManager extends AbstractComponent { throw new ElasticsearchIllegalArgumentException("Unexpected field [" + currentFieldName + "]"); } } else { - throw new ElasticsearchIllegalArgumentException("Unexpected token [" + token + "]"); + if (token == XContentParser.Token.VALUE_NULL) { + logger.warn("Got null value for [{}]", currentFieldName); + } else { + throw new ElasticsearchIllegalArgumentException("Unexpected token [" + token + "] for [" + currentFieldName + "]"); + } } } } catch (IOException e) {