Skip to content

Commit

Permalink
Add option to specify the LVM command that chef-ruby-lvm runs
Browse files Browse the repository at this point in the history
With sensu assets it's not trivial to call the entire plugin script with sudo
This allows us to call the lvm command with sudo specifically which is a lot easier and better for sudo security
  • Loading branch information
Dan Ragnar committed Jan 9, 2020
1 parent 9ffa440 commit e3b6005
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
### Added
- Add sensu go bonsai asset (@danragnar)
- Bump bundler to 2.1
- Allow to specify the LVM command to run

### Changed
- appeased the cops (@majormoses)
Expand Down
8 changes: 7 additions & 1 deletion bin/check-lv-usage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ class CheckLVUsage < Sensu::Plugin::Check::CLI
description: 'Critical if PERCENT or more of logical metadata volume',
proc: proc(&:to_i),
default: 95

option :lvm_command,
short: '-m COMMAND',
long: '--command COMMAND',
description: 'Run this lvm command, e.g /bin/sudo /sbin/lvm'

# Setup variables
#
def initialize(argv = ARGV)
Expand All @@ -81,7 +87,7 @@ def initialize(argv = ARGV)
end

def logical_volumes
@logical_volumes ||= LVM::LVM.new.logical_volumes.list
@logical_volumes ||= config.key?(:lvm_command) ? LVM::LVM.new(command: config[:lvm_command]).logical_volumes.list : LVM::LVM.new.logical_volumes.list
end

def empty_volumes_msg
Expand Down
8 changes: 7 additions & 1 deletion bin/check-vg-usage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ class CheckVg < Sensu::Plugin::Check::CLI
proc: proc(&:to_i),
default: 95

option :lvm_command,
short: '-m COMMAND',
long: '--command COMMAND',
description: 'Run this lvm command, e.g /bin/sudo /sbin/lvm'

# Setup variables
#
def initialize
Expand All @@ -72,7 +77,8 @@ def initialize
# Get group data
#
def volume_groups
LVM::LVM.new.volume_groups.each do |line|
vgs = config.key?(:lvm_command) ? LVM::LVM.new(command: config[:lvm_command]).volume_groups : LVM::LVM.new.volume_groups
vgs.each do |line|
begin
next if config[:ignorevg]&.include?(line.name)
next if config[:ignorevgre]&.match(line.name)
Expand Down
8 changes: 7 additions & 1 deletion bin/metrics-vg-usage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,16 @@ class VgUsageMetrics < Sensu::Plugin::Metric::CLI::Graphite
description: 'Ignore volume group(s) matching regular expression',
proc: proc { |a| Regexp.new(a) }

option :lvm_command,
short: '-m COMMAND',
long: '--command COMMAND',
description: 'Run this lvm command, e.g /bin/sudo /sbin/lvm'

# Get group data
#
def volume_groups
LVM::LVM.new.volume_groups.each do |line|
vgs = config.key?(:lvm_command) ? LVM::LVM.new(command: config[:lvm_command]).volume_groups : LVM::LVM.new.volume_groups
vgs.each do |line|
begin
next if config[:ignorevg]&.include?(line.name)
next if config[:ignorevgre]&.match(line.name)
Expand Down
2 changes: 1 addition & 1 deletion lib/sensu-plugins-lvm/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module SensuPluginsLvm
module Version
MAJOR = 2
MINOR = 0
MINOR = 1
PATCH = 0

VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
Expand Down

0 comments on commit e3b6005

Please sign in to comment.