Skip to content

Commit

Permalink
Merge pull request #115 from jindraj/patch-1
Browse files Browse the repository at this point in the history
Filter interfaces by regex in metrics-interface.rb
  • Loading branch information
Jef Spaleta authored Jan 17, 2020
2 parents cce7052 + 1d3a485 commit 6b0dfb8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md)

## [Unreleased]
### Update metrics-interfaces.rb
- Add `-X`, `--exclude-interfaces-regex` and `-I`, `--include-interfaces-regex` as alternative to `-x` and `-i`. Fixes [How can I filter out all veth* interfaces.](https://github.com/sensu-plugins/sensu-plugins-network-checks/issues/112)

### Breaking Changes
- Added hostname to default metric scheme.

Expand Down
12 changes: 12 additions & 0 deletions bin/metrics-interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ class InterfaceGraphite < Sensu::Plugin::Metric::CLI::Graphite
long: '--scheme SCHEME',
default: "#{Socket.gethostname}.interface"

option :excludeinterfaceregex,
description: 'Regex matching interfaces to exclude',
short: '-X INTERFACE',
long: '--exclude-interface-regex'

option :includeinterfaceregex,
description: 'Regex matching interfaces to include',
short: '-I INTERFACE',
long: '--include-interface-regex'

option :excludeinterface,
description: 'List of interfaces to exclude',
short: '-x INTERFACE[,INTERFACE]',
Expand Down Expand Up @@ -72,6 +82,8 @@ def run

File.open('/proc/net/dev', 'r').each_line do |line|
interface, stats_string = line.scan(/^\s*([^:]+):\s*(.*)$/).first
next if config[:excludeinterfaceregex] && (interface =~ /#{config[:excludeinterfaceregex]}/)
next if config[:includeinterfaceregex] && (interface !~ /#{config[:includeinterfaceregex]}/)
next if config[:excludeinterface] && config[:excludeinterface].find { |x| line.match(x) }
next if config[:includeinterface] && !(config[:includeinterface].find { |x| line.match(x) })
next unless interface
Expand Down

0 comments on commit 6b0dfb8

Please sign in to comment.