Sha256: d8f48162b5f7d84f4b3338e9585a140cd1ec1345804f5ded23c74ccadbebbed4

Contents?: true

Size: 1.04 KB

Versions: 4

Compression:

Stored size: 1.04 KB

Contents

require 'net/http'

# A module for Herald
module PuppetHerald
  # A client class for Herald
  class Client
    # Constructs a client
    #
    # @param host [String] a host to connect to, default to +'localhost'+
    # @param port [Integer] a port to connect to, default to +11303+
    # @return [PuppetHerald::Client] a client instance
    def initialize(host = 'localhost', port = 11_303)
      @host = host
      @port = port
      self
    end

    # Process a puppet report and sends it to Herald
    #
    # @param report [Puppet::Transaction::Report] a puppet report
    # @param block [Proc] a optional block that can modify request before sending
    # @return [Boolean] true if everything is ok
    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
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
puppet-herald-client-1.0.0 lib/puppet-herald/client.rb
puppet-herald-0.8.1 lib/puppet-herald/client.rb
puppet-herald-0.8.0 lib/puppet-herald/client.rb
puppet-herald-0.2.0 lib/puppet-herald/client.rb