class SensuPluginsRocketchat::ContentGenerator

Generates notification body from event data

Public Class Methods

new(event) click to toggle source
# File lib/sensu-plugins-rocketchat/content_generator.rb, line 6
def initialize(event)
  @event = event
  @client = event['client']
  @check = event['check']
end

Public Instance Methods

content() click to toggle source
# File lib/sensu-plugins-rocketchat/content_generator.rb, line 12
def content
  eruby = Erubis::Eruby.new(body)
  eruby.result(binding)
end

Private Instance Methods

body() click to toggle source
# File lib/sensu-plugins-rocketchat/content_generator.rb, line 19
    def body
      <<-BODY.gsub(/^\s+/, '')
      <%= output %>
      Host: <%= @client['name'] %>
      Timestamp: <%= Time.at(@check['issued']) %>
      Address: <%= @client['address'] %>
      Check Name: <%= @check['name'] %>
      Command: <%= command %>
      Status: <%= status %>
      Occurrences: <%= @event['occurrences'] %>
      BODY
    end
command() click to toggle source
# File lib/sensu-plugins-rocketchat/content_generator.rb, line 32
def command
  strip_passwords(@check['command'])
end
output() click to toggle source
# File lib/sensu-plugins-rocketchat/content_generator.rb, line 36
def output
  strip_passwords(@check['output'])
end
status() click to toggle source
# File lib/sensu-plugins-rocketchat/content_generator.rb, line 44
def status
  case @check['status']
  when 0
    'OK'
  when 1
    'WARNING'
  when 2
    'CRITICAL'
  else
    'UNKNOWN'
  end
end
strip_passwords(str) click to toggle source
# File lib/sensu-plugins-rocketchat/content_generator.rb, line 40
def strip_passwords(str)
  str.gsub(/(\s-p|\s-P|\s--password)(\s*\S+)/, '\1 [FILTERED]')
end