sensu-plugins-postgres 3.0.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1593b3a386d0b9b726e50346ffb80d4f94968f1bf2a5450cfc2f1e7d06817404
4
- data.tar.gz: 13227e510d8dce85cee7affb6b1fca18755b74894835dabe2418b07bcb326944
3
+ metadata.gz: 8588535b67594b25fb79d59b28175d7eae496a4ce1d0a86ca8c36d83683f6a87
4
+ data.tar.gz: e1d5a2c92b8faf9cae20ba0ccb2218809c2da9704f4453936ab0924f3e60e00e
5
5
  SHA512:
6
- metadata.gz: ac667445c8eba52cf14afc24bce3d0fc8b80c1aa18d7ef1e0482b43aabb3a118ee296ac1adfbf266270eea9c778f0343bbb3699dcb8c2ece93135e3cf308bd55
7
- data.tar.gz: a3b11df6dd270af85f84e663215eee6fa613e7ab35326dcb8b6ae1c1ad175701995d18ee2d85f447f85f408daf3cfc785c6c91f32387170a6c8d43050de4fac9
6
+ metadata.gz: 9ec6be4ad4243a06d52bb61dadf72b55307ac8a1b82dc24bbcdfca1ac772270aee4afa19d7af85f7762676f3a6ad0d7f1a738ca38bfc35d39d4e984d38aaf5fe
7
+ data.tar.gz: 4b5afc11a6a76097923b947f95b34cc559c0ee8d10de50c9659bb178fde4c86c7ac8b5646238deea0af7b4a6b39e57822e82071e4dc3d3724b0b7594741d37f9
data/CHANGELOG.md CHANGED
@@ -5,6 +5,25 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [4.0.0] - 2020-01-09
9
+
10
+ ### Breaking Changes
11
+ - Update `sensu-plugin` dependency from `~> 1.2` to `~> 4.0` you can read the changelog entries for [4.0](https://github.com/sensu-plugins/sensu-plugin/blob/master/CHANGELOG.md#400---2018-02-17), [3.0](https://github.com/sensu-plugins/sensu-plugin/blob/master/CHANGELOG.md#300---2018-12-04), and [2.0](https://github.com/sensu-plugins/sensu-plugin/blob/master/CHANGELOG.md#v200---2017-03-29)
12
+ - `check-postgres-replication.rb`: both `--slave-host` and `master-host` arguments are now required flags where previously they had localhost defaults (@phumpal)
13
+
14
+ ### Fixed
15
+ - `check-postgres-replication.rb`: fix condition where connection timeout is considered a boolean rather than an integer value (@majormoses) (@phumpal) (@VeselaHouba)
16
+ - `check-postgres-replication.rb`: critical if the master and slave are same (@phumpal)
17
+
18
+ ### Added
19
+ - `check-postgres-query.rb`: Add `-r`, `--regex-pattern` to match query result against (@jindraj)
20
+
21
+ ### Changes
22
+ - Updated development dependency to bundler ~> 2.1
23
+ - Updated development dependency to rake ~> 13.0
24
+ - Updated development dependency to test-kitchen ~> 1.25.0
25
+ - Updated runtime dependency to 'pg' '1.2.1' from 1.1
26
+ - Updated runtime dependency 'dentaku' '3.3.4' from 2.04
8
27
 
9
28
  ## [3.0.0] - 2019-11-20
10
29
  ### Breaking Changes
@@ -187,7 +206,8 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
187
206
  ### Added
188
207
  - initial release
189
208
 
190
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/3.0.0...HEAD
209
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/4.0.0...HEAD
210
+ [4.0.0]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/3.0.0...4.0.0
191
211
  [3.0.0]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/2.4.0...3.0.0
192
212
  [2.4.0]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/2.3.2...2.4.0
193
213
  [2.3.2]: https://github.com/sensu-plugins/sensu-plugins-postgres/compare/2.3.1...2.3.2
@@ -1,4 +1,6 @@
1
1
  #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  #
3
5
  # check-postgres-alive
4
6
  #
@@ -86,6 +88,6 @@ class CheckPostgres < Sensu::Plugin::Check::CLI
86
88
  rescue PG::Error => e
87
89
  critical "Error message: #{e.error.split("\n").first}"
88
90
  ensure
89
- con.close if con
91
+ con&.close
90
92
  end
91
93
  end
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  #
3
5
  # check-postgres-connections
4
6
  #
@@ -114,7 +116,7 @@ class CheckPostgresConnections < Sensu::Plugin::Check::CLI
114
116
  unknown "Unable to query PostgreSQL: #{e.message}"
115
117
  end
116
118
 
117
- percent = (current_conns.to_f / max_conns.to_f * 100).to_i
119
+ percent = (current_conns / max_conns.to_f * 100).to_i
118
120
 
119
121
  if config[:use_percentage]
120
122
  message = "PostgreSQL connections at #{percent}%, #{current_conns} out of #{available_conns} connections"
@@ -1,4 +1,6 @@
1
1
  #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  #
3
5
  # check-postgres-query
4
6
  #
@@ -73,6 +75,11 @@ class CheckPostgresQuery < Sensu::Plugin::Check::CLI
73
75
  long: '--query QUERY',
74
76
  required: true
75
77
 
78
+ option :regex_pattern,
79
+ description: 'Regex pattern to match on query results and alert on if it does not match',
80
+ short: '-r REGEX',
81
+ long: '--regex-pattern REGEX'
82
+
76
83
  option :check_tuples,
77
84
  description: 'Check against the number of tuples (rows) returned by the query',
78
85
  short: '-t',
@@ -125,6 +132,8 @@ class CheckPostgresQuery < Sensu::Plugin::Check::CLI
125
132
  critical "Results: #{res.values}"
126
133
  elsif config[:warning] && calc.evaluate(config[:warning], value: value)
127
134
  warning "Results: #{res.values}"
135
+ elsif config[:regex_pattern] && (res.getvalue(0, 0) !~ /#{config[:regex_pattern]}/)
136
+ critical "Query result #{res.getvalue(0, 0)} doesn't match configured regex #{config[:regex_pattern]}"
128
137
  else
129
138
  ok 'Query OK'
130
139
  end
@@ -1,4 +1,6 @@
1
1
  #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  #
3
5
  # check-postgres-replication
4
6
  #
@@ -41,13 +43,14 @@ class CheckPostgresReplicationStatus < Sensu::Plugin::Check::CLI
41
43
  option(:master_host,
42
44
  short: '-m',
43
45
  long: '--master-host=HOST',
46
+ required: true,
44
47
  description: 'PostgreSQL master HOST')
45
48
 
46
49
  option(:slave_host,
47
50
  short: '-s',
48
51
  long: '--slave-host=HOST',
49
- description: 'PostgreSQL slave HOST',
50
- default: 'localhost')
52
+ required: true,
53
+ description: 'PostgreSQL slave HOST')
51
54
 
52
55
  option(:port,
53
56
  short: '-P',
@@ -92,10 +95,11 @@ class CheckPostgresReplicationStatus < Sensu::Plugin::Check::CLI
92
95
  proc: lambda { |s| s.to_i }) # rubocop:disable Lambda
93
96
 
94
97
  option(:timeout,
95
- short: '-T',
96
- long: '--timeout',
97
- default: nil,
98
- description: 'Connection timeout (seconds)')
98
+ short: '-T TIMEOUT',
99
+ long: '--timeout=TIMEOUT',
100
+ default: 2,
101
+ description: 'Connection timeout (seconds)',
102
+ proc: proc(&:to_i))
99
103
 
