7
7
8
8
namespace Nest
9
9
{
10
+ /// <summary>
11
+ /// A Watcher action
12
+ /// </summary>
10
13
[ InterfaceDataContract ]
11
14
public interface IAction
12
15
{
16
+ /// <summary>
17
+ /// The type of action
18
+ /// </summary>
13
19
[ IgnoreDataMember ]
14
20
ActionType ActionType { get ; }
15
21
22
+ /// <summary>
23
+ /// The name of the action
24
+ /// </summary>
16
25
[ IgnoreDataMember ]
17
26
string Name { get ; set ; }
18
27
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>
19
33
[ IgnoreDataMember ]
20
34
Time ThrottlePeriod { get ; set ; }
21
35
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 ]
23
50
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 ; }
24
58
}
25
59
60
+ /// <inheritdoc />
26
61
public abstract class ActionBase : IAction
27
62
{
28
63
internal ActionBase ( ) { }
@@ -31,12 +66,21 @@ internal ActionBase() { }
31
66
32
67
public abstract ActionType ActionType { get ; }
33
68
69
+ /// <inheritdoc />
34
70
public string Name { get ; set ; }
35
71
72
+ /// <inheritdoc />
36
73
public Time ThrottlePeriod { get ; set ; }
37
74
75
+ /// <inheritdoc />
76
+ public string Foreach { get ; set ; }
77
+
78
+ /// <inheritdoc />
38
79
public TransformContainer Transform { get ; set ; }
39
80
81
+ /// <inheritdoc />
82
+ public ConditionContainer Condition { get ; set ; }
83
+
40
84
public static bool operator false( ActionBase a ) => false ;
41
85
42
86
public static bool operator true( ActionBase a ) => false ;
@@ -78,7 +122,10 @@ internal class ActionsFormatter : IJsonFormatter<Actions>
78
122
{ "index" , 3 } ,
79
123
{ "logging" , 4 } ,
80
124
{ "slack" , 5 } ,
81
- { "pagerduty" , 6 }
125
+ { "pagerduty" , 6 } ,
126
+ { "foreach" , 7 } ,
127
+ { "transform" , 8 } ,
128
+ { "condition" , 9 }
82
129
} ;
83
130
84
131
public Actions Deserialize ( ref JsonReader reader , IJsonFormatterResolver formatterResolver )
@@ -92,6 +139,10 @@ public Actions Deserialize(ref JsonReader reader, IJsonFormatterResolver formatt
92
139
93
140
Time throttlePeriod = null ;
94
141
IAction action = null ;
142
+ string @foreach = null ;
143
+ TransformContainer transform = null ;
144
+ ConditionContainer condition = null ;
145
+
95
146
while ( reader . ReadIsInObject ( ref actionCount ) )
96
147
{
97
148
var propertyName = reader . ReadPropertyNameSegmentRaw ( ) ;
@@ -128,6 +179,17 @@ public Actions Deserialize(ref JsonReader reader, IJsonFormatterResolver formatt
128
179
action = formatterResolver . GetFormatter < PagerDutyAction > ( )
129
180
. Deserialize ( ref reader , formatterResolver ) ;
130
181
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 ;
131
193
}
132
194
}
133
195
else
@@ -138,6 +200,9 @@ public Actions Deserialize(ref JsonReader reader, IJsonFormatterResolver formatt
138
200
{
139
201
action . Name = name ;
140
202
action . ThrottlePeriod = throttlePeriod ;
203
+ action . Foreach = @foreach ;
204
+ action . Transform = transform ;
205
+ action . Condition = condition ;
141
206
dictionary . Add ( name , action ) ;
142
207
}
143
208
}
@@ -166,6 +231,28 @@ public void Serialize(ref JsonWriter writer, Actions value, IJsonFormatterResolv
166
231
timeFormatter . Serialize ( ref writer , action . ThrottlePeriod , formatterResolver ) ;
167
232
writer . WriteValueSeparator ( ) ;
168
233
}
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
+
169
256
writer . WritePropertyName ( kvp . Value . ActionType . GetStringValue ( ) ) ;
170
257
171
258
switch ( action . ActionType )
0 commit comments