summaryrefslogtreecommitdiff
path: root/lib/oxidized/hook/awssns.rb
diff options
context:
space:
mode:
authorytti <saku@ytti.fi>2016-12-04 19:38:25 +0200
committerGitHub <noreply@github.com>2016-12-04 19:38:25 +0200
commitb2e53088e457babfbfec74a03e730b3d91b9701f (patch)
treef9aa3515d2d7bef8ca6e120b51d3f830c67cbdf0 /lib/oxidized/hook/awssns.rb
parente0da3feeb2fc506af31df0b41e14a3f9c588ef82 (diff)
parent0e26ca4e877570b5ba02370768fcd758c4b03cc8 (diff)
Merge pull request #628 from natm/master
New hook: awssns - Publish messages to AWS SNS topics
Diffstat (limited to 'lib/oxidized/hook/awssns.rb')
-rw-r--r--lib/oxidized/hook/awssns.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/oxidized/hook/awssns.rb b/lib/oxidized/hook/awssns.rb
new file mode 100644
index 0000000..dbc2d47
--- /dev/null
+++ b/lib/oxidized/hook/awssns.rb
@@ -0,0 +1,27 @@
+require 'aws-sdk'
+
+class AwsSns < Oxidized::Hook
+ def validate_cfg!
+ raise KeyError, 'hook.region is required' unless cfg.has_key?('region')
+ raise KeyError, 'hook.topic_arn is required' unless cfg.has_key?('topic_arn')
+ end
+
+ def run_hook(ctx)
+ sns = Aws::SNS::Resource.new(region: cfg.region)
+ topic = sns.topic(cfg.topic_arn)
+ message = {
+ :event => ctx.event.to_s
+ }
+ if ctx.node
+ message.merge!(
+ :group => ctx.node.group.to_s,
+ :model => ctx.node.model.class.name.to_s.downcase,
+ :node => ctx.node.name.to_s
+ )
+ end
+ topic.publish({
+ message: message.to_json
+ })
+ end
+
+end