bin/metric-postgres-statstable.rb in sensu-plugins-postgres-1.3.0 vs bin/metric-postgres-statstable.rb in sensu-plugins-postgres-1.4.0

- old
+ new

@@ -27,15 +27,22 @@ # Author Gilles Devaux <gilles.devaux@gmail.com> # Released under the same terms as Sensu (the MIT license); see LICENSE # for details. # +require 'sensu-plugins-postgres/pgpass' require 'sensu-plugin/metric/cli' require 'pg' require 'socket' class PostgresStatsTableMetrics < Sensu::Plugin::Metric::CLI::Graphite + 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' @@ -45,24 +52,21 @@ long: '--password PASS' option :hostname, description: 'Hostname to login to', short: '-h HOST', - long: '--hostname HOST', - default: 'localhost' + long: '--hostname HOST' option :port, description: 'Database port', short: '-P PORT', - long: '--port PORT', - default: 5432 + long: '--port PORT' option :database, description: 'Database name', short: '-d DB', - long: '--db DB', - default: 'postgres' + long: '--db DB' option :scope, description: 'Scope, see http://www.postgresql.org/docs/9.2/static/monitoring-stats.html', short: '-s SCOPE', long: '--scope SCOPE', @@ -77,12 +81,14 @@ description: 'Connection timeout (seconds)', short: '-T TIMEOUT', long: '--timeout TIMEOUT', default: nil + include Pgpass + def run timestamp = Time.now.to_i - + pgpass con = PG.connect(host: config[:hostname], dbname: config[:database], user: config[:user], password: config[:password], port: config[:port],