lib/arborist/monitor/snmp/disk.rb
author Mahlon E. Smith <mahlon@martini.nu>
Tue, 28 Apr 2020 10:10:19 -0700
changeset 26 54f2f57cc0b0
parent 17 e4f0fd44734d
child 27 02b8e772e0c5
permissions -rw-r--r--
Automatically clear stale mounts from node properties during disk checks.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     1
# -*- ruby -*-
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     2
# vim: set noet nosta sw=4 ts=4 :
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     3
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     4
require 'arborist/monitor/snmp' unless defined?( Arborist::Monitor::SNMP )
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     5
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
     6
# Disk capacity checks.
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
     7
#
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
     8
# Sets all configured mounts with their current usage percentage
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
     9
# in an attribute named "mounts".
4
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    10
#
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    11
class Arborist::Monitor::SNMP::Disk
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    12
	include Arborist::Monitor::SNMP
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    13
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    14
	extend Configurability, Loggability
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    15
	log_to :arborist_snmp
4
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    16
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    17
	# OIDS required to pull disk information from net-snmp.
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    18
	#
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    19
	STORAGE_NET_SNMP = {
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    20
		path: '1.3.6.1.4.1.2021.9.1.2',
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    21
		percent: '1.3.6.1.4.1.2021.9.1.9',
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    22
		type: '1.3.6.1.2.1.25.3.8.1.4'
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    23
	}
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    24
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    25
	# The OID that matches a local windows hard disk.
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    26
	#
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    27
	WINDOWS_DEVICES = [
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    28
		'1.3.6.1.2.1.25.2.1.4', # local disk
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    29
		'1.3.6.1.2.1.25.2.1.7'  # removables, but we have to include them for iscsi mounts
4
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    30
	]
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    31
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    32
	# OIDS required to pull disk information from Windows.
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    33
	#
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    34
	STORAGE_WINDOWS = {
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    35
		type: '1.3.6.1.2.1.25.2.3.1.2',
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    36
		path: '1.3.6.1.2.1.25.2.3.1.3',
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    37
		total: '1.3.6.1.2.1.25.2.3.1.5',
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    38
		used: '1.3.6.1.2.1.25.2.3.1.6'
4
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    39
	}
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    40
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    41
	# The fallback warning capacity.
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    42
	WARN_AT = 90
4
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    43
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    44
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    45
	# Configurability API
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    46
	#
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    47
	configurability( 'arborist.snmp.disk' ) do
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    48
		# What percentage qualifies as a warning
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    49
		setting :warn_at, default: WARN_AT
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    50
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    51
		# If non-empty, only these paths are included in checks.
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    52
		#
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    53
		setting :include do |val|
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    54
			if val
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    55
				mounts = Array( val ).map{|m| Regexp.new(m) }
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    56
				Regexp.union( mounts )
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    57
			end
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    58
		end
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    59
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    60
		# Paths to exclude from checks
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    61
		#
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    62
		setting :exclude,
17
e4f0fd44734d Fix up the docs, make the default disk exclusion list more useful.
Mahlon E. Smith <mahlon@martini.nu>
parents: 14
diff changeset
    63
			default: [ '^/dev(/.+)?$', '/dev$', '^/net(/.+)?$', '/proc$', '^/run$', '^/sys/', '/sys$' ] do |val|
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    64
			mounts = Array( val ).map{|m| Regexp.new(m) }
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    65
			Regexp.union( mounts )
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    66
		end
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    67
	end
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    68
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    69
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    70
	### Return the properties used by this monitor.
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    71
	###
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    72
	def self::node_properties
26
54f2f57cc0b0 Automatically clear stale mounts from node properties during disk checks.
Mahlon E. Smith <mahlon@martini.nu>
parents: 17
diff changeset
    73
		used_properties = USED_PROPERTIES.dup
54f2f57cc0b0 Automatically clear stale mounts from node properties during disk checks.
Mahlon E. Smith <mahlon@martini.nu>
parents: 17
diff changeset
    74
		used_properties << :mounts
54f2f57cc0b0 Automatically clear stale mounts from node properties during disk checks.
Mahlon E. Smith <mahlon@martini.nu>
parents: 17
diff changeset
    75
		return used_properties
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    76
	end
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    77
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    78
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    79
	### Class #run creates a new instance and immediately runs it.
4
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    80
	###
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    81
	def self::run( nodes )
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    82
		return new.run( nodes )
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    83
	end
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    84
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    85
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    86
	### Perform the monitoring checks.
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    87
	###
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    88
	def run( nodes )
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    89
		super do |host, snmp|
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    90
			self.gather_disks( host, snmp )
4
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    91
		end
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    92
	end
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    93
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    94
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    95
	#########
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    96
	protected
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    97
	#########
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    98
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    99
	### Collect mount point usage for +host+ from an existing (and open)
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   100
	### +snmp+ connection.
