Class: PuppetHerald::Client
- Inherits:
-
Object
- Object
- PuppetHerald::Client
- Defined in:
- lib/puppet-herald/client.rb
Overview
A client class for Herald
Instance Method Summary collapse
-
#initialize(host = 'localhost', port = 11_303) ⇒ PuppetHerald::Client
constructor
Constructs a client.
-
#process(report, &block) ⇒ Boolean
Process a puppet report and sends it to Herald.
Constructor Details
#initialize(host = 'localhost', port = 11_303) ⇒ PuppetHerald::Client
Constructs a client
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
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 |