Skip to content

Commit c81a573

Browse files
committed
Merge branch 'fix/watcher-email-tests-pre-2.3' into 2.x
2 parents d377118 + 51c77f8 commit c81a573

File tree

9 files changed

+1132
-327
lines changed

9 files changed

+1132
-327
lines changed

src/Nest/Nest.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,7 @@
12651265
<Compile Include="XPack\Watcher\Action\ActionBase.cs" />
12661266
<Compile Include="XPack\Watcher\Action\ActionsDescriptorBase.cs" />
12671267
<Compile Include="XPack\Watcher\Action\ActionType.cs" />
1268+
<Compile Include="XPack\Watcher\Action\Email\AttachData.cs" />
12681269
<Compile Include="XPack\Watcher\Action\Email\DataAttachment.cs" />
12691270
<Compile Include="XPack\Watcher\Action\Email\EmailAction.cs" />
12701271
<Compile Include="XPack\Watcher\Action\Email\EmailAttachments.cs" />

src/Nest/XPack/Watcher/Action/Actions.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ public ActionsDescriptor() : base(new Actions())
7474
{
7575
}
7676

77+
/// <summary>
78+
/// A watch action that sends email notifications.
79+
/// To use the email action, you must configure at least one email account.
80+
/// </summary>
7781
public ActionsDescriptor Email(string name, Func<EmailActionDescriptor, IEmailAction> selector) =>
7882
Assign(name, selector.InvokeOrDefault(new EmailActionDescriptor(name)));
7983

