lib/logstash/inputs/snmp.rb in logstash-input-snmp-1.0.1 vs lib/logstash/inputs/snmp.rb in logstash-input-snmp-1.1.0
- old
+ new
@@ -18,10 +18,13 @@
config :get,:validate => :array # ["1.3.6.1.2.1.1.1.0"]
# List of OIDs for which we want to retrieve the subtree of information
config :walk,:validate => :array # ["1.3.6.1.2.1.1.1.0"]
+ # List of tables to walk
+ config :tables, :validate => :array #[ {"name" => "interfaces" "columns" => ["1.3.6.1.2.1.2.2.1.1", "1.3.6.1.2.1.2.2.1.2", "1.3.6.1.2.1.2.2.1.5"]} ]
+
# List of hosts to query the configured `get` and `walk` options.
#
# Each host definition is a hash and must define the `host` key and value.
# `host` must use the format {tcp|udp}:{ip address}/{port}
# for example `host => "udp:127.0.0.1/161"`
@@ -89,10 +92,11 @@
PROVIDED_MIB_PATHS = [::File.join(BASE_MIB_PATH, "logstash"), ::File.join(BASE_MIB_PATH, "ietf")].map { |path| ::File.expand_path(path) }
def register
validate_oids!
validate_hosts!
+ validate_tables!
mib = LogStash::SnmpMib.new
if @use_provided_mibs
PROVIDED_MIB_PATHS.each do |path|
@@ -170,10 +174,20 @@
logger.error("error invoking walk operation on OID: #{oid}, ignoring", :exception => e, :backtrace => e.backtrace)
end
end
end
+ if !Array(@tables).empty?
+ @tables.each do |table_entry|
+ begin
+ result = result.merge(definition[:client].table(table_entry, @oid_root_skip))
+ rescue => e
+ logger.error("error invoking table operation on OID: #{table_entry['name']}, ignoring", :exception => e, :backtrace => e.backtrace)
+ end
+ end
+ end
+
unless result.empty?
metadata = {
"host_protocol" => definition[:host_protocol],
"host_address" => definition[:host_address],
"host_port" => definition[:host_port],
@@ -215,11 +229,24 @@
raise(LogStash::ConfigurationError, "The walk option oid '#{oid}' has an invalid format")
end
$1
end
- raise(LogStash::ConfigurationError, "at least one get OID or one walk OID is required") if @get.empty? && @walk.empty?
+ if !@tables.nil?
+ @tables.each do |table_entry|
+ # Verify oids for valid pattern and get rid of any leading dot if present
+ columns = table_entry["columns"]
+ columns.each do |column|
+ unless column =~ OID_REGEX
+ raise(Logstash::ConfigurationError, "The table column oid '#{column}' is an invalid format")
+ end
+ end
+ $1
+ end
+ end
+
+ raise(LogStash::ConfigurationError, "at least one get OID, one walk OID, or one table OID is required") if @get.empty? && @walk.empty? && @tables.nil?
end
def validate_v3_user!
errors = []
@@ -238,8 +265,16 @@
raise(LogStash::ConfigurationError, "at least one host definition is required") if Array(@hosts).empty?
@hosts.each do |host|
raise(LogStash::ConfigurationError, "each host definition must have a \"host\" option") if !host.is_a?(Hash) || host["host"].nil?
+ end
+ end
+
+ def validate_tables!
+ if !@tables.nil?
+ @tables.each do |table_entry|
+ raise(LogStash::ConfigurationError, "each table definition must have a \"name\" option") if !table_entry.is_a?(Hash) || table_entry["name"].nil?
+ end
end
end
end