]>
git.immae.eu Git - perso/Immae/Projets/Puppet.git/blob - modules/base_installation/lib/puppet/reports/store_changed.rb
bb39beb6185766ca28839536914cf729131607bd
5 SEPARATOR
= [Regexp
.escape(File
::SEPARATOR.to_s
), Regexp
.escape(File
::ALT_SEPARATOR.to_s
)].join
7 Puppet
::Reports.register_report(:store_changed) do
8 desc
"Store the yaml report on disk. Each host sends its report as a YAML dump
9 and this just stores the file on disk, in the `reportdir` directory.
11 These files collect quickly -- one every half hour -- so it is a good idea
12 to perform some maintenance on them if you use this report (it's the only
17 if status
== "unchanged"
21 dir
= File
.join(Puppet
[:reportdir], host
)
23 if ! Puppet
::FileSystem.exist
?(dir
)
24 FileUtils
.mkdir_p(dir
)
25 FileUtils
.chmod_R(0750, dir
)
28 # Now store the report.
30 name
= %w
{year month day hour min
}.collect
do |method
|
31 # Make sure we're at least two digits everywhere
32 "%02d" % now
.send(method
).to_s
33 end.join("") +
".yaml"
35 file
= File
.join(dir
, name
)
38 Puppet
::Util.replace_file(file
, 0640) do |fh
|
42 Puppet
.log_exception(detail
, "Could not write report for #{host} at #{file}: #{detail}")
45 # Only testing cares about the return value
49 # removes all reports for a given host?
50 def self.destroy(host
)
53 dir
= File
.join(Puppet
[:reportdir], host
)
55 if Puppet
::FileSystem.exist
?(dir
)
56 Dir
.entries(dir
).each
do |file
|
57 next if ['.','..'].include?(file
)
58 file
= File
.join(dir
, file
)
59 Puppet
::FileSystem.unlink(file
) if File
.file
?(file
)
65 def validate_host(host
)
66 if host
=~ Regexp
.union(/[#{SEPARATOR}]/, /\A\.\.?\Z/)
67 raise ArgumentError
, _("Invalid node name %{host}") % { host
: host
.inspect
}
70 module_function
:validate_host