Skip to content
This repository was archived by the owner on Apr 12, 2018. It is now read-only.

Added basic slack action support #20

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Nest.Watcher/Domain/Action/ActionType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public enum ActionType
[EnumMember(Value = "logging")]
Logging,
[EnumMember(Value = "webhook")]
Webhook
}
Webhook,
[EnumMember(Value = "slack")]
Slack
}
}
28 changes: 28 additions & 0 deletions src/Nest.Watcher/Domain/Action/SlackAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Collections.Generic;
using Nest.Resolvers.Converters;
using Newtonsoft.Json;

namespace Nest
{
[JsonObject]
[JsonConverter(typeof(ReadAsTypeConverter<SlackAction>))]
public interface ISlackAction : IAction
{
}

public class SlackAction : Action, ISlackAction
{
public string Account { get; set; }
public Message Message { get; set; }
}

[JsonObject]
public class Message
{
[JsonProperty("to")]
public IList<string> To { get; set; }

[JsonProperty("text")]
public string Text { get; set; }
}
}
1 change: 1 addition & 0 deletions src/Nest.Watcher/Nest.Watcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<Compile Include="Domain\ActionExecution\ExecutionResult.cs" />
<Compile Include="Domain\Action\Action.cs" />
<Compile Include="Domain\Action\ActionType.cs" />
<Compile Include="Domain\Action\SlackAction.cs" />
<Compile Include="Domain\Condition\CompareCondition.cs" />
<Compile Include="Domain\ActionExecution\ActionExecutionMode.cs" />
<Compile Include="Domain\Enums\LogLevel.cs" />
Expand Down
4 changes: 3 additions & 1 deletion src/Nest.Watcher/Serialization/ActionDictionaryConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
WriteActionEntry(kvp.Key, "webhook", kvp.Value, writer, serializer);
else if (kvp.Value is ILoggingAction)
WriteActionEntry(kvp.Key, "logging", kvp.Value, writer, serializer);
else
else if (kvp.Value is ISlackAction)
WriteActionEntry(kvp.Key, "slack", kvp.Value, writer, serializer);
else
throw new ArgumentException("Unknown IAction type");
}
writer.WriteEndObject();
Expand Down
40 changes: 39 additions & 1 deletion src/Tests/Nest.Watcher.Tests.Unit/Put/PutActionsJsonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,43 @@ public void WebHook()
this.JsonEquals(expectedRequest, response);
}

}
[Test]
public void SlackAction()
{
var expectedRequest = new
{
actions = new
{
slack = new
{
slack = new
{
account = "slackAccount",
message = new
{
to = new[] { "#general" },
text = "Testing Slack Watcher Integration"
}
}
}
}
};
var response = this.Client.PutWatch("some-watch", p => p
.Actions(a => a
.Add("slack", new SlackAction
{
Account = "slackAccount",
Message = new Message
{
Text = "Testing Slack Watcher Integration",
To = new[] { "#general" }
}
})
)
);
this.JsonEquals(expectedRequest, response);
}


}
}