1 |
require 'puppet' |
2 |
require 'yaml' |
3 |
|
4 |
unless Puppet.version >= '2.6.5' |
5 |
fail "This report processor requires Puppet version 2.6.5 or later" |
6 |
end |
7 |
|
8 |
Puppet::Reports.register_report(:socket) do |
9 |
configfile = File.join([File.dirname(Puppet.settings[:config]), "socket.yaml"]) |
10 |
raise(Puppet::ParseError, "Socket report config file #{configfile} not readable") unless File.exist?(configfile) |
11 |
|
12 |
config = YAML.load_file(configfile) |
13 |
SOCKET_PATH = config[:socket_path] |
14 |
# TODO add support for using another user ? |
15 |
|
16 |
desc <<-DESC |
17 |
Send notification of failed reports to a socket. |
18 |
DESC |
19 |
|
20 |
def process |
21 |
if self.status == 'failed' |
22 |
message = "Puppet run for #{self.host} #{self.status} at #{Time.now.asctime}." |
23 |
if File.exist?(SOCKET_PATH) |
24 |
Puppet::Util.execute("echo #{message} > #{SOCKET_PATH}" , "nobody", "nogroup") |
25 |
end |
26 |
end |
27 |
end |
28 |
end |