lib/arborist/monitor/snmp/process.rb
author Katelyn Schiesser <kschiesser@laika.com>
Thu, 18 Apr 2019 12:11:01 -0700
changeset 22 d36032444b99
parent 16 d6773db8469c
child 26 54f2f57cc0b0
permissions -rw-r--r--
remove nil predicate
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
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     6
# SNMP running process checks.
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     7
#
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
     8
# This only checks running userland processes.
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
     9
#
4
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    10
class Arborist::Monitor::SNMP::Process
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    11
	include Arborist::Monitor::SNMP
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    12
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    13
	extend Configurability, Loggability
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    14
	log_to :arborist_snmp
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    15
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 for discovering running processes.
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    18
	# Of course, Windows does it slightly differently.
4
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    19
	#
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    20
	PROCESS = {
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    21
		netsnmp: {
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    22
			list: '1.3.6.1.2.1.25.4.2.1.4',
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    23
			args: '1.3.6.1.2.1.25.4.2.1.5'
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
		windows: {
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    26
			list: '1.3.6.1.2.1.25.4.2.1.2',
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    27
			path: '1.3.6.1.2.1.25.4.2.1.4',
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    28
			args: '1.3.6.1.2.1.25.4.2.1.5'
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    29
		}
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
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    32
4
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    33
	# Global defaults for instances of this monitor
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    34
	#
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    35
	configurability( 'arborist.snmp.processes' ) do
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    36
		# Default list of processes to check for
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    37
		setting :check, default: [] do |val|
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    38
			Array( val )
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    39
		end
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    40
	end
4
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    41
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    42
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    43
	### 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
    44
	###
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    45
	def self::node_properties
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    46
		return USED_PROPERTIES
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    47
	end
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    48
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    49
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    50
	### 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
    51
	###
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    52
	def self::run( nodes )
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    53
		return new.run( nodes )
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    54
	end
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    55
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    56
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    57
	### Perform the monitoring checks.
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    58
	###
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    59
	def run( nodes )
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    60
		super do |host, snmp|
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    61
			self.gather_processlist( host, snmp )
4
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    62
		end
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    63
	end
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    64
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    65
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    66
	#########
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    67
	protected
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    68
	#########
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    69
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    70
	### Collect running processes on +host+ from an existing (and open)
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    71
	#### +snmp+ connection.
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    72
	###
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    73
	def gather_processlist( host, snmp )
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    74
		config = self.identifiers[ host ].last || {}
4
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    75
		errors = []
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    76
		procs  = self.system =~ /windows\s+/i ? self.get_windows( snmp ) : self.get_procs( snmp )
4
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    77
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    78
		self.log.debug "Running processes for host: %s: %p" % [ host, procs ]
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    79
		self.results[ host ] = { count: procs.size }
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    80
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    81
		# Check against what is running.
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    82
		#
16
d6773db8469c Fix per-node config key for process checks.
Mahlon E. Smith <mahlon@martini.nu>
parents: 14
diff changeset
    83
		Array( config['check'] || self.class.check ).each do |process|
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    84
			process_r = Regexp.new( process )
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    85
			found = procs.find{|p| p.match(process_r) }
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    86
			errors << "'%s' is not running" % [ process ] unless found
4
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    87
		end
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    88
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    89
		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
    90
	end
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    91
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    92
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    93
	### Parse OIDS and return an Array of running processes.
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    94
	### Windows specific behaviors.
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    95
	###
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    96
	def get_windows( snmp )
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    97
		oids = [ PROCESS[:windows][:path], PROCESS[:windows][:list], PROCESS[:windows][:args] ]
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
    98
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
    99
		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
   100
			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
   101
		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
   102
		procs = 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
   103
			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
   104
		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
   105
		args = 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
   106
			acc << value
4
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   107
		end
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
   108
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
   109
		return paths.zip( procs, args ).collect do |(path, process, arg)|
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
   110
			next unless path && process
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
   111
			next if path.empty?
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
   112
			path << process unless process.empty?
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 << " %s" % [ arg.to_s ] if arg && ! arg.empty?
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
   114
			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
   115
		end.compact
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   116
	end
4
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   117
8
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   118
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   119
	### Parse OIDS and return an Array of running processes.
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   120
	###
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   121
	def get_procs( snmp )
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   122
		oids = [ PROCESS[:netsnmp][:list], PROCESS[:netsnmp][:args] ]
e0b7c95a154f Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents: 4
diff changeset
   123
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
   124
		procs = 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
   125
			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
   126
		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
   127
		args = 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
   128
			acc << value
4
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   129
		end
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
   130
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
   131
		return procs.zip( args ).collect do |(process, arg)|
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
   132
			next if process.empty?
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
   133
			process << " %s" % [ arg.to_s ] unless arg.empty?
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
   134
			process
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
   135
		end.compact
4
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   136
	end
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   137
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   138
end # class Arborist::Monitor::SNMP::Process
e6eb11b1e00d Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   139