Class: LogStash::Inputs::DrupalDblog
- Defined in:
- lib/logstash/inputs/drupal_dblog.rb
Overview
Retrieve watchdog log events from a Drupal installation with DBLog enabled. The events are pulled out directly from the database. The original events are not deleted, and on every consecutive run only new events are pulled.
The last watchdog event id that was processed is stored in the Drupal variable table with the name “logstash_last_wid”. Delete this variable or set it to 0 if you want to re-import all events.
More info on DBLog: drupal.org/documentation/modules/dblog
Constant Summary
Constants included from Config::Mixin
Instance Attribute Summary
Attributes inherited from Base
Attributes included from Config::Mixin
Attributes inherited from Plugin
Instance Method Summary collapse
Methods inherited from Base
Methods included from Config::Mixin
Methods inherited from Plugin
#eql?, #finished, #finished?, #hash, #initialize, #inspect, lookup, #reload, #running?, #shutdown, #teardown, #terminating?, #to_s
Constructor Details
This class inherits a constructor from LogStash::Inputs::Base
Instance Method Details
#config_init(params) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/logstash/inputs/drupal_dblog.rb', line 71 def config_init(params) super dbs = {} valid = true @databases.each do |name, rawUri| uri = URI(rawUri) dbs[name] = { "site" => name, "scheme" => uri.scheme, "host" => uri.host, "user" => uri.user, "password" => uri.password, "database" => uri.path.sub('/', ''), "port" => uri.port.to_i } if not ( uri.scheme and not uri.scheme.empty?\ and uri.host and not uri.host.empty?\ and uri.user and not uri.user.empty?\ and uri.password\ and uri.path and not uri.path.sub('/', '').empty? ) @logger.error("Drupal DBLog: Invalid database URI for #{name} : #{rawUri}") valid = false end if not uri.scheme == 'mysql' @logger.error("Drupal DBLog: Only mysql databases are supported.") valid = false end end if not valid @logger.error("Config validation failed.") exit 1 end @databases = dbs end |
#register ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/logstash/inputs/drupal_dblog.rb', line 60 def register require "php_serialize" if RUBY_PLATFORM == 'java' require "logstash/inputs/drupal_dblog/jdbcconnection" else require "mysql2" end end |
#run(output_queue) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/logstash/inputs/drupal_dblog.rb', line 115 def run(output_queue) @logger.info("Initializing drupal_dblog") loop do @logger.debug("Drupal DBLog: Starting to fetch new watchdog entries") start = Time.now.to_i @databases.each do |name, db| @logger.debug("Drupal DBLog: Checking database #{name}") check_database(output_queue, db) @logger.info("Drupal DBLog: Retrieved all new watchdog messages from #{name}") end timeTaken = Time.now.to_i - start @logger.info("Drupal DBLog: Fetched all new watchdog entries in #{timeTaken} seconds") # If fetching of all databases took less time than the interval, # sleep a bit. sleepTime = @interval * 60 - timeTaken if sleepTime > 0 @logger.debug("Drupal DBLog: Sleeping for #{sleepTime} seconds") sleep(sleepTime) end end # loop end |