|
# <%= ERB.new(File.read(File.expand_path("_header.erb",File.dirname(file)))).result(binding) -%>
|
|
# copy this file to your report dir - e.g. /usr/lib/ruby/1.8/puppet/reports/
|
|
# add this report in your puppetmaster reports - e.g, in your puppet.conf add:
|
|
# reports=log, foreman # (or any other reports you want)
|
|
|
|
# URL of your Foreman installation
|
|
$foreman_url='<%= @foreman_url %>'
|
|
# if CA is specified, remote Foreman host will be verified
|
|
$foreman_ssl_ca = "<%= @ssl_ca -%>"
|
|
# ssl_cert and key are required if require_ssl_puppetmasters is enabled in Foreman
|
|
$foreman_ssl_cert = "<%= @ssl_cert -%>"
|
|
$foreman_ssl_key = "<%= @ssl_key -%>"
|
|
|
|
require 'puppet'
|
|
require 'net/http'
|
|
require 'net/https'
|
|
require 'uri'
|
|
|
|
Puppet::Reports.register_report(:foreman) do
|
|
Puppet.settings.use(:reporting)
|
|
desc "Sends reports directly to Foreman"
|
|
|
|
def process
|
|
begin
|
|
uri = URI.parse($foreman_url)
|
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
http.use_ssl = uri.scheme == 'https'
|
|
if http.use_ssl?
|
|
if $foreman_ssl_ca && !$foreman_ssl_ca.empty?
|
|
http.ca_file = $foreman_ssl_ca
|
|
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
|
else
|
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
end
|
|
if $foreman_ssl_cert && !$foreman_ssl_cert.empty? && $foreman_ssl_key && !$foreman_ssl_key.empty?
|
|
http.cert = OpenSSL::X509::Certificate.new(File.read($foreman_ssl_cert))
|
|
http.key = OpenSSL::PKey::RSA.new(File.read($foreman_ssl_key), nil)
|
|
end
|
|
end
|
|
req = Net::HTTP::Post.new("#{uri.path}/reports/create?format=yml")
|
|
req.set_form_data({'report' => to_yaml})
|
|
response = http.request(req)
|
|
rescue Exception => e
|
|
raise Puppet::Error, "Could not send report to Foreman at #{$foreman_url}/reports/create?format=yml: #{e}"
|
|
end
|
|
end
|
|
end
|