Class: NotificationModule
- Inherits:
-
Object
- Object
- NotificationModule
- Defined in:
- lib/modules/slack_notifier/slack_notifier.rb,
lib/modules/rotation_emailer/rotation_emailer.rb
Instance Method Summary collapse
-
#initialize(config) ⇒ NotificationModule
constructor
A new instance of NotificationModule.
- #run ⇒ Object
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
#run ⇒ Object
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']}" = open(c[:config]['message_template']).read # Populate Template b = binding b.local_variable_set(:data, c[:data]) = ERB.new().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 ---' .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 end @log.info '' @log.info ' Finished slack_notifier.rb logic.' end |