Class: Chef::Handler::Graylog::Sender::Http

Inherits:
Chef::HTTP::BasicClient
  • Object
show all
Defined in:
lib/chef/handler/graylog/sender/http.rb

Defined Under Namespace

Classes: GraylogSSLPolicy

Instance Method Summary collapse

Constructor Details

#initialize(url, config = {}) ⇒ Http

Returns a new instance of Http.



31
32
33
34
# File 'lib/chef/handler/graylog/sender/http.rb', line 31

def initialize(url, config = {})
  @config = config # Needs to be set BEFORE calling super to avoid nil error in #config.
  super(URI.parse(url), :ssl_policy => GraylogSSLPolicy)
end

Instance Method Details

#configObject



36
37
38
39
# File 'lib/chef/handler/graylog/sender/http.rb', line 36

def config
  # Using a small timeout by default because there could be lots of HTTP requests.
  {:rest_timeout => @config[:timeout] || 1}
end

#configure_ssl(http_client) ⇒ Object



41
42
43
44
# File 'lib/chef/handler/graylog/sender/http.rb', line 41

def configure_ssl(http_client)
  http_client.use_ssl = true
  ssl_policy.apply_to(http_client, @config)
end

#send_payload(message) ⇒ Object



46
47
48
49
50
# File 'lib/chef/handler/graylog/sender/http.rb', line 46

def send_payload(message)
  request(:POST, url, JSON.dump(message.to_hash), 'X-Graylog-Chef-Handler-Version' => Graylog::VERSION)
rescue => e
  Chef::Log.error("[#{self.class}] Sending GELF message failed: #{e.message}")
end