sensu-plugins-postgres 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1323464e435535d66a0b1576376858022278a8d
4
- data.tar.gz: 4019c094ae4a807a0160cfc9125094eec1ceccc9
3
+ metadata.gz: 700df0f38e6925029e0dc4b00a262e7d8aca68f6
4
+ data.tar.gz: d88ebc9c96c571ee5ead092b938c52d0bd8da872
5
5
  SHA512:
6
- metadata.gz: 85cf122222ee4acbc37ac6743e600d5af3a76c0ff81c3f9fc570883d82d9bfb0ec85cd13c2da68afdf73c3d79fea39a07385b799f86dda6487825978bbc5ed29
7
- data.tar.gz: cc3e9ee519fdf64b8cfec6080cd5c502edc176c14cd93be807ea95a6dd6c411ad7cad17681eb4f0ae1d013bd07a78570e65d903f732dfe1722391c9f16f6090c
6
+ metadata.gz: 9bfda3d996fb16c6a3fd6dbe9ac4e4e2c162dd409e36f1a9e924c0ef51323f300a18577405e48ca414397c8c56388ccf6516b409a5c413dfea089f171e1245e6
7
+ data.tar.gz: 8038becb84e1b1311bf6fad897cc78e841db73dfb2b24ba9a2e766251f5b367785867791c0502ff3425bd4d84d4f3ddca8956940a9cd63ce480e9e63b9bac6ac
data/CHANGELOG.md CHANGED
@@ -5,6 +5,10 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [1.4.0] - 2017-08-04
9
+ ### Added
10
+ - all checks now support using the pgpass file and is backwards compatible with the previous versions (@ahes)
11
+
8
12
  ## [1.3.0] - 2017-07-25
9
13
  ### Fixed
10
14
  - Take into account reserved superuser connections in check-postgres-connections.rb (@Evesy)
@@ -106,7 +110,8 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
106
110
  ### Added
107
111
  - initial release
108
112
 
109
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/1.3.0...HEAD
113
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/1.4.0...HEAD
114
+ [1.4.0]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/1.3.0...1.4.0
110
115
  [1.3.0]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/1.2.0...1.3.0
111
116
  [1.2.0]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/1.1.2...1.2.0
112
117
  [1.1.2]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/1.1.1...1.1.2
data/README.md CHANGED
@@ -25,8 +25,85 @@
25
25
 
26
26
  ## Usage
27
27
 
28
+ Use `--help` to see command arguments.
29
+
30
+ ### Sample usage
31
+
32
+ #### Check if PostgreSQL is alive
33
+ ```
34
+ $ check-postgres-alive.rb -d template1 -f /var/lib/postgresql/.pgpass
35
+ CheckPostgres OK: Server version: {"version"=>"PostgreSQL 9.6.3 on x86_64-pc-linux-gnu, compiled by gcc (Debian 4.9.2-10) 4.9.2, 64-bit"}
36
+ ```
37
+
38
+ ### Check replication status
39
+ ```
40
+ $ check-postgres-replication.rb -m psql1.local -s psql2.local -d template1 -w 5 -c 10
41
+ CheckPostgresReplicationStatus OK: replication delayed by 0.0MB :: master:B0/B4031000 slave:B0/B4031000 m_segbytes:16777216
42
+ ```
43
+
44
+ ### Check number of connections
45
+ ```
46
+ $ export PGPASSWORD=this-is-secret-password
47
+ $ check-postgres-connections.rb -a -w 80 -c 90 -d template1 -u sensu
48
+ CheckPostgresConnections OK: PostgreSQL connections under threshold: 17%, 174 out of 997 connections
49
+ ```
50
+
51
+ ### Default values
52
+
53
+ | Argument | Env variable | Value |
54
+ |----------------|--------------|-----------|
55
+ | -f, --pgpass | PGPASSFILE | ~/.pgpass |
56
+ | -h, --hostname | PGHOST | localhost |
57
+ | -P, --port | PGPORT | 5432 |
58
+ | -d, --database | PGDATABASE | postgres |
59
+ | -u, --user | PGUSER | postgres |
60
+ | -p, --password | PGPASSWORD | |
61
+
62
+ Options precedence is following:
63
+ 1. command line arguments
64
+ 1. pgpass file
65
+ 1. env variables
66
+ 1. defaults
67
+
68
+ ### Pgpass file
69
+
70
+ When file `~/.pgpass` is found it is used by default. You can also use `-f, --pgpass` command line argument or set `PGPASSFILE` env variable.
71
+
72
+ File format is:
73
+
74
+ ```
75
+ hostname:port:database:username:password
76
+ ```
77
+
78
+ Only first line is used. If database is set to `*` it is ommited.
79
+
80
+ You can ovveride `pgpass` values with command line arguments, e.g. `-h` for hostname.
81
+
28
82
  ## Installation
