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 |
# do not raise a error since this will show in puppet log |
11 |
# raise(Puppet::ParseError, "Socket report config file #{configfile} not readable") unless |
12 |
if File.exist?(configfile) |
13 |
|
14 |
# TODO add support for using another user ? |
15 |
config = YAML.load_file(configfile) |
16 |
SOCKET_PATH = config[:socket_path] |
17 |
else |
18 |
SOCKET_PATH = nil |
19 |
end |
20 |
|
21 |
desc <<-DESC |
22 |
Send notification of failed reports to a socket. |
23 |
DESC |
24 |
|
25 |
def process |
26 |
if self.status == 'failed' |
27 |
message = "Puppet run for #{self.host} #{self.status} at #{Time.now.asctime}." |
28 |
if File.exist?(SOCKET_PATH) |
29 |
Puppet::Util.execute("echo #{message} > #{SOCKET_PATH}" , "nobody", "nogroup") |
30 |
end |
31 |
end |
32 |
end |
33 |
end |