lib/arborist/monitor/snmp/process.rb
changeset 14 d5cb8bd33170
parent 8 e0b7c95a154f
child 16 d6773db8469c
equal deleted inserted replaced
13:6723f3b07536 14:d5cb8bd33170
    93 	### Parse OIDS and return an Array of running processes.
    93 	### Parse OIDS and return an Array of running processes.
    94 	### Windows specific behaviors.
    94 	### Windows specific behaviors.
    95 	###
    95 	###
    96 	def get_windows( snmp )
    96 	def get_windows( snmp )
    97 		oids = [ PROCESS[:windows][:path], PROCESS[:windows][:list], PROCESS[:windows][:args] ]
    97 		oids = [ PROCESS[:windows][:path], PROCESS[:windows][:list], PROCESS[:windows][:args] ]
    98 		return snmp.walk( oids ).each_slice( 3 ). each_with_object( [] ) do |vals, acc|
    98 
    99 			path, process, args = vals[0][1], vals[1][1], vals[2][1]
    99 		paths = snmp.walk( oid: oids[0] ).each_with_object( [] ) do |(_, value), acc|
       
   100 			acc << value
       
   101 		end
       
   102 		procs = snmp.walk( oid: oids[1] ).each_with_object( [] ) do |(_, value), acc|
       
   103 			acc << value
       
   104 		end
       
   105 		args = snmp.walk( oid: oids[2] ).each_with_object( [] ) do |(_, value), acc|
       
   106 			acc << value
       
   107 		end
       
   108 
       
   109 		return paths.zip( procs, args ).collect do |(path, process, arg)|
       
   110 			next unless path && process
   100 			next if path.empty?
   111 			next if path.empty?
   101 
   112 			path << process unless process.empty?
   102 			process = "%s%s" % [ path, process ]
   113 			path << " %s" % [ arg.to_s ] if arg && ! arg.empty?
   103 			process << " %s" % [ args ] unless args.empty?
   114 			path
   104 			acc << process
   115 		end.compact
   105 		end
       
   106 	end
   116 	end
   107 
   117 
   108 
   118 
   109 	### Parse OIDS and return an Array of running processes.
   119 	### Parse OIDS and return an Array of running processes.
   110 	###
   120 	###
   111 	def get_procs( snmp )
   121 	def get_procs( snmp )
   112 		oids = [ PROCESS[:netsnmp][:list], PROCESS[:netsnmp][:args] ]
   122 		oids = [ PROCESS[:netsnmp][:list], PROCESS[:netsnmp][:args] ]
   113 		return snmp.walk( oids ).each_slice( 2 ).each_with_object( [] ) do |vals, acc|
   123 
   114 			process, args = vals[0][1], vals[1][1]
   124 		procs = snmp.walk( oid: oids.first ).each_with_object( [] ) do |(_, value), acc|
       
   125 			acc << value
       
   126 		end
       
   127 		args = snmp.walk( oid: oids.last ).each_with_object( [] ) do |(_, value), acc|
       
   128 			acc << value
       
   129 		end
       
   130 
       
   131 		return procs.zip( args ).collect do |(process, arg)|
   115 			next if process.empty?
   132 			next if process.empty?
   116 
   133 			process << " %s" % [ arg.to_s ] unless arg.empty?
   117 			process << " %s" % [ args ] unless args.empty?
   134 			process
   118 			acc << process
   135 		end.compact
   119 		end
       
   120 	end
   136 	end
   121 
   137 
   122 end # class Arborist::Monitor::SNMP::Process
   138 end # class Arborist::Monitor::SNMP::Process
   123 
   139