Skip to content

Commit 4990fc1

Browse files
jindrajmajormoses
authored andcommitted
Add regex pattern to match the query output
1 parent a3c7e0d commit 4990fc1

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
44
This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md).
55

66
## [Unreleased]
7+
### Added
8+
- `check-postgres-query.rb`: Add `-r`, `--regex-pattern` to match query result against (@jindraj)
9+
710
### Changes
811
- Updated development dependency to bundler ~> 2.1
912
- Updated development dependency to rake ~> 13.0

bin/check-postgres-query.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ class CheckPostgresQuery < Sensu::Plugin::Check::CLI
7575
long: '--query QUERY',
7676
required: true
7777

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+
7883
option :check_tuples,
7984
description: 'Check against the number of tuples (rows) returned by the query',
8085
short: '-t',
@@ -127,6 +132,8 @@ def run
127132
critical "Results: #{res.values}"
128133
elsif config[:warning] && calc.evaluate(config[:warning], value: value)
129134
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]}"
130137
else
131138
ok 'Query OK'
132139
end

0 commit comments

Comments
 (0)