37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/puppet/parser/functions/dynatrace_functions.rb', line 37
newfunction(:find_pids, :type => :rvalue) do |args|
pattern = args[0]
user = args[1]
platform_family = args[2]
pids = []
if %w(debian fedora rhel).include? platform_family
pgrep_pattern_opt = !pattern.nil? ? "-f \"#{pattern}\"" : ''
pgrep_user_opt = !user.nil? ? "-u #{user}" : ''
search_processes_cmd = "pgrep #{pgrep_pattern_opt} #{pgrep_user_opt}"
pidStr = `#{search_processes_cmd}`
unless pidStr.empty?
text = []
text << pidStr.lines.map(&:chomp)
text.each do |x|
x.each do |y|
pids << y.to_i
end
end
end
else
raise 'ERROR: Unsupported platform'
end
pids
end
|