bin/check-postgres-replication.rb in sensu-plugins-postgres-1.3.0 vs bin/check-postgres-replication.rb in sensu-plugins-postgres-1.4.0
- old
+ new
@@ -24,14 +24,21 @@
# LICENSE:
# 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 CheckPostgresReplicationStatus < Sensu::Plugin::Check::CLI
+ option :pgpass,
+ description: 'Pgpass file',
+ short: '-f FILE',
+ long: '--pgpass',
+ default: ENV['PGPASSFILE'] || "#{ENV['HOME']}/.pgpass"
+
option(:master_host,
short: '-m',
long: '--master-host=HOST',
description: 'PostgreSQL master HOST')
@@ -42,12 +49,11 @@
default: 'localhost')
option(:port,
short: '-P',
long: '--port=PORT',
- description: 'PostgreSQL port',
- default: 5432)
+ description: 'PostgreSQL port')
option(:database,
short: '-d',
long: '--database=NAME',
description: 'Database NAME')
@@ -88,19 +94,22 @@
short: '-T',
long: '--timeout',
default: nil,
description: 'Connection timeout (seconds)')
+ include Pgpass
+
def compute_lag(master, slave, m_segbytes)
m_segment, m_offset = master.split('/')
s_segment, s_offset = slave.split('/')
((m_segment.hex - s_segment.hex) * m_segbytes) + (m_offset.hex - s_offset.hex)
end
def run
ssl_mode = config[:ssl] ? 'require' : 'prefer'
# Establishing connection to the master
+ pgpass
conn_master = PG.connect(host: config[:master_host],
dbname: config[:database],
user: config[:user],
password: config[:password],
port: config[:port],