Automatically clear stale mounts from node properties during disk checks.
--- a/README.md Sun Sep 01 13:28:18 2019 -0700
+++ b/README.md Tue Apr 28 10:10:19 2020 -0700
@@ -33,7 +33,7 @@
Prerequisites
-------------
- * Ruby 2.3 or better
+ * Ruby 2.4 or better
Installation
@@ -274,7 +274,7 @@
## License
-Copyright (c) 2016-2019 Michael Granger and Mahlon E. Smith
+Copyright (c) 2016-2020 Michael Granger and Mahlon E. Smith
All rights reserved.
Redistribution and use in source and binary forms, with or without
--- a/lib/arborist/monitor/snmp.rb Sun Sep 01 13:28:18 2019 -0700
+++ b/lib/arborist/monitor/snmp.rb Tue Apr 28 10:10:19 2020 -0700
@@ -57,7 +57,7 @@
nodes.each_pair do |(identifier, props)|
next unless props.key?( 'addresses' )
address = props[ 'addresses' ].first
- self.identifiers[ address ] = [ identifier, props['config'] ]
+ self.identifiers[ address ] = [ identifier, props ]
end
# Perform the work!
--- a/lib/arborist/monitor/snmp/cpu.rb Sun Sep 01 13:28:18 2019 -0700
+++ b/lib/arborist/monitor/snmp/cpu.rb Tue Apr 28 10:10:19 2020 -0700
@@ -117,7 +117,7 @@
def find_load( host, snmp )
info = self.format_load( snmp )
- config = identifiers[ host ].last || {}
+ config = self.identifiers[ host ].last['config'] || {}
warn_at = config[ 'warn_at' ] || self.class.warn_at
usage = info.dig( :cpu, :usage ) || 0
--- a/lib/arborist/monitor/snmp/disk.rb Sun Sep 01 13:28:18 2019 -0700
+++ b/lib/arborist/monitor/snmp/disk.rb Tue Apr 28 10:10:19 2020 -0700
@@ -70,7 +70,9 @@
### Return the properties used by this monitor.
###
def self::node_properties
- return USED_PROPERTIES
+ used_properties = USED_PROPERTIES.dup
+ used_properties << :mounts
+ return used_properties
end
@@ -98,22 +100,23 @@
### +snmp+ connection.
###
def gather_disks( host, snmp )
- mounts = self.system =~ /windows\s+/i ? self.windows_disks( snmp ) : self.unix_disks( snmp )
- config = self.identifiers[ host ].last || {}
- warn_at = config[ 'warn_at' ] || self.class.warn_at
+ current_mounts = self.system =~ /windows\s+/i ? self.windows_disks( snmp ) : self.unix_disks( snmp )
+ config = self.identifiers[ host ].last['config'] || {}
+ warn_at = config[ 'warn_at' ] || self.class.warn_at
+
+ self.log.warn self.identifiers[ host ]
includes = self.format_mounts( config, 'include' ) || self.class.include
excludes = self.format_mounts( config, 'exclude' ) || self.class.exclude
- mounts.reject! do |path, percentage|
+ current_mounts.reject! do |path, percentage|
path = path.to_s
excludes.match( path ) || ( includes && ! includes.match( path ) )
end
errors = []
warnings = []
- mounts.each_pair do |path, percentage|
-
+ current_mounts.each_pair do |path, percentage|
warn = if warn_at.is_a?( Hash )
warn_at[ path ] || WARN_AT
else
@@ -131,6 +134,13 @@
end
end
+ # Remove any past mounts that configuration exclusions should
+ # now omit.
+ mounts = self.identifiers[ host ].last[ 'mounts' ] || {}
+ mounts.keys.each{|k| mounts[k] = nil }
+
+ mounts.merge!( current_mounts )
+
self.results[ host ] = { mounts: mounts }
self.results[ host ][ :error ] = errors.join(', ') unless errors.empty?
self.results[ host ][ :warning ] = warnings.join(', ') unless warnings.empty?
--- a/lib/arborist/monitor/snmp/memory.rb Sun Sep 01 13:28:18 2019 -0700
+++ b/lib/arborist/monitor/snmp/memory.rb Tue Apr 28 10:10:19 2020 -0700
@@ -84,7 +84,7 @@
def gather_memory( host, snmp )
info = self.system =~ /windows\s+/i ? self.get_windows( snmp ) : self.get_mem( snmp )
- config = identifiers[ host ].last || {}
+ config = self.identifiers[ host ].last['config'] || {}
physical_warn_at = config[ 'physical_warn_at' ] || self.class.physical_warn_at
swap_warn_at = config[ 'swap_warn_at' ] || self.class.swap_warn_at
--- a/lib/arborist/monitor/snmp/process.rb Sun Sep 01 13:28:18 2019 -0700
+++ b/lib/arborist/monitor/snmp/process.rb Tue Apr 28 10:10:19 2020 -0700
@@ -71,7 +71,7 @@
#### +snmp+ connection.
###
def gather_processlist( host, snmp )
- config = self.identifiers[ host ].last || {}
+ config = self.identifiers[ host ].last['config'] || {}
errors = []
procs = self.system =~ /windows\s+/i ? self.get_windows( snmp ) : self.get_procs( snmp )
--- a/lib/arborist/monitor/snmp/ups/battery.rb Sun Sep 01 13:28:18 2019 -0700
+++ b/lib/arborist/monitor/snmp/ups/battery.rb Tue Apr 28 10:10:19 2020 -0700
@@ -104,7 +104,7 @@
def check_battery( host, snmp )
info = self.format_battery( snmp )
- config = identifiers[ host ].last || {}
+ config = self.identifiers[ host ].last['config'] || {}
cap_warn = config[ 'capacity_warn_at' ] || self.class.capacity_warn_at
temp_warn = config[ 'temperature_warn_at' ] || self.class.temperature_warn_at
--- a/lib/arborist/snmp.rb Sun Sep 01 13:28:18 2019 -0700
+++ b/lib/arborist/snmp.rb Tue Apr 28 10:10:19 2020 -0700
@@ -14,7 +14,7 @@
# Package version
- VERSION = '0.6.1'
+ VERSION = '0.6.2'
# Version control revision
REVISION = %q$Revision$