4
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   101
	###
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   102
	def gather_disks( host, snmp )
26
54f2f57cc0b0 Automatically clear stale mounts from node properties during disk checks.
Mahlon E. Smith <mahlon@martini.nu>
parents: 17
diff changeset
   103
		current_mounts = self.system =~ /windows\s+/i ? self.windows_disks( snmp ) : self.unix_disks( snmp )
54f2f57cc0b0 Automatically clear stale mounts from node properties during disk checks.
Mahlon E. Smith <mahlon@martini.nu>
parents: 17
diff changeset
   104
		config         = self.identifiers[ host ].last['config'] || {}
54f2f57cc0b0 Automatically clear stale mounts from node properties during disk checks.
Mahlon E. Smith <mahlon@martini.nu>
parents: 17
diff changeset
   105
		warn_at        = config[ 'warn_at' ] || self.class.warn_at
54f2f57cc0b0 Automatically clear stale mounts from node properties during disk checks.
Mahlon E. Smith <mahlon@martini.nu>
parents: 17
diff changeset
   106
54f2f57cc0b0 Automatically clear stale mounts from node properties during disk checks.
Mahlon E. Smith <mahlon@martini.nu>
parents: 17
diff changeset
   107
		self.log.warn self.identifiers[ host ]
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   108
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   109
		includes = self.format_mounts( config, 'include' ) || self.class.include
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   110
		excludes = self.format_mounts( config, 'exclude' ) || self.class.exclude
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   111
26
54f2f57cc0b0 Automatically clear stale mounts from node properties during disk checks.
Mahlon E. Smith <mahlon@martini.nu>
parents: 17
diff changeset
   112
		current_mounts.reject! do |path, percentage|
14
d5cb8bd33170 Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents: 8
diff changeset
   113
			path = path.to_s
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   114
			excludes.match( path ) || ( includes && ! includes.match( path ) )
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   115
		end
4
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   116
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   117
		errors   = []
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   118
		warnings = []
26
54f2f57cc0b0 Automatically clear stale mounts from node properties during disk checks.
Mahlon E. Smith <mahlon@martini.nu>
parents: 17
diff changeset
   119
		current_mounts.each_pair do |path, percentage|
17
e4f0fd44734d Fix up the docs, make the default disk exclusion list more useful.
Mahlon E. Smith <mahlon@martini.nu>
parents: 14
diff changeset
   120
			warn = if warn_at.is_a?( Hash )
e4f0fd44734d Fix up the docs, make the default disk exclusion list more useful.
Mahlon E. Smith <mahlon@martini.nu>
parents: 14
diff changeset
   121
				warn_at[ path ] || WARN_AT
e4f0fd44734d Fix up the docs, make the default disk exclusion list more useful.
Mahlon E. Smith <mahlon@martini.nu>
parents: 14
diff changeset
   122
			else
e4f0fd44734d Fix up the docs, make the default disk exclusion list more useful.
Mahlon E. Smith <mahlon@martini.nu>
parents: 14
diff changeset
   123
				warn_at
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   124
			end
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   125
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   126
			self.log.debug "%s:%s -> at %d, warn at %d" % [ host, path, percentage, warn ]
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   127
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   128
			if percentage >= warn.to_i
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   129
				if percentage >= 100
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   130
					errors << "%s at %d%% capacity" % [ path, percentage ]
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   131
				else
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   132
					warnings << "%s at %d%% capacity" % [ path, percentage ]
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   133
				end
4
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   134
			end
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   135
		end
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   136
26
54f2f57cc0b0 Automatically clear stale mounts from node properties during disk checks.
Mahlon E. Smith <mahlon@martini.nu>
parents: 17
diff changeset
   137
		# Remove any past mounts that configuration exclusions should
54f2f57cc0b0 Automatically clear stale mounts from node properties during disk checks.
Mahlon E. Smith <mahlon@martini.nu>
parents: 17
diff changeset
   138
		# now omit.
54f2f57cc0b0 Automatically clear stale mounts from node properties during disk checks.
Mahlon E. Smith <mahlon@martini.nu>
parents: 17
diff changeset
   139
		mounts = self.identifiers[ host ].last[ 'mounts' ] || {}
54f2f57cc0b0 Automatically clear stale mounts from node properties during disk checks.
Mahlon E. Smith <mahlon@martini.nu>
parents: 17
diff changeset
   140
		mounts.keys.each{|k| mounts[k] = nil }
54f2f57cc0b0 Automatically clear stale mounts from node properties during disk checks.
Mahlon E. Smith <mahlon@martini.nu>
parents: 17
diff changeset
   141
54f2f57cc0b0 Automatically clear stale mounts from node properties during disk checks.
Mahlon E. Smith <mahlon@martini.nu>
parents: 17
diff changeset
   142
		mounts.merge!( current_mounts )