@@ -86,6 +90,13 @@ public ActionsDescriptor Index(string name, Func<IndexActionDescriptor, IIndexAc
8690
public ActionsDescriptor Logging(string name, Func<LoggingActionDescriptor, ILoggingAction> selector) =>
8791
Assign(name, selector.InvokeOrDefault(new LoggingActionDescriptor(name)));
8892

93+
/// <summary>
94+
/// A watch action that creates events in PagerDuty.
95+
/// To use the PagerDuty action, you need to configure at least one PagerDuty account in Watcher.
96+
/// </summary>
97+
/// <remarks>
98+
/// Only available in Watcher 2.3 and up
99+
/// </remarks>
89100
public ActionsDescriptor PagerDuty(string name, Func<PagerDutyActionDescriptor, IPagerDutyAction> selector) =>
90101
Assign(name, selector.InvokeOrDefault(new PagerDutyActionDescriptor(name)));
91102

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Nest
4+
{
5+
[JsonObject]
6+
public class AttachData
7+
{
8+
[JsonProperty("format")]
9+
public DataAttachmentFormat Format { get; set; }
10+
}
11+
}

src/Nest/XPack/Watcher/Action/Email/EmailAction.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
namespace Nest
66
{
7+
/// <summary>
8+
/// A watch action that sends email notifications.
9+
/// To use the email action, you must configure at least one email account.
10+
/// </summary>
711
[JsonObject]
812
public interface IEmailAction : IAction
913
{
@@ -36,8 +40,16 @@ public interface IEmailAction : IAction
3640

3741
[JsonProperty("attachments")]
3842
IEmailAttachments Attachments { get; set; }
43+
44+
[JsonProperty("attach_data")]
45+
[Obsolete("Deprecated in Watcher 2.3. Use Attachments to set Attachment data")]
46+
Union<bool?, AttachData> AttachData { get; set; }
3947
}
4048

49+
/// <summary>
50+
/// A watch action that sends email notifications.
51+
/// To use the email action, you must configure at least one email account.
52+
/// </summary>
4153
public class EmailAction : ActionBase, IEmailAction
4254
{
4355
public override ActionType ActionType => ActionType.Email;
@@ -62,9 +74,28 @@ public EmailAction(string name) : base(name) {}
6274

6375
public EmailPriority? Priority { get; set; }
6476

77+
/// <summary>
78+
/// Attaches an attachment to the email
79+
/// </summary>
80+
/// <remarks>
81+
/// Only available in Watcher 2.3 and up
82+
/// </remarks>
6583
public IEmailAttachments Attachments { get; set; }
84+
85+
/// <summary>
86+
/// Indicates whether the watch execution data should be attached to the email.
87+
/// If set to <c>true</c>, the data is attached as a YAML file called data.yml.
88+
/// If it’s set to <c>false</c>, no data is attached.
89+
/// To attach data and control the format of the attached data, assign <see cref="AttachData"/>
90+
/// </summary>
91+
[Obsolete("Deprecated in Watcher 2.3. Use Attachments to set Attachment data")]
92+
public Union<bool?, AttachData> AttachData { get; set; }
6693
}
6794

95+
/// <summary>
96+
/// A watch action that sends email notifications.
97+
/// To use the email action, you must configure at least one email account.
98+
/// </summary>
6899
public class EmailActionDescriptor : ActionsDescriptorBase<EmailActionDescriptor, IEmailAction>, IEmailAction
69100
{
70101
public EmailActionDescriptor(string name) : base(name) {}
@@ -81,6 +112,7 @@ public EmailActionDescriptor(string name) : base(name) {}
81112
IEmailBody IEmailAction.Body { get; set; }
82113
EmailPriority? IEmailAction.Priority { get; set; }
83114
IEmailAttachments IEmailAction.Attachments { get; set; }
115+
Union<bool?, AttachData> IEmailAction.AttachData { get; set; }
84116

85117
public EmailActionDescriptor Account(string account) => Assign(a => a.Account = account);
86118

@@ -109,7 +141,27 @@ public EmailActionDescriptor Body(Func<EmailBodyDescriptor, IEmailBody> selector
109141

110142
public EmailActionDescriptor Priority(EmailPriority priority) => Assign(a => a.Priority = priority);
111143

144+
/// <summary>
145+
/// Attach an attachment to the email, only available since watcher 2.3 and up.
146+
/// </summary>
112147
public EmailActionDescriptor Attachments(Func<EmailAttachmentsDescriptor, IPromise<IEmailAttachments>> selector) =>
113148
Assign(a => a.Attachments = selector?.Invoke(new EmailAttachmentsDescriptor())?.Value);
149+
150+
/// <summary>
151+
/// Indicates whether the watch execution data should be attached to the email.
152+
/// If set to <c>true</c>, the data is attached as a YAML file called data.yml.
153+
/// If it’s set to <c>false</c>, no data is attached.
154+
/// To attach data and control the format of the attached data, use <see cref="AttachData(DataAttachmentFormat)"/>
155+
/// </summary>
156+
[Obsolete("Deprecated in Watcher 2.3. Use Attachments to set Attachment data")]
157+
public EmailActionDescriptor AttachData(bool attach = true) =>
158+
Assign(a => a.AttachData = attach);
159+
160+
/// <summary>
161+
/// Indicates to attach the watch execution data attached to the email and the format.
162+
/// </summary>
163+
[Obsolete("Deprecated in Watcher 2.3. Use Attachments to set Attachment data")]
164+
public EmailActionDescriptor AttachData(DataAttachmentFormat format) =>
165+
Assign(a => a.AttachData = new AttachData { Format = format });
114166
}
115167
}

src/Nest/XPack/Watcher/Action/PagerDuty/PagerDutyAction.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,25 @@
66

77
namespace Nest
88
{
9+
/// <summary>
10+
/// A watch action that creates events in PagerDuty.
11+
/// To use the PagerDuty action, you need to configure at least one PagerDuty account in Watcher.
12+
/// </summary>
13+
/// <remarks>
14+
/// Only available in Watcher 2.3 and up
15+
/// </remarks>
916
[JsonObject]
1017
public interface IPagerDutyAction : IAction, IPagerDutyEvent
1118
{
1219
}
1320

21+
/// <summary>
22+
/// A watch action that creates events in PagerDuty.
23+
/// To use the PagerDuty action, you need to configure at least one PagerDuty account in Watcher.
24+
/// </summary>
25+
/// <remarks>
26+
/// Only available in Watcher 2.3 and up
27+
/// </remarks>
1428
public class PagerDutyAction : ActionBase, IPagerDutyAction
1529
{
1630
public override ActionType ActionType => ActionType.PagerDuty;
@@ -36,6 +50,13 @@ public PagerDutyAction(string name) : base(name)
3650
}
3751
}
3852

53+
/// <summary>
54+
/// A watch action that creates events in PagerDuty.
55+
/// To use the PagerDuty action, you need to configure at least one PagerDuty account in Watcher.
56+
/// </summary>
57+
/// <remarks>
58+
/// Only available in Watcher 2.3 and up
59+
/// </remarks>
3960
public class PagerDutyActionDescriptor : ActionsDescriptorBase<PagerDutyActionDescriptor, IPagerDutyAction>, IPagerDutyAction
4061
{
4162
protected override ActionType ActionType => ActionType.PagerDuty;

src/Nest/XPack/Watcher/Input/ChainInput.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ namespace Nest
77
/// <summary>
88
/// input to load data from multiple sources into the watch execution context when the watch is triggered.
99
/// </summary>
10+
/// <remarks>
11+
/// Only available in Watcher 2.1 onwards
12+
/// </remarks>
1013
[JsonObject]
1114
[JsonConverter(typeof(ChainInputJsonConverter))]
1215
public interface IChainInput : IInput
@@ -17,7 +20,12 @@ public interface IChainInput : IInput
1720
IDictionary<string, InputContainer> Inputs { get; set; }
1821
}
1922

20-
/// <inheritdoc />
23+
/// <summary>
24+
/// input to load data from multiple sources into the watch execution context when the watch is triggered.
25+
/// </summary>
26+
/// <remarks>
27+
/// Only available in Watcher 2.1 onwards
28+
/// </remarks>
2129
public class ChainInput : InputBase, IChainInput
2230
{
2331
public ChainInput() {}
@@ -33,7 +41,12 @@ public ChainInput(IDictionary<string, InputContainer> inputs)
3341
internal override void WrapInContainer(IInputContainer container) => container.Chain = this;
3442
}
3543

36-
/// <inheritdoc />
44+
/// <summary>
45+
/// input to load data from multiple sources into the watch execution context when the watch is triggered.
46+
/// </summary>
47+
/// <remarks>
48+
/// Only available in Watcher 2.1 onwards
49+
/// </remarks>
3750
public class ChainInputDescriptor : DescriptorBase<ChainInputDescriptor, IChainInput>, IChainInput
3851
{
3952
public ChainInputDescriptor() {}

src/Nest/XPack/Watcher/Input/InputContainer.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ public interface IInputContainer
1616
[JsonProperty("simple")]
1717
ISimpleInput Simple { get; set; }
1818

19+
/// <summary>
20+
/// input to load data from multiple sources into the watch execution context when the watch is triggered.
21+
/// </summary>
22+
/// <remarks>
23+
/// Only available in Watcher 2.1 onwards
24+
/// </remarks>
1925
[JsonProperty("chain")]
2026
IChainInput Chain { get; set; }
2127
}
@@ -54,6 +60,12 @@ public InputDescriptor Http(Func<HttpInputDescriptor, IHttpInput> selector) =>
5460
public InputDescriptor Simple(Func<SimpleInputDescriptor, ISimpleInput> selector) =>
5561
Assign(a => a.Simple = selector.Invoke(new SimpleInputDescriptor()));
5662

63+
/// <summary>
64+
/// input to load data from multiple sources into the watch execution context when the watch is triggered.
65+
/// </summary>
66+
/// <remarks>
67+
/// Only available in Watcher 2.1 onwards
68+
/// </remarks>
5769
public InputDescriptor Chain(Func<ChainInputDescriptor, IChainInput> selector) =>
5870
Assign(a => a.Chain = selector.Invoke(new ChainInputDescriptor()));
5971
}

src/Tests/XPack/Watcher/ExecuteWatch/ExecuteWatchApiTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Tests.XPack.Watcher.ExecuteWatch
1313
{
14+
[SkipVersion("<2.3.0", "Email action has no attachments and pagerduty action does not exist in these versions")]
1415
public class ExecuteWatchApiTests : ApiIntegrationTestBase<XPackCluster, IExecuteWatchResponse, IExecuteWatchRequest, ExecuteWatchDescriptor, ExecuteWatchRequest>
1516
{
1617
private readonly DateTimeOffset _triggeredDateTime = new DateTimeOffset(2016, 11, 17, 13, 00, 00, TimeSpan.Zero);

0 commit comments

Comments
 (0)