2d86295d1c2aa83510959a775057fac7d7155368
[packages/precise/mcollective.git] / plugins / mcollective / audit / logfile.rb
1 module MCollective
2   module RPC
3     # An audit plugin that just logs to a file
4     #
5     # You can configure which file it logs to with the setting
6     #
7     #   plugin.rpcaudit.logfile
8     #
9     class Logfile<Audit
10       require 'pp'
11
12       def audit_request(request, connection)
13         logfile = Config.instance.pluginconf["rpcaudit.logfile"] || "/var/log/mcollective-audit.log"
14
15         now = Time.now
16         now_tz = tz = now.utc? ? "Z" : now.strftime("%z")
17         now_iso8601 = "%s.%06d%s" % [now.strftime("%Y-%m-%dT%H:%M:%S"), now.tv_usec, now_tz]
18
19         File.open(logfile, "a") do |f|
20           f.puts("#{now_iso8601}: reqid=#{request.uniqid}: reqtime=#{request.time} caller=#{request.caller}@#{request.sender} agent=#{request.agent} action=#{request.action} data=#{request.data.pretty_print_inspect}")
21         end
22       end
23     end
24   end
25 end