Skip to content

Commit

Permalink
Update metrics-snmp-if.rb (#23)
Browse files Browse the repository at this point in the history
* Update metrics-snmp-if.rb

add timeout option

* appeasing the cops and adding a changelog entry.
  • Loading branch information
rocdove authored and majormoses committed Jun 26, 2018
1 parent 0878983 commit c1c044e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,9 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/)

## [Unreleased]

### Added
- metrics-snmp-if.rb: added `--timeout|-t` option which controls the request timeout (@rocdove)

## [2.0.0] - 2017-11-04

### Changed
Expand Down
14 changes: 13 additions & 1 deletion bin/metrics-snmp-if.rb
Expand Up @@ -123,6 +123,12 @@ class SNMPIfStatsGraphite < Sensu::Plugin::Metric::CLI::Graphite
default: false,
description: 'Use low capacity counters'

option :timeout,
short: '-t TIMEOUT',
long: '--timeout TIMEOUT',
default: 5,
description: 'Request timeout'

def run # rubocop:disable Metrics/AbcSize
if_table_HC_columns = %w(
ifHCInOctets ifHCOutOctets
Expand All @@ -143,7 +149,13 @@ def run # rubocop:disable Metrics/AbcSize
if_table_columns = if_table_common_columns +
(config[:low_capacity] ? if_table_LC_columns : if_table_HC_columns)

SNMP::Manager.open(host: config[:host].to_s, port: config[:port].to_i, community: config[:community].to_s, version: config[:version]) do |manager|
SNMP::Manager.open(
host: config[:host].to_s,
port: config[:port].to_i,
community: config[:community].to_s,
version: config[:version],
timeout: config[:timeout]
) do |manager|
manager.walk(if_table_columns) do |row_array|
# turn row (an array) into a hash for eaiser access to the columns
row = Hash[*if_table_columns.zip(row_array).flatten]
Expand Down

0 comments on commit c1c044e

Please sign in to comment.