29
83
 
30
- [Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
84
+ ```
85
+ gem install sensu-plugins-postgres
86
+ ```
87
+
88
+ See [Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html) for details.
89
+
90
+ ### Known issues
91
+
92
+ When using Sensu with `EMBEDDED_RUBY=true` and installing Postgres checks with `/usr/bin/sensu-install -p sensu-plugins-postgres` you might get following error:
93
+
94
+ ```
95
+ ERROR: Error installing sensu-plugins-postgres:
96
+ ERROR: Failed to build gem native extension.
97
+ [...]
98
+ checking for PQconnectdb() in -lpq... no
99
+ checking for PQconnectdb() in -llibpq... no
100
+ checking for PQconnectdb() in -lms/libpq... no
101
+ Can't find the PostgreSQL client library (libpq)
102
+ *** extconf.rb failed ***
103
+ ```
104
+
105
+ The reason is that **libssl** library which comes with Sensu is incompatible with **libpq** library installed on your system. There is no easy way to fix it. You might want to install sensu-plugins-postgres globally with `gem install sensu-plugins-postgres`.
106
+
107
+ Checks are in `/usr/local/bin` directory.
31
108
 
32
109
  ## Notes
@@ -27,10 +27,17 @@
27
27
  # for details.
28
28
  #
29
29
 
30
+ require 'sensu-plugins-postgres/pgpass'
30
31
  require 'sensu-plugin/check/cli'
31
32
  require 'pg'
32
33
 
33
34
  class CheckPostgres < Sensu::Plugin::Check::CLI
35
+ option :pgpass,
36
+ description: 'Pgpass file',
37
+ short: '-f FILE',
38
+ long: '--pgpass',
39
+ default: ENV['PGPASSFILE'] || "#{ENV['HOME']}/.pgpass"
40
+
34
41
  option :user,
35
42
  description: 'Postgres User',
36
43
  short: '-u USER',
@@ -49,14 +56,12 @@ class CheckPostgres < Sensu::Plugin::Check::CLI
49
56
  option :database,
50
57
  description: 'Database schema to connect to',
51
58
  short: '-d DATABASE',
52
- long: '--database DATABASE',
53
- default: 'test'
59
+ long: '--database DATABASE'
54
60
 
55
61
  option :port,
56
62
  description: 'Database port',
57
63
  short: '-P PORT',
58
- long: '--port PORT',
59
- default: 5432
64
+ long: '--port PORT'
60
65
 
61
66
  option :timeout,
62
67
  description: 'Connection timeout (seconds)',
@@ -64,7 +69,10 @@ class CheckPostgres < Sensu::Plugin::Check::CLI
64
69
  long: '--timeout TIMEOUT',
65
70
  default: nil
66
71
 
72
+ include Pgpass
73
+
67
74
  def run
75
+ pgpass
68
76
  con = PG.connect(host: config[:hostname],
69
77
  dbname: config[:database],
70
78
  user: config[:user],
@@ -32,10 +32,17 @@
32
32
  # for details.
33
33
  #
34
34
 
35
+ require 'sensu-plugins-postgres/pgpass'
35
36
  require 'sensu-plugin/check/cli'
36
37
  require 'pg'
37
38
 
38
39
  class CheckPostgresConnections < Sensu::Plugin::Check::CLI
40
+ option :pgpass,
41
+ description: 'Pgpass file',
42
+ short: '-f FILE',
43
+ long: '--pgpass',
44
+ default: ENV['PGPASSFILE'] || "#{ENV['HOME']}/.pgpass"
45
+
39
46
  option :user,
40
47
  description: 'Postgres User',
41
48
  short: '-u USER',
@@ -49,20 +56,17 @@ class CheckPostgresConnections < Sensu::Plugin::Check::CLI
49
56
  option :hostname,
50
57
  description: 'Hostname to login to',
51
58
  short: '-h HOST',
52
- long: '--hostname HOST',
53
- default: 'localhost'
59
+ long: '--hostname HOST'
54
60
 
55
61
  option :port,
56
62
  description: 'Database port',
57
63
  short: '-P PORT',
58
- long: '--port PORT',
59
- default: 5432
64
+ long: '--port PORT'
60
65
 
61
66
  option :database,
62
67
  description: 'Database name',
63
68
  short: '-d DB',
64
- long: '--db DB',
65
- default: 'postgres'
69
+ long: '--db DB'
66
70
 
67
71
  option :warning,
68
72
  description: 'Warning threshold number or % of connections. (default: 200 connections)',
@@ -91,8 +95,11 @@ class CheckPostgresConnections < Sensu::Plugin::Check::CLI
91
95
  long: '--timeout TIMEOUT',
92
96
  default: nil
93
97
 
98
+ include Pgpass
99
+
94
100
  def run
95
101
  begin
102
+ pgpass
96
103
  con = PG.connect(host: config[:hostname],
97
104
  dbname: config[:database],
98
105
  user: config[:user],
@@ -29,12 +29,19 @@
29
29
  # for details.
30
30
  #
31
31
 
32
+ require 'sensu-plugins-postgres/pgpass'
32
33
  require 'sensu-plugin/check/cli'
33
34
  require 'pg'
34
35
  require 'dentaku'
35
36
 
36
37
  # Check PostgresSQL Query
37
38
  class CheckPostgresQuery < Sensu::Plugin::Check::CLI
39
+ option :pgpass,
40
+ description: 'Pgpass file',
41
+ short: '-f FILE',
42
+ long: '--pgpass',
43
+ default: ENV['PGPASSFILE'] || "#{ENV['HOME']}/.pgpass"
44
+
38
45
  option :user,
39
46
  description: 'Postgres User',
40
47
  short: '-u USER',
@@ -48,20 +55,17 @@ class CheckPostgresQuery < Sensu::Plugin::Check::CLI
48
55
  option :hostname,
49
56
  description: 'Hostname to login to',
50
57
  short: '-h HOST',
51
- long: '--hostname HOST',
52
- default: 'localhost'
58
+ long: '--hostname HOST'
53
59
 
54
60
  option :port,
55
61
  description: 'Database port',
56
62
  short: '-P PORT',
57
- long: '--port PORT',
58
- default: 5432
63
+ long: '--port PORT'
59
64
 
60
65
  option :database,
61
66
  description: 'Database name',
62
67
  short: '-d DB',
63
- long: '--db DB',
64
- default: 'postgres'
68
+ long: '--db DB'
65
69
 
66
70
  option :query,
67
71
  description: 'Database query to execute',
@@ -94,8 +98,11 @@ class CheckPostgresQuery < Sensu::Plugin::Check::CLI
94
98
  long: '--timeout TIMEOUT',
95
99
  default: nil
96
100
 
101
+ include Pgpass
102
+
97
103
  def run
98
104
  begin
105
+ pgpass
99
106
  con = PG.connect(host: config[:hostname],
100
107
  dbname: config[:database],
101
108
  user: config[:user],
@@ -26,10 +26,17 @@
26
26
  # for details.
27
27
  #
28
28
 
29
+ require 'sensu-plugins-postgres/pgpass'
29
30
  require 'sensu-plugin/check/cli'
30
31
  require 'pg'
31
32
 
32
33
  class CheckPostgresReplicationStatus < Sensu::Plugin::Check::CLI
34
+ option :pgpass,
35
+ description: 'Pgpass file',
36
+ short: '-f FILE',
37
+ long: '--pgpass',
38
+ default: ENV['PGPASSFILE'] || "#{ENV['HOME']}/.pgpass"
39
+
33
40
  option(:master_host,
34
41
  short: '-m',
35
42
  long: '--master-host=HOST',
@@ -44,8 +51,7 @@ class CheckPostgresReplicationStatus < Sensu::Plugin::Check::CLI
44
51
  option(:port,
45
52
  short: '-P',
46
53
  long: '--port=PORT',
47
- description: 'PostgreSQL port',
48
- default: 5432)
54
+ description: 'PostgreSQL port')
49
55
 
50
56
  option(:database,
51
57
  short: '-d',
@@ -90,6 +96,8 @@ class CheckPostgresReplicationStatus < Sensu::Plugin::Check::CLI
90
96
  default: nil,
91
97
  description: 'Connection timeout (seconds)')
92
98
 
99
+ include Pgpass
100
+
93
101
  def compute_lag(master, slave, m_segbytes)
94
102
  m_segment, m_offset = master.split('/')
95
103
  s_segment, s_offset = slave.split('/')
@@ -100,6 +108,7 @@ class CheckPostgresReplicationStatus < Sensu::Plugin::Check::CLI
100
108
  ssl_mode = config[:ssl] ? 'require' : 'prefer'
101
109
 
102
110
  # Establishing connection to the master
111
+ pgpass
103
112
  conn_master = PG.connect(host: config[:master_host],
104
113
  dbname: config[:database],
105
114
  user: config[:user],
@@ -28,11 +28,18 @@
28
28
  # for details.
29
29
  #
30
30
 
31
+ require 'sensu-plugins-postgres/pgpass'
31
32
  require 'sensu-plugin/metric/cli'
32
33
  require 'pg'
33
34
  require 'socket'
34
35
 
35
36
  class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
37
+ option :pgpass,
38
+ description: 'Pgpass file',
39
+ short: '-f FILE',
40
+ long: '--pgpass',
41
+ default: "#{ENV['HOME']}/.pgpass"
42
+
36
43
  option :user,
37
44
  description: 'Postgres User',
38
45
  short: '-u USER',
@@ -46,20 +53,17 @@ class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
46
53
  option :hostname,
47
54
  description: 'Hostname to login to',
48
55
  short: '-h HOST',
49
- long: '--hostname HOST',
50
- default: 'localhost'
56
+ long: '--hostname HOST'
51
57
 
52
58
  option :port,
53
59
  description: 'Database port',
54
60
  short: '-P PORT',
55
- long: '--port PORT',
56
- default: 5432
61
+ long: '--port PORT'
57
62
 
58
63
  option :database,
59
64
  description: 'Database name',
60
65
  short: '-d DB',
61
- long: '--db DB',
62
- default: 'postgres'
66
+ long: '--db DB'
63
67
 
64
68
  option :scheme,
65
69
  description: 'Metric naming scheme, text to prepend to $queue_name.$metric',
@@ -72,9 +76,11 @@ class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
72
76
  long: '--timeout TIMEOUT',
73
77
  default: nil
74
78
 
79
+ include Pgpass
80
+
75
81
  def run
76
82
  timestamp = Time.now.to_i
77
-
83
+ pgpass
78
84
  con = PG.connect(host: config[:hostname],
79
85
  dbname: config[:database],
80
86
  user: config[:user],
@@ -28,11 +28,18 @@
28
28
  # for details.
29
29
  #
30
30
 
31
+ require 'sensu-plugins-postgres/pgpass'
31
32
  require 'sensu-plugin/metric/cli'
32
33
  require 'pg'
33
34
  require 'socket'
34
35
 
35
36
  class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
37
+ option :pgpass,
38
+ description: 'Pgpass file',
39
+ short: '-f FILE',
40
+ long: '--pgpass',
41
+ default: ENV['PGPASSFILE'] || "#{ENV['HOME']}/.pgpass"
42
+
36
43
  option :user,
37
44
  description: 'Postgres User',
38
45
  short: '-u USER',
@@ -46,20 +53,17 @@ class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
46
53
  option :hostname,
47
54
  description: 'Hostname to login to',
48
55
  short: '-h HOST',
49
- long: '--hostname HOST',
50
- default: 'localhost'
56
+ long: '--hostname HOST'
51
57
 
52
58
  option :port,
53
59
  description: 'Database port',
54
60
  short: '-P PORT',
55
- long: '--port PORT',
56
- default: 5432
61
+ long: '--port PORT'
57
62
 
58
63
  option :database,
59
64
  description: 'Database name',
60
65
  short: '-d DB',
61
- long: '--db DB',
62
- default: 'postgres'
66
+ long: '--db DB'
63
67
 
64
68
  option :scheme,
65
69
  description: 'Metric naming scheme, text to prepend to $queue_name.$metric',
@@ -72,9 +76,11 @@ class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
72
76
  long: '--timeout TIMEOUT',
73
77
  default: nil
74
78
 
79
+ include Pgpass
80
+
75
81
  def run
76
82
  timestamp = Time.now.to_i
77
-
83
+ pgpass
78
84
  con = PG.connect(host: config[:hostname],
79
85
  dbname: config[:database],
80
86
  user: config[:user],
@@ -26,11 +26,18 @@
26
26
  # for details.
27
27
  #
28
28
 
29
+ require 'sensu-plugins-postgres/pgpass'
29
30
  require 'pg'
30
31
  require 'sensu-plugin/metric/cli'
31
32
  require 'socket'
32
33
 
33
34
  class CheckpostgresReplicationStatus < Sensu::Plugin::Metric::CLI::Graphite
35
+ option :pgpass,
36
+ description: 'Pgpass file',
37
+ short: '-f FILE',
38
+ long: '--pgpass',
39
+ default: ENV['PGPASSFILE'] || "#{ENV['HOME']}/.pgpass"
40
+
34
41
  option :master_host,
35
42
  short: '-m',
36
43
  long: '--master=HOST',
@@ -45,8 +52,7 @@ class CheckpostgresReplicationStatus < Sensu::Plugin::Metric::CLI::Graphite
45
52
  option :database,
46
53
  short: '-d',
47
54
  long: '--database=NAME',
48
- description: 'Database NAME',
49
- default: 'postgres'
55
+ description: 'Database NAME'
50
56
 
51
57
  option :user,
52
58
  short: '-u',
@@ -67,8 +73,7 @@ class CheckpostgresReplicationStatus < Sensu::Plugin::Metric::CLI::Graphite
67
73
  option :port,
68
74
  description: 'Database port',
69
75
  short: '-P PORT',
70
- long: '--port PORT',
71
- default: 5432
76
+ long: '--port PORT'
72
77
 
73
78
  option :timeout,
74
79
  description: 'Connection timeout (seconds)',
@@ -76,8 +81,11 @@ class CheckpostgresReplicationStatus < Sensu::Plugin::Metric::CLI::Graphite
76
81
  long: '--timeout TIMEOUT',
77
82
  default: nil
78
83
 
84
+ include Pgpass
85
+
79
86
  def run
80
87
  # Establishing connections to the master
88
+ pgpass
81
89
  conn_master = PG.connect(host: config[:master_host],
82
90
  dbname: config[:database],
83
91
  user: config[:user],
@@ -28,11 +28,18 @@
28
28
  # for details.
29
29
  #
30
30
 
31
+ require 'sensu-plugins-postgres/pgpass'
31
32
  require 'sensu-plugin/metric/cli'
32
33
  require 'pg'
33
34
  require 'socket'
34
35
 
35
36
  class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
37
+ option :pgpass,
38
+ description: 'Pgpass file',
39
+ short: '-f FILE',
40
+ long: '--pgpass',
41
+ default: ENV['PGPASSFILE'] || "#{ENV['HOME']}/.pgpass"
42
+
36
43
  option :user,
37
44
  description: 'Postgres User',
38
45
  short: '-u USER',
@@ -46,20 +53,17 @@ class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
46
53
  option :hostname,
47
54
  description: 'Hostname to login to',
48
55
  short: '-h HOST',
49
- long: '--hostname HOST',
50
- default: 'localhost'
56
+ long: '--hostname HOST'
51
57
 
52
58
  option :port,
53
59
  description: 'Database port',
54
60
  short: '-P PORT',
55
- long: '--port PORT',
56
- default: 5432
61
+ long: '--port PORT'
57
62
 
58
63
  option :database,
59
64
  description: 'Database name',
60
65
  short: '-d DB',
61
- long: '--db DB',
62
- default: 'postgres'
66
+ long: '--db DB'
63
67
 
64
68
  option :scheme,
65
69
  description: 'Metric naming scheme, text to prepend to $queue_name.$metric',
@@ -72,11 +76,13 @@ class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
72
76
  long: '--timeout TIMEOUT',
73
77
  default: nil
74
78
 
79
+ include Pgpass
80
+
75
81
  def run
76
82
  timestamp = Time.now.to_i
77
83
 
78
84
  locks_per_type = Hash.new(0)
79
-
85
+ pgpass
80
86
  con = PG.connect(host: config[:hostname],
81
87
  dbname: config[:database],
82
88
  user: config[:user],
@@ -28,11 +28,18 @@
28
28
  # for details.
29
29
  #
30
30
 
31
+ require 'sensu-plugins-postgres/pgpass'
31
32
  require 'sensu-plugin/metric/cli'
32
33
  require 'pg'
33
34
  require 'socket'
34
35
 
35
36
  class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
37
+ option :pgpass,
38
+ description: 'Pgpass file',
39
+ short: '-f FILE',
40
+ long: '--pgpass',
41
+ default: ENV['PGPASSFILE'] || "#{ENV['HOME']}/.pgpass"
42
+
36
43
  option :user,
37
44
  description: 'Postgres User',
38
45
  short: '-u USER',
@@ -46,14 +53,12 @@ class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
46
53
  option :hostname,
47
54
  description: 'Hostname to login to',
48
55
  short: '-h HOST',
49
- long: '--hostname HOST',
50
- default: 'localhost'
56
+ long: '--hostname HOST'
51
57
 
52
58
  option :port,
53
59
  description: 'Database port',
54
60
  short: '-P PORT',
55
- long: '--port PORT',
56
- default: 5432
61
+ long: '--port PORT'
57
62
 
58
63
  option :scheme,
59
64
  description: 'Metric naming scheme, text to prepend to $queue_name.$metric',
@@ -66,9 +71,11 @@ class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
66
71
  long: '--timeout TIMEOUT',
67
72
  default: nil
68
73
 
74
+ include Pgpass
75
+
69
76
  def run
70
77
  timestamp = Time.now.to_i
71
-
78
+ pgpass
72
79
  con = PG.connect(host: config[:hostname],
73
80
  dbname: 'postgres',
74
81
  user: config[:user],
@@ -29,11 +29,18 @@
29
29
  # for details.
30
30
  #
31
31
 
32
+ require 'sensu-plugins-postgres/pgpass'
32
33
  require 'sensu-plugin/metric/cli'
33
34
  require 'pg'
34
35
  require 'socket'
35
36
 
36
37
  class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
38
+ option :pgpass,
39
+ description: 'Pgpass file',
40
+ short: '-f FILE',
41
+ long: '--pgpass',
42
+ default: ENV['PGPASSFILE'] || "#{ENV['HOME']}/.pgpass"
43
+
37
44
  option :user,
38
45
  description: 'Postgres User',
39
46
  short: '-u USER',
@@ -47,20 +54,17 @@ class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
47
54
  option :hostname,
48
55
  description: 'Hostname to login to',
49
56
  short: '-h HOST',
50
- long: '--hostname HOST',
51
- default: 'localhost'
57
+ long: '--hostname HOST'
52
58
 
53
59
  option :port,
54
60
  description: 'Database port',
55
61
  short: '-P PORT',
56
- long: '--port PORT',
57
- default: 5432
62
+ long: '--port PORT'
58
63
 
59
64
  option :database,
60
65
  description: 'Database name',
61
66
  short: '-d DB',
62
- long: '--db DB',
63
- default: 'postgres'
67
+ long: '--db DB'
64
68
 
65
69
  option :scheme,
66
70
  description: 'Metric naming scheme, text to prepend to $queue_name.$metric',
@@ -73,9 +77,11 @@ class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
73
77
  long: '--timeout TIMEOUT',
74
78
  default: nil
75
79
 
80
+ include Pgpass
81
+
76
82
  def run
77
83
  timestamp = Time.now.to_i
78
-
84
+ pgpass
79
85
  con = PG.connect(host: config[:hostname],
80
86
  dbname: config[:database],
81
87
  user: config[:user],
@@ -29,11 +29,18 @@
29
29
  # for details.
30
30
  #
31
31
 
32
+ require 'sensu-plugins-postgres/pgpass'
32
33
  require 'sensu-plugin/metric/cli'
33
34
  require 'pg'
34
35
  require 'socket'
35
36
 
36
37
  class PostgresStatsIOMetrics < Sensu::Plugin::Metric::CLI::Graphite
38
+ option :pgpass,
39
+ description: 'Pgpass file',
40
+ short: '-f FILE',
41
+ long: '--pgpass',
42
+ default: ENV['PGPASSFILE'] || "#{ENV['HOME']}/.pgpass"
43
+
37
44
  option :user,
38
45
  description: 'Postgres User',
39
46
  short: '-u USER',
@@ -47,20 +54,17 @@ class PostgresStatsIOMetrics < Sensu::Plugin::Metric::CLI::Graphite
47
54
  option :hostname,
48
55
  description: 'Hostname to login to',
49
56
  short: '-h HOST',
50
- long: '--hostname HOST',
51
- default: 'localhost'
57
+ long: '--hostname HOST'
52
58
 
53
59
  option :port,
54
60
  description: 'Database port',
55
61
  short: '-P PORT',
56
- long: '--port PORT',
57
- default: 5432
62
+ long: '--port PORT'
58
63
 
59
64
  option :database,
60
65
  description: 'Database name',
61
66
  short: '-d DB',
62
- long: '--db DB',
63
- default: 'postgres'
67
+ long: '--db DB'
64
68
 
65
69
  option :scope,
66
70
  description: 'Scope, see http://www.postgresql.org/docs/9.2/static/monitoring-stats.html',
@@ -79,9 +83,11 @@ class PostgresStatsIOMetrics < Sensu::Plugin::Metric::CLI::Graphite
79
83
  long: '--timeout TIMEOUT',
80
84
  default: nil
81
85
 
86
+ include Pgpass
87
+
82
88
  def run
83
89
  timestamp = Time.now.to_i
84
-
90
+ pgpass
85
91
  con = PG.connect(host: config[:hostname],
86
92
  dbname: config[:database],
87
93
  user: config[:user],
@@ -29,11 +29,18 @@
29
29
  # for details.
30
30
  #
31
31
 
32
+ require 'sensu-plugins-postgres/pgpass'
32
33
  require 'sensu-plugin/metric/cli'
33
34
  require 'pg'
34
35
  require 'socket'
35
36
 
36
37
  class PostgresStatsTableMetrics < Sensu::Plugin::Metric::CLI::Graphite
38
+ option :pgpass,
39
+ description: 'Pgpass file',
40
+ short: '-f FILE',
41
+ long: '--pgpass',
42
+ default: ENV['PGPASSFILE'] || "#{ENV['HOME']}/.pgpass"
43
+
37
44
  option :user,
38
45
  description: 'Postgres User',
39
46
  short: '-u USER',
@@ -47,20 +54,17 @@ class PostgresStatsTableMetrics < Sensu::Plugin::Metric::CLI::Graphite
47
54
  option :hostname,
48
55
  description: 'Hostname to login to',
49
56
  short: '-h HOST',
50
- long: '--hostname HOST',
51
- default: 'localhost'
57
+ long: '--hostname HOST'
52
58
 
53
59
  option :port,
54
60
  description: 'Database port',
55
61
  short: '-P PORT',
56
- long: '--port PORT',
57
- default: 5432
62
+ long: '--port PORT'
58
63
 
59
64
  option :database,
60
65
  description: 'Database name',
61
66
  short: '-d DB',
62
- long: '--db DB',
63
- default: 'postgres'
67
+ long: '--db DB'
64
68
 
65
69
  option :scope,
66
70
  description: 'Scope, see http://www.postgresql.org/docs/9.2/static/monitoring-stats.html',
@@ -79,9 +83,11 @@ class PostgresStatsTableMetrics < Sensu::Plugin::Metric::CLI::Graphite
79
83
  long: '--timeout TIMEOUT',
80
84
  default: nil
81
85
 
86
+ include Pgpass
87
+
82
88
  def run
83
89
  timestamp = Time.now.to_i
84
-
90
+ pgpass
85
91
  con = PG.connect(host: config[:hostname],
86
92
  dbname: config[:database],
87
93
  user: config[:user],
@@ -27,10 +27,17 @@
27
27
  # for details.
28
28
  #
29
29
 
30
+ require 'sensu-plugins-postgres/pgpass'
30
31
  require 'sensu-plugin/metric/cli'
31
32
  require 'pg'
32
33
 
33
34
  class MetricsPostgresQuery < Sensu::Plugin::Metric::CLI::Graphite
35
+ option :pgpass,
36
+ description: 'Pgpass file',
37
+ short: '-f FILE',
38
+ long: '--pgpass',
39
+ default: ENV['PGPASSFILE'] || "#{ENV['HOME']}/.pgpass"
40
+
34
41
  option :user,
35
42
  description: 'Postgres User',
36
43
  short: '-u USER',
@@ -44,20 +51,17 @@ class MetricsPostgresQuery < Sensu::Plugin::Metric::CLI::Graphite
44
51
  option :hostname,
45
52
  description: 'Hostname to login to',
46
53
  short: '-h HOST',
47
- long: '--hostname HOST',
48
- default: 'localhost'
54
+ long: '--hostname HOST'
49
55
 
50
56
  option :port,
51
57
  description: 'Database port',
52
58
  short: '-P PORT',
53
- long: '--port PORT',
54
- default: 5432
59
+ long: '--port PORT'
55
60
 
56
61
  option :database,
57
62
  description: 'Database name',
58
63
  short: '-d DB',
59
- long: '--db DB',
60
- default: 'postgres'
64
+ long: '--db DB'
61
65
 
62
66
  option :query,
63
67
  description: 'Database query to execute',
@@ -91,8 +95,11 @@ class MetricsPostgresQuery < Sensu::Plugin::Metric::CLI::Graphite
91
95
  long: '--timeout TIMEOUT',
92
96
  default: nil
93
97
 
98
+ include Pgpass
99
+
94
100
  def run
95
101
  begin
102
+ pgpass
96
103
  con = PG.connect(host: config[:hostname],
97
104
  dbname: config[:database],
98
105
  user: config[:user],
@@ -1 +1,2 @@
1
1
  require 'sensu-plugins-postgres/version'
2
+ require 'sensu-plugins-postgres/pgpass'
@@ -0,0 +1,17 @@
1
+ module Pgpass
2
+ def pgpass
3
+ if File.file?(config[:pgpass])
4
+ pgpass = Hash[[:hostname, :port, :database, :user, :password].zip(File.readlines(config[:pgpass])[0].strip.split(':'))]
5
+ pgpass[:database] = nil if pgpass[:database] == '*'
6
+ pgpass.each do |k, v|
7
+ config[k] ||= v
8
+ end
9
+ else
10
+ config[:hostname] ||= ENV['PGHOST'] || 'localhost'
11
+ config[:port] ||= ENV['PGPORT'] || 5432
12
+ config[:database] ||= ENV['PGDATABASE'] || 'postgres'
13
+ config[:user] ||= ENV['PGUSER'] || 'postgres'
14
+ config[:password] ||= ENV['PGPASSWORD']
15
+ end
16
+ end
17
+ end
@@ -1,7 +1,7 @@
1
1
  module SensuPluginsPostgres
2
2
  module Version
3
3
  MAJOR = 1
4
- MINOR = 3
4
+ MINOR = 4
5
5
  PATCH = 0
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-postgres
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sensu-Plugins and contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-26 00:00:00.000000000 Z
11
+ date: 2017-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sensu-plugin
@@ -220,6 +220,7 @@ files:
220
220
  - bin/metric-postgres-statstable.rb
221
221
  - bin/metrics-postgres-query.rb
222
222
  - lib/sensu-plugins-postgres.rb
223
+ - lib/sensu-plugins-postgres/pgpass.rb
223
224
  - lib/sensu-plugins-postgres/version.rb
224
225
  homepage: https://github.com/sensu-plugins/sensu-plugins-postgres
225
226
  licenses: