Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add a centralrpclog agent that writes to mongodb

  • Loading branch information...
commit e327d9e78bd2ec37e7672ffe2a98262cc77442ca 1 parent e9fcadd
@ripienaar ripienaar authored
Showing with 53 additions and 0 deletions.
  1. +53 −0 audit/centralrpclog/agent/centralrpclog-mongodb.rb
View
53 audit/centralrpclog/agent/centralrpclog-mongodb.rb
@@ -0,0 +1,53 @@
+module MCollective
+ module Agent
+ # An agent that receives and logs RPC Audit messages sent from the accompanying Audit plugin
+ #
+ # It stores them in MongoDB, you can configure the mongo parameters:
+ #
+ # plugin.centralrpclog.mongohost = localhost
+ # plugin.centralrpclog.mongodb = mcollective
+ # plugin.centralrpclog.collection = rpclog
+ #
+ # These are the defaults. You need the mongo gem installed.
+ class Centralrpclog
+ attr_reader :timeout, :meta
+
+ def initialize
+ @timeout = 1
+
+ @config = Config.instance
+
+ @meta = {:license => "Apache 2",
+ :author => "R.I.Pienaar <rip@devco.net>",
+ :url => "http://code.google.com/p/mcollective-plugins/"}
+
+ require 'mongo'
+
+ @mongohost = @config.pluginconf["centralrpclog.mongohost"] || "localhost"
+ @mongodb = @config.pluginconf["centralrpclog.mongodb"] || "mcollective"
+ @collection = @config.pluginconf["centralrpclog.collection"] || "rpclog"
+
+ Log.instance.debug("Connecting to mongodb @ #{@mongohost} db #{@mongodb} collection #{@collection}")
+
+ @dbh = Mongo::Connection.new(@mongohost).db(@mongodb)
+ @coll = @dbh.collection(@collection)
+ end
+
+ def handlemsg(msg, connection)
+ request = msg[:body]
+
+ @coll.save(request.to_hash)
+
+ # never reply
+ nil
+ end
+
+ def help
+ <<-EOH
+ EOH
+ end
+ end
+ end
+end
+
+# vi:tabstop=4:expandtab:ai:filetype=ruby
Please sign in to comment.
Something went wrong with that request. Please try again.