# HG changeset patch # User Mahlon E. Smith # Date 1596316665 25200 # Node ID 40bcd1565627259fb5ff21c884ffb20485a2bd16 # Parent 534fa741c700d23ab2f9d67739b755d035a7751d Alterations for consistency, add documentation. Version bump. diff -r 534fa741c700 -r 40bcd1565627 README.md --- a/README.md Fri Jul 31 13:57:55 2020 -0700 +++ b/README.md Sat Aug 01 14:17:45 2020 -0700 @@ -117,6 +117,9 @@ You can also set this to a Hash, keyed on mount name, if you want differing warning values per mount point. A mount point that is at 100% capacity will be explicity set to `down`, as the resource it represents has been exhausted. + * **alert_readonly**: Set the now to an `error` state if mounts are readonly. + This may be helpful in iscsi-root environments. You can set this to a Hash, + keyed on mount name, if you want differing behavior per mount point. * **include**: String or Array of Strings. If present, only matching mount points are considered while performing checks. These are treated as regular expressions. * **exclude**: String or Array of Strings. If present, matching mount point are removed @@ -232,6 +235,7 @@ * Only monitor specific disk partitions, warning at different capacities . * Ensure the 'important' processing is running with the '--production' flag. * Warns at 95% memory utilization OR 10% swap. + * Ensure '/' is not a mounted as a read-only filesystem. - @@ -259,8 +263,11 @@ '^/var' ], warn_at: { - '/tmp' => 50, - '/var' => 80 + '/tmp' => 50, + '/var' => 80 + }, + alert_readonly: { + '/' => true } end diff -r 534fa741c700 -r 40bcd1565627 lib/arborist/monitor/snmp/disk.rb --- a/lib/arborist/monitor/snmp/disk.rb Fri Jul 31 13:57:55 2020 -0700 +++ b/lib/arborist/monitor/snmp/disk.rb Sat Aug 01 14:17:45 2020 -0700 @@ -17,10 +17,10 @@ # OIDS required to pull disk information from net-snmp. # STORAGE_NET_SNMP = { - path: '1.3.6.1.4.1.2021.9.1.2', + path: '1.3.6.1.4.1.2021.9.1.2', percent: '1.3.6.1.4.1.2021.9.1.9', - type: '1.3.6.1.2.1.25.3.8.1.4', - access: '1.3.6.1.2.1.25.3.8.1.5' + type: '1.3.6.1.2.1.25.3.8.1.4', + access: '1.3.6.1.2.1.25.3.8.1.5' } # The OID that matches a local windows hard disk. @@ -33,15 +33,18 @@ # OIDS required to pull disk information from Windows. # STORAGE_WINDOWS = { - type: '1.3.6.1.2.1.25.2.3.1.2', - path: '1.3.6.1.2.1.25.2.3.1.3', + type: '1.3.6.1.2.1.25.2.3.1.2', + path: '1.3.6.1.2.1.25.2.3.1.3', total: '1.3.6.1.2.1.25.2.3.1.5', - used: '1.3.6.1.2.1.25.2.3.1.6' + used: '1.3.6.1.2.1.25.2.3.1.6' } # The fallback warning capacity. WARN_AT = 90 + # Don't alert if a mount is readonly by default. + ALERT_READONLY = false + # Access mode meanings ACCESS_READWRITE = 1 ACCESS_READONLY = 2 @@ -52,6 +55,9 @@ # What percentage qualifies as a warning setting :warn_at, default: WARN_AT + # Set down if the mounts are readonly? + setting :alert_readonly, default: ALERT_READONLY + # If non-empty, only these paths are included in checks. # setting :include do |val| @@ -68,12 +74,6 @@ mounts = Array( val ).map{|m| Regexp.new(m) } Regexp.union( mounts ) end - - # Paths to alert for read-only status - setting :readonly_include, default: [ '^/$' ] do |val| - mounts = Array( val ).map{|m| Regexp.new(m) } - Regexp.union( mounts ) - end end @@ -113,6 +113,7 @@ 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 + alert_readonly = config[ 'alert_readonly' ] || self.class.alert_readonly self.log.debug self.identifiers[ host ] @@ -128,11 +129,13 @@ warnings = [] current_mounts.each_pair do |path, data| warn = if warn_at.is_a?( Hash ) - warn_at[ path ] || WARN_AT + warn_at[ path ] || self.class.warn_at else warn_at end + readonly = alert_readonly.is_a?( Hash ) ? alert_readonly[ path ] : alert_readonly + self.log.debug "%s:%s -> %p, warn at %d" % [ host, path, data, warn ] if data[ :capacity ] >= warn.to_i @@ -143,7 +146,7 @@ end end - if self.class.readonly_include.match( path ) && data[ :accessmode ] == ACCESS_READONLY + if readonly && data[ :accessmode ] == ACCESS_READONLY errors << "%s is mounted read-only." % [ path ] end end @@ -174,23 +177,16 @@ ### Fetch information for Windows systems. ### def windows_disks( snmp ) - oids = [ - STORAGE_WINDOWS[:path], - STORAGE_WINDOWS[:type], - STORAGE_WINDOWS[:total], - STORAGE_WINDOWS[:used] - ] - - paths = snmp.walk( oid: oids[0] ).each_with_object( [] ) do |(_, value), acc| + paths = snmp.walk( oid: STORAGE_WINDOWS[:path] ).each_with_object( [] ) do |(_, value), acc| acc << value end - types = snmp.walk( oid: oids[1] ).each_with_object( [] ) do |(_, value), acc| + types = snmp.walk( oid: STORAGE_WINDOWS[:type] ).each_with_object( [] ) do |(_, value), acc| acc << WINDOWS_DEVICES.include?( value ) end - totals = snmp.walk( oid: oids[2] ).each_with_object( [] ) do |(_, value), acc| + totals = snmp.walk( oid: STORAGE_WINDOWS[:total] ).each_with_object( [] ) do |(_, value), acc| acc << value end - used = snmp.walk( oid: oids[3] ).each_with_object( [] ) do |(_, value), acc| + used = snmp.walk( oid: STORAGE_WINDOWS[:used] ).each_with_object( [] ) do |(_, value), acc| acc << value end @@ -209,7 +205,6 @@ ### Fetch information for Unix/MacOS systems. ### def unix_disks( snmp ) - oids = [ STORAGE_NET_SNMP[:path], STORAGE_NET_SNMP[:percent], STORAGE_NET_SNMP[:access] ] paths = snmp.walk( oid: STORAGE_NET_SNMP[:path] ).each_with_object( [] ) do |(_, value), acc| acc << value end diff -r 534fa741c700 -r 40bcd1565627 lib/arborist/snmp.rb --- a/lib/arborist/snmp.rb Fri Jul 31 13:57:55 2020 -0700 +++ b/lib/arborist/snmp.rb Sat Aug 01 14:17:45 2020 -0700 @@ -1,5 +1,6 @@ # -*- ruby -*- #encoding: utf-8 +# vim: set noet nosta sw=4 ts=4 : require 'loggability' require 'arborist' @@ -14,7 +15,7 @@ # Package version - VERSION = '0.6.2' + VERSION = '0.7.0' # Version control revision REVISION = %q$Revision$