54f2f57cc0b0 Automatically clear stale mounts from node properties during disk checks.
Mahlon E. Smith <mahlon@martini.nu>
parents: 17
diff changeset
   143
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   144
		self.results[ host ] = { mounts: mounts }
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   145
		self.results[ host ][ :error ]   = errors.join(', ')   unless errors.empty?
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   146
		self.results[ host ][ :warning ] = warnings.join(', ') unless warnings.empty?
4
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   147
	end
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   148
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   149
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   150
	### Return a single regexp for the 'include' or 'exclude' section of
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   151
	### resource node's +config+, or nil if nonexistent.
4
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   152
	###
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   153
	def format_mounts( config, section )
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   154
		list = config[ section ] || return
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   155
		mounts = Array( list ).map{|m| Regexp.new(m) }
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   156
		return Regexp.union( mounts )
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   157
	end
4
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   158
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   159
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   160
	### Fetch information for Windows systems.
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   161
	###
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   162
	def windows_disks( snmp )
14
d5cb8bd33170 Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents: 8
diff changeset
   163
		oids = [
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   164
			STORAGE_WINDOWS[:path],
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   165
			STORAGE_WINDOWS[:type],
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   166
			STORAGE_WINDOWS[:total],
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   167
			STORAGE_WINDOWS[:used]
14
d5cb8bd33170 Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents: 8
diff changeset
   168
		]
d5cb8bd33170 Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents: 8
diff changeset
   169
d5cb8bd33170 Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents: 8
diff changeset
   170
		paths = snmp.walk( oid: oids[0] ).each_with_object( [] ) do |(_, value), acc|
d5cb8bd33170 Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents: 8
diff changeset
   171
			acc << value
d5cb8bd33170 Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents: 8
diff changeset
   172
		end
d5cb8bd33170 Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents: 8
diff changeset
   173
		types = snmp.walk( oid: oids[1] ).each_with_object( [] ) do |(_, value), acc|
d5cb8bd33170 Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents: 8
diff changeset
   174
			acc << WINDOWS_DEVICES.include?( value )
d5cb8bd33170 Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents: 8
diff changeset
   175
		end
d5cb8bd33170 Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents: 8
diff changeset
   176
		totals = snmp.walk( oid: oids[2] ).each_with_object( [] ) do |(_, value), acc|
d5cb8bd33170 Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents: 8
diff changeset
   177
			acc << value
d5cb8bd33170 Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents: 8
diff changeset
   178
		end
d5cb8bd33170 Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents: 8
diff changeset
   179
		used = snmp.walk( oid: oids[3] ).each_with_object( [] ) do |(_, value), acc|
d5cb8bd33170 Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents: 8
diff changeset
   180
			acc << value
d5cb8bd33170 Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents: 8
diff changeset
   181
		end
4
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   182
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   183
		disks = {}
14
d5cb8bd33170 Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents: 8
diff changeset
   184
		paths.each_with_index do |path, idx|
d5cb8bd33170 Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents: 8
diff changeset
   185
			next if totals[ idx ].zero?
d5cb8bd33170 Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents: 8
diff changeset
   186
			next unless types[ idx ]
d5cb8bd33170 Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents: 8
diff changeset
   187
			disks[ path ] ||= {}
d5cb8bd33170 Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents: 8
diff changeset
   188
			disks[ path ] = (( used[idx].to_f / totals[idx] ) * 100).round( 1 )
4
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   189
		end
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   190
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   191
		return disks
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   192
	end
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   193
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   194
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   195
	### Fetch information for Unix/MacOS systems.
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   196
	###
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   197
	def unix_disks( snmp )
14
d5cb8bd33170 Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents: 8
diff changeset
   198
		oids = [ STORAGE_NET_SNMP[:path], STORAGE_NET_SNMP[:percent] ]
d5cb8bd33170 Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents: 8
diff changeset
   199
		paths = snmp.walk( oid: oids.first ).each_with_object( [] ) do |(_, value), acc|
d5cb8bd33170 Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents: 8
diff changeset
   200
			acc << value
d5cb8bd33170 Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents: 8
diff changeset
   201
		end
d5cb8bd33170 Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents: 8
diff changeset
   202
		capacities = snmp.walk( oid: oids.last ).each_with_object( [] ) do |(_, value), acc|
d5cb8bd33170 Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents: 8
diff changeset
   203
			acc << value
d5cb8bd33170 Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents: 8
diff changeset
   204
		end
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   205
14
d5cb8bd33170 Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents: 8
diff changeset
   206
		pairs = paths.zip( capacities )
d5cb8bd33170 Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents: 8
diff changeset
   207
		return Hash[ *pairs.flatten ]
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   208
	end
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   209
4
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   210
end # class Arborist::Monitor::SNMP::Disk
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   211