Class: AwsSns

Inherits:
Oxidized::Hook show all
Defined in:
lib/oxidized/hook/awssns.rb

Instance Attribute Summary

Attributes inherited from Oxidized::Hook

#cfg

Instance Method Summary collapse

Methods inherited from Oxidized::Hook

#log

Instance Method Details

#run_hook(ctx) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/oxidized/hook/awssns.rb', line 9

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

#validate_cfg!Object

Raises:

  • (KeyError)


4
5
6
7
# File 'lib/oxidized/hook/awssns.rb', line 4

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