Created
February 13, 2012 12:28
-
-
Save larstobi/1816444 to your computer and use it in GitHub Desktop.
Send Puppet reports to Foreman
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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='<%= scope.lookupvar("foreman::foreman_url") %>' | |
| $relative_url_root = '<%= scope.lookupvar("foreman::relative_url_root") %>' | |
| require 'puppet' | |
| require 'net/http' | |
| 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) | |
| if uri.scheme == 'https' then | |
| http.use_ssl = true | |
| http.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
| end | |
| req = Net::HTTP::Post.new("#{$relative_url_root}/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}#{$relative_url_root}/reports/create?format=yml: #{e}" | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment