Skip to content

Commit

Permalink
Merge pull request #1 from mrichar1/mibs
Browse files Browse the repository at this point in the history
snmp metrics improvements/fixes
  • Loading branch information
mattyjones committed Jun 12, 2015
2 parents 7ca77ee + b6fb67b commit d16bddd
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
1 change: 1 addition & 0 deletions bin/check-snmp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
require 'sensu-plugin/check/cli'
require 'snmp'

# Class that checks the return from querying SNMP.
class CheckSNMP < Sensu::Plugin::Check::CLI
option :host,
short: '-h host',
Expand Down
26 changes: 22 additions & 4 deletions bin/metrics-snmp-bulk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
require 'sensu-plugin/metric/cli'
require 'snmp'

# Class that collects and outputs SNMP metrics in graphite format
class SNMPGraphite < Sensu::Plugin::Metric::CLI::Graphite
option :host,
short: '-h host',
Expand Down Expand Up @@ -66,17 +67,30 @@ class SNMPGraphite < Sensu::Plugin::Metric::CLI::Graphite
description: 'Number of supplied OIDs that should not be iterated over (defaults to 0)',
default: 0

option :mibdir,
short: '-d mibdir',
description: 'Full path to custom MIB directory.'

option :mibs,
short: '-l mib[,mib,mib...]',
description: 'Custom MIBs to load (from custom mib path).',
default: ''

option :timeout,
short: '-t timeout (seconds) (defaults to 5)',
default: 5

def run
oids = config[:objectid].split(',')
mibs = config[:mibs].split(',')
begin
manager = SNMP::Manager.new(host: "#{config[:host]}",
community: "#{config[:community]}",
version: config[:snmp_version].to_sym,
timeout: config[:timeout].to_i)
if config[:mibdir] && !mibs.empty?
manager.load_modules(mibs, config[:mibdir])
end
response = manager.get_bulk(config[:nonrepeat].to_i,
config[:maxrepeat].to_i,
oids)
Expand All @@ -89,10 +103,14 @@ def run
response.each_varbind do |vb|
name = vb.oid
name = "#{name}".gsub('.', '_') if config[:graphite]
if config[:prefix]
output "#{config[:prefix]}.#{config[:host]}.#{config[:suffix]}.#{name}", vb.value.to_f
else
output "#{config[:host]}.#{config[:suffix]}.#{name}", vb.value.to_f
begin
if config[:prefix]
output "#{config[:prefix]}.#{config[:host]}.#{config[:suffix]}.#{name}", value.to_f
else
output "#{config[:host]}.#{config[:suffix]}.#{name}", vb.value.to_f
end
rescue NameError # rubocop:disable all
# Some values may fail to cast to float
end
end
manager.close
Expand Down
1 change: 1 addition & 0 deletions bin/metrics-snmp-if.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def graphite_safe_name(name)
name.gsub(/\W/, '_')
end

# Class that collects SNMP if metrics and outputs them in graphite format.
class SNMPIfStatsGraphite < Sensu::Plugin::Metric::CLI::Graphite
option :host,
short: '-h host',
Expand Down
14 changes: 14 additions & 0 deletions bin/metrics-snmp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
require 'sensu-plugin/metric/cli'
require 'snmp'

# Class that collects and outputs SNMP metrics in graphite format
class SNMPGraphite < Sensu::Plugin::Metric::CLI::Graphite
option :host,
short: '-h host',
Expand Down Expand Up @@ -56,9 +57,22 @@ class SNMPGraphite < Sensu::Plugin::Metric::CLI::Graphite
description: 'Replace dots with underscores in hostname',
boolean: true

option :mibdir,
short: '-d mibdir',
description: 'Full path to custom MIB directory.'

option :mibs,
short: '-l mib[,mib,mib...]',
description: 'Custom MIBs to load (from custom mib path).',
default: ''

def run
mibs = config[:mibs].split(',')
begin
manager = SNMP::Manager.new(host: "#{config[:host]}", community: "#{config[:community]}", version: config[:snmp_version].to_sym)
if config[:mibdir] && !mibs.empty?
manager.load_modules(mibs, config[:mibdir])
end
response = manager.get(["#{config[:objectid]}"])
rescue SNMP::RequestTimeout
unknown "#{config[:host]} not responding"
Expand Down

0 comments on commit d16bddd

Please sign in to comment.