Class: Flowchef::NotifyInbox

Inherits:
Chef::Handler
  • Object
show all
Defined in:
lib/flowchef.rb

Defined Under Namespace

Classes: InvalidParameterError

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ NotifyInbox

Returns a new instance of NotifyInbox.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/flowchef.rb', line 21

def initialize(options = {})
  @api_token = if options[:api_token].kind_of?(Array)
                 options[:api_token]
               else
                 options[:api_token].to_s
               end
  raise InvalidParameterError, "Must specify a Flow token" if blank?(@api_token)
  # Emacs indented this oddly
  @tags = if options[:tags].kind_of?(Array)
            options[:tags].each do |tag|
      raise InvalidParameterError, "Tags must be strings" if not tag.kind_of?(String)
    end
          end
end

Instance Method Details

#blank?(var) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/flowchef.rb', line 50

def blank?(var)
  var.nil? || var.respond_to?(:length) && var.length == 0
end

#reportObject



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/flowchef.rb', line 36

def report
  msg = <<-eos 
         <h2>Chef failures on #{node.name}</h2>
         #{run_status.formatted_exception}
        eos
  flow = Flowdock::Flow.new(:api_token => @api_token,
                            :source => "chef-#{node.environment}",
                            :from => {:name => "Node #{node.fqdn}",
                              :address => "noreply@#{node.fqdn}"})
  flow.push_to_team_inbox(:subject => "Chef failuers on #{node.name}",
                          :content => msg,
                          :tags => [])
end