77
88namespace Nest
99{
10+ /// <summary>
11+ /// A Watcher action
12+ /// </summary>
1013 [ InterfaceDataContract ]
1114 public interface IAction
1215 {
16+ /// <summary>
17+ /// The type of action
18+ /// </summary>
1319 [ IgnoreDataMember ]
1420 ActionType ActionType { get ; }
1521
22+ /// <summary>
23+ /// The name of the action
24+ /// </summary>
1625 [ IgnoreDataMember ]
1726 string Name { get ; set ; }
1827
28+ /// <summary>
29+ /// Limit how often an action is executed, after it has been executed.
30+ /// When a throttling period is set, repeated executions of the action are prevented if it has already
31+ /// executed within the throttling period time frame (now - throttling period).
32+ /// </summary>
1933 [ IgnoreDataMember ]
2034 Time ThrottlePeriod { get ; set ; }
2135
22- [ DataMember ( Name = "transform" ) ]
36+ /// <summary>
37+ /// Trigger the configured action for every element within an array
38+ /// defined by the path assigned.
39+ /// <para />
40+ /// Valid only in Elasticsearch 7.3.0+
41+ /// </summary>
42+ [ IgnoreDataMember ]
43+ string Foreach { get ; set ; }
44+
45+ /// <summary>
46+ /// Transforms the payload before executing the action. The transformation is only applied
47+ /// for the payload for this action.
48+ /// </summary>
49+ [ IgnoreDataMember ]
2350 TransformContainer Transform { get ; set ; }
51+
52+ /// <summary>
53+ /// A condition for the action. Allows a single watch to specify multiple actions, but
54+ /// further control when each action will be executed.
55+ /// </summary>
56+ [ IgnoreDataMember ]
57+ ConditionContainer Condition { get ; set ; }
2458 }
2559
60+ /// <inheritdoc />
2661 public abstract class ActionBase : IAction
2762 {
2863 internal ActionBase ( ) { }
@@ -31,12 +66,21 @@ internal ActionBase() { }
3166
3267 public abstract ActionType ActionType { get ; }
3368
69+ /// <inheritdoc />
3470 public string Name { get ; set ; }
3571
72+ /// <inheritdoc />
3673 public Time ThrottlePeriod { get ; set ; }
3774
75+ /// <inheritdoc />
76+ public string Foreach { get ; set ; }
77+
78+ /// <inheritdoc />
3879 public TransformContainer Transform { get ; set ; }
3980
81+ /// <inheritdoc />
82+ public ConditionContainer Condition { get ; set ; }
83+
4084 public static bool operator false( ActionBase a ) => false ;
4185
4286 public static bool operator true( ActionBase a ) => false ;
@@ -78,7 +122,10 @@ internal class ActionsFormatter : IJsonFormatter<Actions>
78122 { "index" , 3 } ,
79123 { "logging" , 4 } ,
80124 { "slack" , 5 } ,
81- { "pagerduty" , 6 }
125+ { "pagerduty" , 6 } ,
126+ { "foreach" , 7 } ,
127+ { "transform" , 8 } ,
128+ { "condition" , 9 }
82129 } ;
83130
84131 public Actions Deserialize ( ref JsonReader reader , IJsonFormatterResolver formatterResolver )
@@ -92,6 +139,10 @@ public Actions Deserialize(ref JsonReader reader, IJsonFormatterResolver formatt
92139
93140 Time throttlePeriod = null ;
94141 IAction action = null ;
142+ string @foreach = null ;
143+ TransformContainer transform = null ;
144+ ConditionContainer condition = null ;
145+
95146 while ( reader . ReadIsInObject ( ref actionCount ) )
96147 {
97148 var propertyName = reader . ReadPropertyNameSegmentRaw ( ) ;
@@ -128,6 +179,17 @@ public Actions Deserialize(ref JsonReader reader, IJsonFormatterResolver formatt
128179 action = formatterResolver . GetFormatter < PagerDutyAction > ( )
129180 . Deserialize ( ref reader , formatterResolver ) ;
130181 break ;
182+ case 7 :
183+ @foreach = reader . ReadString ( ) ;
184+ break ;
185+ case 8 :
186+ transform = formatterResolver . GetFormatter < TransformContainer > ( )
187+ . Deserialize ( ref reader , formatterResolver ) ;
188+ break ;
189+ case 9 :
190+ condition = formatterResolver . GetFormatter < ConditionContainer > ( )
191+ . Deserialize ( ref reader , formatterResolver ) ;
192+ break ;
131193 }
132194 }
133195 else
@@ -138,6 +200,9 @@ public Actions Deserialize(ref JsonReader reader, IJsonFormatterResolver formatt
138200 {
139201 action . Name = name ;
140202 action . ThrottlePeriod = throttlePeriod ;
203+ action . Foreach = @foreach ;
204+ action . Transform = transform ;
205+ action . Condition = condition ;
141206 dictionary . Add ( name , action ) ;
142207 }
143208 }
@@ -166,6 +231,28 @@ public void Serialize(ref JsonWriter writer, Actions value, IJsonFormatterResolv
166231 timeFormatter . Serialize ( ref writer , action . ThrottlePeriod , formatterResolver ) ;
167232 writer . WriteValueSeparator ( ) ;
168233 }
234+
235+ if ( ! string . IsNullOrEmpty ( action . Foreach ) )
236+ {
237+ writer . WritePropertyName ( "foreach" ) ;
238+ writer . WriteString ( action . Foreach ) ;
239+ writer . WriteValueSeparator ( ) ;
240+ }
241+
242+ if ( action . Transform != null )
243+ {
244+ writer . WritePropertyName ( "transform" ) ;
245+ formatterResolver . GetFormatter < TransformContainer > ( ) . Serialize ( ref writer , action . Transform , formatterResolver ) ;
246+ writer . WriteValueSeparator ( ) ;
247+ }
248+
249+ if ( action . Condition != null )
250+ {
251+ writer . WritePropertyName ( "condition" ) ;
252+ formatterResolver . GetFormatter < ConditionContainer > ( ) . Serialize ( ref writer , action . Condition , formatterResolver ) ;
253+ writer . WriteValueSeparator ( ) ;
254+ }
255+
169256 writer . WritePropertyName ( kvp . Value . ActionType . GetStringValue ( ) ) ;
170257
171258 switch ( action . ActionType )
0 commit comments