bin/check-postgres-query.rb in sensu-plugins-postgres-1.3.0 vs bin/check-postgres-query.rb in sensu-plugins-postgres-1.4.0
- old
+ new
@@ -27,16 +27,23 @@
# Copyright 2015, Eric Heydrick <eheydrick@gmail.com>
# 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'
require 'dentaku'
# Check PostgresSQL Query
class CheckPostgresQuery < 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'
@@ -46,24 +53,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 :query,
description: 'Database query to execute',
short: '-q QUERY',
long: '--query QUERY',
@@ -92,11 +96,14 @@
description: 'Connection timeout (seconds)',
short: '-T TIMEOUT',
long: '--timeout TIMEOUT',
default: nil
+ include Pgpass
+
def run
begin
+ pgpass
con = PG.connect(host: config[:hostname],
dbname: config[:database],
user: config[:user],
password: config[:password],
port: config[:port],