[checkmk-commits] Check_MK Git: check_mk: Linux Agent, mk_postgres: Supporting pgsql and postgres as user

git version control git at mathias-kettner.de
Wed Nov 21 16:43:51 CET 2012


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

Author: Lars Michelsen <lm at mathias-kettner.de>
Date:   Wed Nov 21 16:42:08 2012 +0100

Linux Agent, mk_postgres: Supporting pgsql and postgres as user

---

 ChangeLog                  |    3 +++
 agents/plugins/mk_postgres |   21 ++++++++++++++-------
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 07a633f..c977b00 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,7 @@
 1.2.1i4:
+    Checks & Agents:
+    * Linux Agent, mk_postgres: Supporting pgsql and postgres as user
+
     Multisite:
     * Implemented LDAP integration of Multisite. You can now authenticate your
       users using the form based authentication with LDAP. It is also possible
diff --git a/agents/plugins/mk_postgres b/agents/plugins/mk_postgres
index 6667aab..adeb761 100755
--- a/agents/plugins/mk_postgres
+++ b/agents/plugins/mk_postgres
@@ -1,10 +1,17 @@
 #!/bin/sh
 
-if id pgsql >/dev/null  ; then
-  echo '<<<postgres_sessions>>>'
-  echo "select current_query = '<IDLE>', count(*) from pg_stat_activity group by (current_query = '<IDLE>');" | su - pgsql -c "psql -d postgres -A -t -F' '"
-
-  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,conflicts, pg_database_size(datname) as "datsize" from pg_stat_database;' \
-     | su - pgsql -c "psql -d postgres -A -F';'" | sed '$d'
+# Try to detect the postgres user
+if id pgsql >/dev/null 2>&1; then
+    USER=pgsql
+elif id postgres >/dev/null 2>&1; then
+    USER=postgres
+else
+    exit 0
 fi
+
+echo '<<<postgres_sessions>>>'
+echo "select current_query = '<IDLE>', count(*) from pg_stat_activity group by (current_query = '<IDLE>');" | su - $USER -c "psql -d postgres -A -t -F' '"
+
+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,conflicts, pg_database_size(datname) as "datsize" from pg_stat_database;' \
+    | su - $USER -c "psql -d postgres -A -F';'" | sed '$d'



More information about the checkmk-commits mailing list