Module: check_mk
Branch: master
Commit: a2cd68cdae023ad225cff6e2a6fc5d51bd298aa9
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a2cd68cdae023a…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Mon Mar 10 14:03:13 2014 +0100
mk_postgres: improved support for versions postgres < 9.2
Postgres < 9.2 didn't know the pg_stat_activity column 'query'.
This caused an entry in the error log.
The new mk_postgres plugin is now able to handle this smarter.
---
.werks/731 | 10 ++++++++++
ChangeLog | 1 +
agents/plugins/mk_postgres | 10 +++++-----
3 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/.werks/731 b/.werks/731
new file mode 100644
index 0000000..2307b01
--- /dev/null
+++ b/.werks/731
@@ -0,0 +1,10 @@
+Title: mk_postgres: improved support for versions postgres < 9.2
+Level: 1
+Component: checks
+Version: 1.2.5i1
+Date: 1394456453
+Class: feature
+
+Postgres < 9.2 didn't know the pg_stat_activity column 'query'.
+This caused an entry in the error log.
+The new mk_postgres plugin is now able to handle this smarter.
diff --git a/ChangeLog b/ChangeLog
index 8565e88..21c69c2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -102,6 +102,7 @@
* 0138 Removed caching function in Windows Update agent plugin...
NOTE: Please refer to the migration notes!
* 0564 esx_vsphere_vm.datastores: displays the datastores of the VM...
+ * 0731 mk_postgres: improved support for versions postgres < 9.2...
* 0103 FIX: services: Fixed bug with service inventory defined in main.mk...
* 0299 FIX: borcade_mlx_fan: Prettified output, handling "other" state now
* 0300 FIX: cisco_fru_power: Trying not to inventorize not plugged in FRUs...
diff --git a/agents/plugins/mk_postgres b/agents/plugins/mk_postgres
index dc92a20..9b135d0 100755
--- a/agents/plugins/mk_postgres
+++ b/agents/plugins/mk_postgres
@@ -11,11 +11,11 @@ fi
echo '<<<postgres_sessions>>>'
# Postgres 9.2 uses 'query' instead of 'current_query'
-for name in query current_query
-do
- OUTPUT="$(echo "select $name = '<IDLE>', count(*) from
pg_stat_activity group by ($name = '<IDLE>');" |\
- su - $USER -c "psql --variable ON_ERROR_STOP=1 -d postgres -A -t -F'
'" 2>/dev/null)" && break
-done
+QNAME="$(echo "select column_name from information_schema.columns where
table_name='pg_stat_activity' and column_name in
('query','current_query');" |\
+ su - $USER -c "psql -d postgres -t -A -F';'")"
+OUTPUT="$(echo "select $QNAME = '<IDLE>', count(*) from
pg_stat_activity group by ($QNAME = '<IDLE>');" |\
+ su - $USER -c "psql --variable ON_ERROR_STOP=1 -d postgres -A -t -F'
'" 2>/dev/null)"
+
echo "$OUTPUT"
# line with number of idle sessions is sometimes missing on Postgre 8.x. This can lead
# to an altogether empty section and thus the check disappearing.