Class: MCollective::Audit::Choria

Inherits:
RPC::Audit show all
Defined in:
lib/mcollective/audit/choria.rb

Instance Method Summary collapse

Methods inherited from RPC::Audit

inherited

Instance Method Details

#audit_request(request, connection) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/mcollective/audit/choria.rb', line 4

def audit_request(request, connection)
  logfile = Config.instance.pluginconf["rpcaudit.logfile"]

  unless logfile
    Log.warn("Auditing is not functional because rpcaudit.logfile is not set")
    return
  end

  message = {
    "timestamp" => Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S.%6N%z"),
    "request_id" => request.uniqid,
    "request_time" => request.time,
    "caller" => request.caller,
    "sender" => request.sender,
    "agent" => request.agent,
    "action" => request.action,
    "data" => request.data
  }

  begin
    File.open(logfile, "a") do |f|
      f.puts(message.to_json)
    end
  rescue
    Log.warn("Auditing is not functional because writing to logfile '%s' failed %s: %s" % [logfile, $!.class, $!.to_s])
  end
end