Class: Puppet::HTTP::Service::Report

Inherits:
Puppet::HTTP::Service show all
Defined in:
lib/puppet/http/service/report.rb

Overview

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

Constant Summary collapse

API =

Returns Default API for the report service.

Returns:

  • (String)

    Default API for the report service

'/puppet/v3'

Constants inherited from Puppet::HTTP::Service

EXCLUDED_FORMATS, SERVICE_NAMES

Instance Attribute Summary

Attributes inherited from Puppet::HTTP::Service

#url

Instance Method Summary collapse

Methods inherited from Puppet::HTTP::Service

#connect, create_service, valid_name?, #with_base_url

Constructor Details

#initialize(client, session, server, port) ⇒ Report

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Parameters:

  • client (Puppet::HTTP::Client)
  • session (Puppet::HTTP::Session)
  • server (String)

    (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.

  • port (Integer)

    (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.



24
25
26
27
# File 'lib/puppet/http/service/report.rb', line 24

def initialize(client, session, server, port)
  url = build_url(API, server || Puppet[:report_server], port || Puppet[:report_port])
  super(client, session, url)
end

Instance Method Details

#put_report(name, report, environment:) ⇒ Puppet::HTTP::Response

Submit a report to the report server.

Parameters:

  • name (String)

    the name of the report being submitted

  • report (Puppet::Transaction::Report)

    run report to be submitted

  • environment (String)

    name of the agent environment

Returns:



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/puppet/http/service/report.rb', line 39

def put_report(name, report, environment:)
  formatter = Puppet::Network::FormatHandler.format_for(Puppet[:preferred_serialization_format])
  headers = add_puppet_headers(
    'Accept' => get_mime_types(Puppet::Transaction::Report).join(', '),
    'Content-Type' => formatter.mime
  )

  response = @client.put(
    with_base_url("/report/#{name}"),
    serialize(formatter, report),
    headers: headers,
    params: { environment: environment }
  )

  # override parent's process_response handling
  @session.process_response(response)

  if response.success?
    response
  else
    raise Puppet::HTTP::ResponseError, response
  end
end