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
23 def initialize(client, session, server, port)
24   url = build_url(API, server || Puppet[:report_server], port || Puppet[:report_port])
25   super(client, session, url)
26 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
38 def put_report(name, report, environment:)
39   formatter = Puppet::Network::FormatHandler.format_for(Puppet[:preferred_serialization_format])
40   headers = add_puppet_headers(
41     'Accept' => get_mime_types(Puppet::Transaction::Report).join(', '),
42     'Content-Type' => formatter.mime
43   )
44 
45   response = @client.put(
46     with_base_url("/report/#{name}"),
47     serialize(formatter, report),
48     headers: headers,
49     params: { environment: environment },
50   )
51 
52   # override parent's process_response handling
53   @session.process_response(response)
54 
55   if response.success?
56     response
57   elsif !@session.supports?(:report, 'json') && Puppet[:preferred_serialization_format] != 'pson'
58     #TRANSLATORS "pson", "preferred_serialization_format", and "puppetserver" should not be translated
59     raise Puppet::HTTP::ProtocolError.new(_("To submit reports to a server running puppetserver %{server_version}, set preferred_serialization_format to pson") % { server_version: response[Puppet::HTTP::HEADER_PUPPET_VERSION]})
60   else
61     raise Puppet::HTTP::ResponseError.new(response)
62   end
63 end