module Pgpass

Public Instance Methods

pgpass() click to toggle source
# File lib/sensu-plugins-postgres/pgpass.rb, line 12
def pgpass
  if File.file?(config[:pgpass])
    pgpass = Hash[%i[hostname port database user password].zip(read_pgpass(config[:pgpass]))]
    pgpass[:database] = nil if pgpass[:database] == '*'
    pgpass.each do |k, v|
      config[k] ||= v
    end
  else
    config[:hostname] ||= ENV['PGHOST']     || 'localhost'
    config[:port]     ||= ENV['PGPORT']     || 5432
    config[:database] ||= ENV['PGDATABASE'] || 'postgres'
    config[:user]     ||= ENV['PGUSER']     || 'postgres'
    config[:password] ||= ENV['PGPASSWORD']
  end
end
read_pgpass(pg_pass_file) click to toggle source
# File lib/sensu-plugins-postgres/pgpass.rb, line 4
def read_pgpass(pg_pass_file)
  File.readlines(pg_pass_file).each do |line|
    return line.strip.split(':') unless line.start_with?('#')

    next
  end
end