diff --git a/src/main/java/org/elasticsearch/watcher/condition/ConditionRegistry.java b/src/main/java/org/elasticsearch/watcher/condition/ConditionRegistry.java index feeab65dfdb..328322f4cbd 100644 --- a/src/main/java/org/elasticsearch/watcher/condition/ConditionRegistry.java +++ b/src/main/java/org/elasticsearch/watcher/condition/ConditionRegistry.java @@ -7,6 +7,8 @@ package org.elasticsearch.watcher.condition; import org.elasticsearch.common.collect.ImmutableMap; import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import java.io.IOException; @@ -83,6 +85,7 @@ public class ConditionRegistry { * Parses the xcontent and returns the appropriate condition result. Expecting the following format: *
      *     {
+     *         "met" : true | false,
      *         "condition_type" : {
      *             ...              // result body
      *         }
@@ -92,17 +95,19 @@ public class ConditionRegistry {
     public Condition.Result parseResult(String watchId, XContentParser parser) throws IOException {
         Condition.Result result = null;
 
-        String type = null;
+        String currentFieldName = null;
         XContentParser.Token token;
         while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
             if (token == XContentParser.Token.FIELD_NAME) {
-                type = parser.currentName();
-            } else if (type == null) {
+                currentFieldName = parser.currentName();
+            } else if (currentFieldName == null) {
                 throw new ConditionException("could not parse condition result for watch [{}]. invalid definition. expected a field indicating the condition type, but found", watchId, token);
+            } else if (Condition.Field.MET.match(currentFieldName)) {
+                // we do nothing for now here.... the condition will still parse its state in the type itself
             } else {
-                ConditionFactory factory = factories.get(type);
+                ConditionFactory factory = factories.get(currentFieldName);
                 if (factory == null) {
-                    throw new ConditionException("could not parse condition result for watch [{}]. un known condition type [{}]", watchId, type);
+                    throw new ConditionException("could not parse condition result for watch [{}]. un known condition type [{}]", watchId, currentFieldName);
                 }
                 result = factory.parseResult(watchId, parser);
             }
@@ -113,4 +118,10 @@ public class ConditionRegistry {
         return result;
     }
 
+    public static void writeResult(Condition.Result result, XContentBuilder builder, ToXContent.Params params) throws IOException {
+        builder.startObject()
+                .field(Condition.Field.MET.getPreferredName(), result.met())
+                .field(result.type(), result, params)
+                .endObject();
+    }
 }
diff --git a/src/main/java/org/elasticsearch/watcher/execution/WatchExecutionResult.java b/src/main/java/org/elasticsearch/watcher/execution/WatchExecutionResult.java
index d4654988901..09e78f353c8 100644
--- a/src/main/java/org/elasticsearch/watcher/execution/WatchExecutionResult.java
+++ b/src/main/java/org/elasticsearch/watcher/execution/WatchExecutionResult.java
@@ -86,9 +86,8 @@ public class WatchExecutionResult implements ToXContent {
                     .endObject();
         }
         if (conditionResult != null) {
-            builder.startObject(Field.CONDITION.getPreferredName())
-                    .field(conditionResult.type(), conditionResult, params)
-                    .endObject();
+            builder.field(Field.CONDITION.getPreferredName());
+            ConditionRegistry.writeResult(conditionResult, builder, params);
         }
         if (throttleResult != null && throttleResult.throttle()) {
             builder.field(Field.THROTTLED.getPreferredName(), throttleResult.throttle());
diff --git a/src/main/resources/watch_history.json b/src/main/resources/watch_history.json
index 9bc67c50a50..85d57560952 100644
--- a/src/main/resources/watch_history.json
+++ b/src/main/resources/watch_history.json
@@ -139,6 +139,14 @@
                 "script" : {
                   "type" : "object",
                   "enabled" : false
+                },
+                "always" : {
+                  "type" : "object",
+                  "enabled" : false
+                },
+                "never" : {
+                  "type" : "object",
+                  "enabled" : false
                 }
               }
             },