100
104
  include Pgpass
101
105
  include PgUtil
@@ -103,6 +107,8 @@ class CheckPostgresReplicationStatus < Sensu::Plugin::Check::CLI
103
107
  def run
104
108
  ssl_mode = config[:ssl] ? 'require' : 'prefer'
105
109
 
110
+ critical 'Master and slave cannot be the same host' if config[:master_host] == config[:slave_host]
111
+
106
112
  # Establishing connection to the master
107
113
  pgpass
108
114
  conn_master = PG.connect(host: config[:master_host],
@@ -1,4 +1,6 @@
1
1
  #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  #
3
5
  # metric-postgres-connections
4
6
  #
@@ -81,12 +83,12 @@ class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
81
83
  def run
82
84
  timestamp = Time.now.to_i
83
85
  pgpass
84
- con = PG.connect(host: config[:hostname],
85
- dbname: config[:database],
86
- user: config[:user],
87
- password: config[:password],
88
- port: config[:port],
89
- connect_timeout: config[:timeout])
86
+ con = PG.connect(host: config[:hostname],
87
+ dbname: config[:database],
88
+ user: config[:user],
89
+ password: config[:password],
90
+ port: config[:port],
91
+ connect_timeout: config[:timeout])
90
92
  request = [
91
93
  "select case when count(*) = 1 then 'waiting' else",
92
94
  "'case when wait_event_type is null then false else true end' end as wait_col",
@@ -1,4 +1,6 @@
1
1
  #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  #
3
5
  # metric-postgres-dbsize
4
6
  #
@@ -81,12 +83,12 @@ class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
81
83
  def run
82
84
  timestamp = Time.now.to_i
83
85
  pgpass
84
- con = PG.connect(host: config[:hostname],
85
- dbname: config[:database],
86
- user: config[:user],
87
- password: config[:password],
88
- port: config[:port],
89
- connect_timeout: config[:timeout])
86
+ con = PG.connect(host: config[:hostname],
87
+ dbname: config[:database],
88
+ user: config[:user],
89
+ password: config[:password],
90
+ port: config[:port],
91
+ connect_timeout: config[:timeout])
90
92
  request = [
91
93
  "select pg_database_size('#{config[:database]}')"
92
94
  ]
@@ -1,4 +1,6 @@
1
1
  #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  #
3
5
  # metric-postgres-graphite
4
6
  #
@@ -1,4 +1,6 @@
1
1
  #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  #
3
5
  # metric-postgres-locks
4
6
  #
@@ -83,12 +85,12 @@ class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
83
85
 
84
86
  locks_per_type = Hash.new(0)
85
87
  pgpass
86
- con = PG.connect(host: config[:hostname],
87
- dbname: config[:database],
88
- user: config[:user],
89
- password: config[:password],
90
- port: config[:port],
91
- connect_timeout: config[:timeout])
88
+ con = PG.connect(host: config[:hostname],
89
+ dbname: config[:database],
90
+ user: config[:user],
91
+ password: config[:password],
92
+ port: config[:port],
93
+ connect_timeout: config[:timeout])
92
94
  request = [
93
95
  'SELECT mode, count(mode) AS count FROM pg_locks',
94
96
  "WHERE database = (SELECT oid FROM pg_database WHERE datname = '#{config[:database]}')",
@@ -1,4 +1,6 @@
1
1
  #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  #
3
5
  # metric-postgres-statsbgwriter
4
6
  #
@@ -76,12 +78,12 @@ class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
76
78
  def run
77
79
  timestamp = Time.now.to_i
78
80
  pgpass
79
- con = PG.connect(host: config[:hostname],
80
- dbname: 'postgres',
81
- user: config[:user],
82
- password: config[:password],
83
- port: config[:port],
84
- connect_timeout: config[:timeout])
81
+ con = PG.connect(host: config[:hostname],
82
+ dbname: 'postgres',
83
+ user: config[:user],
84
+ password: config[:password],
85
+ port: config[:port],
86
+ connect_timeout: config[:timeout])
85
87
  request = [
86
88
  'select checkpoints_timed, checkpoints_req,',
87
89
  'checkpoint_write_time, checkpoint_sync_time,',
@@ -1,4 +1,6 @@
1
1
  #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  #
3
5
  # metric-postgres-statsdb
4
6
  #
@@ -1,4 +1,6 @@
1
1
  #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  #
3
5
  # metric-postgres-statsio
4
6
  #
@@ -88,12 +90,12 @@ class PostgresStatsIOMetrics < Sensu::Plugin::Metric::CLI::Graphite
88
90
  def run
89
91
  timestamp = Time.now.to_i
90
92
  pgpass
91
- con = PG.connect(host: config[:hostname],
92
- dbname: config[:database],
93
- user: config[:user],
94
- password: config[:password],
95
- port: config[:port],
96
- connect_timeout: config[:timeout])
93
+ con = PG.connect(host: config[:hostname],
94
+ dbname: config[:database],
95
+ user: config[:user],
96
+ password: config[:password],
97
+ port: config[:port],
98
+ connect_timeout: config[:timeout])
97
99
  request = [
98
100
  'select sum(heap_blks_read) as heap_blks_read, sum(heap_blks_hit) as heap_blks_hit,',
99
101
  'sum(idx_blks_read) as idx_blks_read, sum(idx_blks_hit) as idx_blks_hit,',
@@ -1,4 +1,6 @@
1
1
  #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  #
3
5
  # metric-postgres-statstable
4
6
  #
@@ -88,12 +90,12 @@ class PostgresStatsTableMetrics < Sensu::Plugin::Metric::CLI::Graphite
88
90
  def run
89
91
  timestamp = Time.now.to_i
90
92
  pgpass
91
- con = PG.connect(host: config[:hostname],
92
- dbname: config[:database],
93
- user: config[:user],
94
- password: config[:password],
95
- port: config[:port],
96
- connect_timeout: config[:timeout])
93
+ con = PG.connect(host: config[:hostname],
94
+ dbname: config[:database],
95
+ user: config[:user],
96
+ password: config[:password],
97
+ port: config[:port],
98
+ connect_timeout: config[:timeout])
97
99
  request = [
98
100
  'select sum(seq_scan) as seq_scan, sum(seq_tup_read) as seq_tup_read,',
99
101
  'sum(idx_scan) as idx_scan, sum(idx_tup_fetch) as idx_tup_fetch,',
@@ -1,4 +1,6 @@
1
1
  #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  #
3
5
  # metrics-postgres-query
4
6
  #
@@ -114,7 +116,7 @@ class MetricsPostgresQuery < Sensu::Plugin::Metric::CLI::Graphite
114
116
  value = if config[:count_tuples]
115
117
  res.ntuples
116
118
  else
117
- res.first.values.first unless res.first.nil?
119
+ res.first&.values&.first
118
120
  end
119
121
 
120
122
  if config[:multirow] && !config[:count_tuples]
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sensu-plugins-postgres/version'
2
4
  require 'sensu-plugins-postgres/pgpass'
@@ -1,7 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pgpass
2
4
  def read_pgpass(pg_pass_file)
3
5
  File.readlines(pg_pass_file).each do |line|
4
6
  return line.strip.split(':') unless line.start_with?('#')
7
+
5
8
  next
6
9
  end
7
10
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PgUtil
2
4
  def check_vsn_newer_than_postgres9(conn)
3
5
  pg_vsn = conn.exec("SELECT current_setting('server_version')").getvalue(0, 0)
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SensuPluginsPostgres
2
4
  module Version
3
- MAJOR = 3
5
+ MAJOR = 4
4
6
  MINOR = 0
5
7
  PATCH = 0
6
8
 
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: 3.0.0
4
+ version: 4.0.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: 2019-11-21 00:00:00.000000000 Z
11
+ date: 2020-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sensu-plugin
@@ -16,56 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.2'
19
+ version: '4.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.2'
26
+ version: '4.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: dentaku
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 2.0.4
33
+ version: 3.3.4
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 2.0.4
40
+ version: 3.3.4
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: pg
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: '1.1'
47
+ version: 1.2.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: '1.1'
54
+ version: 1.2.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.7'
61
+ version: '2.1'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1.7'
68
+ version: '2.1'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: codeclimate-test-reporter
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -156,14 +156,14 @@ dependencies:
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: '12.3'
159
+ version: '13.0'
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: '12.3'
166
+ version: '13.0'
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: redcarpet
169
169
  requirement: !ruby/object:Gem::Requirement
@@ -198,42 +198,42 @@ dependencies:
198
198
  requirements:
199
199
  - - "~>"
200
200
  - !ruby/object:Gem::Version
201
- version: 0.49.0
201
+ version: 0.79.0
202
202
  type: :development
203
203
  prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
206
  - - "~>"
207
207
  - !ruby/object:Gem::Version
208
- version: 0.49.0
208
+ version: 0.79.0
209
209
  - !ruby/object:Gem::Dependency
210
210
  name: serverspec
211
211
  requirement: !ruby/object:Gem::Requirement
212
212
  requirements:
213
213
  - - "~>"
214
214
  - !ruby/object:Gem::Version
215
- version: 2.36.1
215
+ version: 2.41.5
216
216
  type: :development
217
217
  prerelease: false
218
218
  version_requirements: !ruby/object:Gem::Requirement
219
219
  requirements:
220
220
  - - "~>"
221
221
  - !ruby/object:Gem::Version
222
- version: 2.36.1
222
+ version: 2.41.5
223
223
  - !ruby/object:Gem::Dependency
224
224
  name: test-kitchen
225
225
  requirement: !ruby/object:Gem::Requirement
226
226
  requirements:
227
227
  - - "~>"
228
228
  - !ruby/object:Gem::Version
229
- version: 1.16.0
229
+ version: 1.25.0
230
230
  type: :development
231
231
  prerelease: false
232
232
  version_requirements: !ruby/object:Gem::Requirement
233
233
  requirements:
234
234
  - - "~>"
235
235
  - !ruby/object:Gem::Version
236
- version: 1.16.0
236
+ version: 1.25.0
237
237
  - !ruby/object:Gem::Dependency
238
238
  name: yard
239
239
  requirement: !ruby/object:Gem::Requirement