class Puppet::HTTP::Service::Report

The Report service is used to submit run reports to the report server.

@api public

Constants

API

@return [String] Default API for the report service

Public Class Methods

new(client, session, server, port) click to toggle source

Use `Puppet::HTTP::Session.route_to(:report)` to create or get an instance of this class.

@param [Puppet::HTTP::Client] client @param [Puppet::HTTP::Session] session @param [String] server (Puppet) If an explicit server is given,

create a service using that server. If server is nil, the default value
is used to create the service.

@param [Integer] port (Puppet) If an explicit port is given, create

a service using that port. If port is nil, the default value is used to
create the service.

@api private

Calls superclass method Puppet::HTTP::Service::new
   # File lib/puppet/http/service/report.rb
24 def initialize(client, session, server, port)
25   url = build_url(API, server || Puppet[:report_server], port || Puppet[:report_port])
26   super(client, session, url)
27 end

Public Instance Methods

put_report(name, report, environment:) click to toggle source

Submit a report to the report server.

@param [String] name the name of the report being submitted @param [Puppet::Transaction::Report] report run report to be submitted @param [String] environment name of the agent environment

@return [Puppet::HTTP::Response] response returned by the server

@api public

   # File lib/puppet/http/service/report.rb
39 def put_report(name, report, environment:)
40   formatter = Puppet::Network::FormatHandler.format_for(Puppet[:preferred_serialization_format])
41   headers = add_puppet_headers(
42     'Accept' => get_mime_types(Puppet::Transaction::Report).join(', '),
43     'Content-Type' => formatter.mime
44   )
45 
46   response = @client.put(
47     with_base_url("/report/#{name}"),
48     serialize(formatter, report),
49     headers: headers,
50     params: { environment: environment },
51   )
52 
53   # override parent's process_response handling
54   @session.process_response(response)
55 
56   if response.success?
57     response
58   else
59     raise Puppet::HTTP::ResponseError.new(response)
60   end
61 end