thecamels-zabbix/bin/pgsql_find_db.sh

12 lines
495 B
Bash
Raw Normal View History

2016-05-02 09:29:00 +02:00
#!/bin/bash
# If you want to monitor "foo" and "bar" databases, you set the GETDB as
# GETDB="select datname from pg_database where datname in ('foo','bar');"
# CREATE USER zabbix WITH PASSWORD 'asfrtgrg432f';
# GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO zabbix;
GETDB="select datname from pg_database where datistemplate = 'f';"
for dbname in $(psql -U zabbix -d postgres -t -c "${GETDB}"); do
dblist="$dblist,"'{"{#DBNAME}":"'$dbname'"}'
done
echo '{"data":['${dblist#,}' ]}'