Class: NotificationModule

Inherits:
Object
  • Object
show all
Defined in:
lib/modules/slack_notifier/slack_notifier.rb,
lib/modules/rotation_emailer/rotation_emailer.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ NotificationModule

Returns a new instance of NotificationModule.



12
13
14
15
# File 'lib/modules/slack_notifier/slack_notifier.rb', line 12

def initialize(config)
  @config = config
  @log = Logging.logger['slack_notifier']
end

Instance Method Details

#runObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/modules/slack_notifier/slack_notifier.rb', line 17

def run

  c = @config

  @log.info ''
  @log.info 'Starting slack_notifier.rb logic...'

  # Load Template
  @log.info ''
  @log.info 'Loading message template from:'
  @log.info " #{c[:config]['message_template']}"

  message_template = open(c[:config]['message_template']).read

  # Populate Template
  b = binding
  b.local_variable_set(:data, c[:data])
  message = ERB.new(message_template).result(b)

  if c[:global]['dryrun']
    @log.info ''
    @log.info 'Not sending slack message because dryrun is enabled.'
    @log.info 'Would have posted the following message:'
    @log.info ''
    @log.info '--- MESSAGE START ---'
    message.each_line do |line|
      @log.info " #{line.chomp}"
    end
    @log.info '--- MESSAGE END ---'
  else
    # Send The Emails
    @log.info ''
    @log.info 'Posting Message to Slack...'
    @log.info " Channel: #{c[:config]['channel']} "
    @log.info " Username: #{c[:config]['username']} "

    notifier = Slack::Notifier.new "#{c[:config]['webhook']}" do
      defaults channel: "#{c[:config]['channel']}",
               username: "#{c[:config]['username']}"
    end
    notifier.ping message
  end
  @log.info ''
  @log.info ' Finished slack_notifier.rb logic.'
end