Class: PuppetHerald::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet-herald/client.rb

Overview

A client class for Herald

Instance Method Summary collapse

Constructor Details

#initialize(host = 'localhost', port = 11_303) ⇒ PuppetHerald::Client

Constructs a client

Parameters:

  • host (String) (defaults to: 'localhost')

    a host to connect to, default to ‘localhost’

  • port (Integer) (defaults to: 11_303)

    a port to connect to, default to 11303



12
13
14
15
16
# File 'lib/puppet-herald/client.rb', line 12

def initialize(host = 'localhost', port = 11_303)
  @host = host
  @port = port
  self
end

Instance Method Details

#process(report, &block) ⇒ Boolean

Process a puppet report and sends it to Herald

Parameters:

Returns:

  • (Boolean)

    true if everything is ok



23
24
25
26
27
28
29
30
31
# File 'lib/puppet-herald/client.rb', line 23

def process(report, &block)
  path = '/api/v1/reports'
  header = { 'Content-Type' => 'application/yaml' }
  req = Net::HTTP::Post.new(path, initheader = header) # rubocop:disable all
  req.body = report.to_yaml
  block.call(req) if block
  Net::HTTP.new(@host, @port).start { |http| http.request(req) }
  true
end