[checkmk-commits] Check_MK Git: check_mk: #1243 FIX mk_postgres: Prevent loading of .psqlrc

Bastian Kuhn bk at mathias-kettner.de
Fri Apr 24 10:13:40 CEST 2015


Module: check_mk
Branch: master
Commit: cb830004e8beb4a51241865df31f131d5a179272
URL:    http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=cb830004e8beb4a51241865df31f131d5a179272

Author: Bastian Kuhn <bk at mathias-kettner.de>
Date:   Fri Apr 24 10:13:35 2015 +0200

#1243 FIX mk_postgres: Prevent loading of .psqlrc

If the user has a ~/.psqlrc file whit options like \timing on, this leads to unexcpected output by psql.
While this is untestet, that fix is not included in 1.2.6. But you can currently use the git version to test.

---

 .werks/1243                |   11 +++++++++++
 ChangeLog                  |    1 +
 agents/plugins/mk_postgres |   22 +++++++++++-----------
 3 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/.werks/1243 b/.werks/1243
new file mode 100644
index 0000000..bb857f8
--- /dev/null
+++ b/.werks/1243
@@ -0,0 +1,11 @@
+Title: mk_postgres: Prevent loading of .psqlrc
+Level: 1
+Component: checks
+Compatible: compat
+Version: 1.2.7i1
+Date: 1429863051
+Class: fix
+
+If the user has a ~/.psqlrc file whit options like \timing on, this leads to unexcpected output by psql.
+While this is untestet, that fix is not included in 1.2.6. But you can currently use the git version to test.
+
diff --git a/ChangeLog b/ChangeLog
index d2c0133..99ce600 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -342,6 +342,7 @@
     * 2069 FIX: netapp_api_disk.summary: fixed one missing disk in summary check...
     * 2070 FIX: agent_netapp: fixed exception when a channel has no shelf-list configured
     * 2212 FIX: oracle_tablespaces: Fix plugin output in case of detected problem in Autoextend settings...
+    * 1243 FIX: mk_postgres: Prevent loading of .psqlrc...
 
     Multisite:
     * 1758 Improved exception hander: Shows details without additional debug request, added mailto link for error report...
diff --git a/agents/plugins/mk_postgres b/agents/plugins/mk_postgres
index c4f6b2c..9c9ae52 100755
--- a/agents/plugins/mk_postgres
+++ b/agents/plugins/mk_postgres
@@ -44,9 +44,9 @@ function compare_version_greater_equal() {
 echo '<<<postgres_sessions>>>'
 # Postgres 9.2 uses 'query' instead of 'current_query'
 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';'")"
+        su - $USER -c "psql -X -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)"
+    su - $USER -c "psql -X --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
@@ -55,18 +55,18 @@ echo "$OUTPUT" | grep -q '^t ' || echo "t 0"
 
 echo '<<<postgres_stat_database:sep(59)>>>'
 echo 'select datid, datname, numbackends, xact_commit, xact_rollback, blks_read, blks_hit, tup_returned, tup_fetched, tup_inserted, tup_updated, tup_deleted, pg_database_size(datname) "datsize" from pg_stat_database;' \
-    | su - $USER -c "psql -d postgres -A -F';'" | sed '$d'
+    | su - $USER -c "psql -X -d postgres -A -F';'" | sed '$d'
 
 
 DATABASES="$(echo "SELECT datname FROM pg_database WHERE datistemplate = false;" |\
-        su - $USER -c "psql -d postgres -t -A -F';'")"
+        su - $USER -c "psql -X -d postgres -t -A -F';'")"
 
-POSTGRES_VERSION=$(su - $USER -c "psql -V | egrep -o '[0-9]{1,}\.[0-9]{1,}'")
+POSTGRES_VERSION=$(su - $USER -c "psql -X -V | egrep -o '[0-9]{1,}\.[0-9]{1,}'")
 
 echo '<<<postgres_locks:sep(59)>>>'
 echo -e "[databases_start]\n$DATABASES\n[databases_end]"
 LOCKS="$(echo "SELECT datname, granted, mode FROM pg_locks l RIGHT JOIN pg_database d ON (d.oid=l.database) WHERE d.datallowconn;" |\
-        su - $USER -c "psql -d postgres -A -F';'")"
+        su - $USER -c "psql -X -d postgres -A -F';'")"
 echo "$LOCKS" | sed '$d'
 
 
@@ -83,7 +83,7 @@ QUERYTIME_QUERY="SELECT datname, datid, usename, client_addr, '' AS state,    CO
 fi
 
 QUERYTIME="$(echo "$QUERYTIME_QUERY" |\
-        su - $USER -c "psql -d postgres -A -F';'")"
+        su - $USER -c "psql -X -d postgres -A -F';'")"
 echo "$QUERYTIME" | sed '$d'
 
 # Contains last vacuum time and analyze time
@@ -101,7 +101,7 @@ for db in $DATABASES ; do
           AND n.oid = c.relnamespace
           AND n.nspname <> 'information_schema'
           ORDER BY 3) AS foo;" |\
-            su - $USER -c "psql -d $db $FIRST-A -F';'")"
+            su - $USER -c "psql -X -d $db $FIRST-A -F';'")"
     LASTVACUUM=$(echo "$LASTVACUUM" | grep -v -e 'COMMIT$' -e 'SET$' -e 'BEGIN$')
     if [ -z $FIRST ] ; then
         FIRST="-t "
@@ -114,7 +114,7 @@ done
 # Postgres version an connection time
 echo '<<<postgres_version:sep(1)>>>'
 (TIMEFORMAT='%3R'; time echo "SELECT version() AS v" |\
- su - $USER -c "psql -d postgres -t -A -F';'; echo '<<<postgres_conn_time>>>'") 2>&1
+ su - $USER -c "psql -X -d postgres -t -A -F';'; echo '<<<postgres_conn_time>>>'") 2>&1
 
 # Number of current connections per database
 echo '<<<postgres_connections:sep(59)>>>'
@@ -140,7 +140,7 @@ ORDER BY datname"
 fi
 
 CONNECTIONS="$(echo "$CONNECTIONS_QUERY" |\
-            su - $USER -c "psql -d postgres -A -F';'")"
+            su - $USER -c "psql -X -d postgres -A -F';'")"
 CONNECTIONS=$(echo "$CONNECTIONS" | grep -v -e 'COMMIT$' -e 'SET$' -e 'BEGIN$')
 echo "$CONNECTIONS" | sed '$d'
 
@@ -295,7 +295,7 @@ fi
 
 FIRST=""
 for db in $DATABASES ; do
-    RESPONSE="$(echo "$BLOAT_QUERY" | su - $USER -c "psql -d $db $FIRST-A -F';'")"
+    RESPONSE="$(echo "$BLOAT_QUERY" | su - $USER -c "psql -X -d $db $FIRST-A -F';'")"
     if [ -z $FIRST ] ; then
         FIRST="-t "
         echo "$RESPONSE" | sed '$d'



More information about the checkmk-commits mailing list