bin/check-postgres-alive.rb in sensu-plugins-postgres-1.3.0 vs bin/check-postgres-alive.rb in sensu-plugins-postgres-1.4.0

- old
+ new

@@ -25,14 +25,21 @@ # Copyright (c) 2012 Lewis Preson & Tom Bassindale # Released under the same terms as Sensu (the MIT license); see LICENSE # for details. # +require 'sensu-plugins-postgres/pgpass' require 'sensu-plugin/check/cli' require 'pg' class CheckPostgres < Sensu::Plugin::Check::CLI + option :pgpass, + description: 'Pgpass file', + short: '-f FILE', + long: '--pgpass', + default: ENV['PGPASSFILE'] || "#{ENV['HOME']}/.pgpass" + option :user, description: 'Postgres User', short: '-u USER', long: '--user USER' @@ -47,25 +54,26 @@ long: '--hostname HOST' option :database, description: 'Database schema to connect to', short: '-d DATABASE', - long: '--database DATABASE', - default: 'test' + long: '--database DATABASE' option :port, description: 'Database port', short: '-P PORT', - long: '--port PORT', - default: 5432 + long: '--port PORT' option :timeout, description: 'Connection timeout (seconds)', short: '-T TIMEOUT', long: '--timeout TIMEOUT', default: nil + include Pgpass + def run + pgpass con = PG.connect(host: config[:hostname], dbname: config[:database], user: config[:user], password: config[:password], port: config[:port],