Skip to content

Commit 525442b

Browse files
Micasoueheydrick
authored andcommitted
Add functionality for retrieving multi row query responses (#29)
* Added functionality for retrieving multi row query responses. * Updated changelog and fixed syntax to pass rubocop requirements. * Added logic flow to handle a special case. Fixed the return loop to properly return the query rows. * Fixed an offense from Rubocop, spacing was off. * Updated multirow option to be more representative of its functionality.
1 parent 028ccec commit 525442b

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
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 at [Keep A Changelog](http://keepachangelog.com/)
55

66
## [Unreleased]
7+
### Updated
8+
- metrics-postgres-query.rb: Added option to return multi row queries.
9+
710
### Fixed
811
- check-postgres-alive.rb: Fix connections using a custom port (#25)
912
- check-postgres-connections.rb: Fix connections using a custom port (#25)

bin/metrics-postgres-query.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ class MetricsPostgresQuery < Sensu::Plugin::Metric::CLI::Graphite
7878
long: '--scheme SCHEME',
7979
default: 'postgres'
8080

81+
option :multirow,
82+
description: 'Determines if we return first row or all rows',
83+
short: '-m',
84+
long: '--multirow',
85+
boolean: true,
86+
default: false
87+
8188
option :timeout,
8289
description: 'Connection timeout (seconds)',
8390
short: '-T TIMEOUT',
@@ -100,10 +107,16 @@ def run
100107
value = if config[:count_tuples]
101108
res.ntuples
102109
else
103-
res.first.values.first
110+
res.values
104111
end
105112

106-
output config[:scheme], value
113+
if config[:multirow] && !config[:count_tuples]
114+
value.each do |row|
115+
output "#{config[:scheme]}.#{row[0]}", row[1]
116+
end
117+
else
118+
output config[:scheme], value
119+
end
107120
ok
108121
end
109122
end

0 commit comments

Comments
 (0)