puppetlabs / puppetlabs-pe_status_check

Self Service Module for Puppet Enterprise
Apache License 2.0
1 stars 33 forks source link

random failures during agent execution #243

Open vchepkov opened 2 hours ago

vchepkov commented 2 hours ago

Agent produces error messages randomly:

2024-11-24 11:18:13 +0000 Facter (err): Error while resolving custom fact fact='agent_status_check', resolution='<anonymous>': No such file or directory @ rb_sysopen - /proc/137056/cmdline

The problem comes from this code: https://github.com/puppetlabs/puppetlabs-pe_status_check/blob/main/lib/facter/agent_status_check.rb#L34 because the list of files between the Dir.glob and File.read operations can change. An exception handling should be added

vchepkov commented 2 hours ago

I am no ruby expert, but maybe something like this?

cmdline_path = Dir.glob('/proc/[0-9]*/cmdline').find do |path|
  begin
    File.read(path).split("\0").first == '/opt/puppetlabs/puppet/bin/pxp-agent'
  rescue Errno::ENOENT
    next
  end
end