[ SEA-GHOST MINI SHELL]

Path : /proc/2/cwd/etc/zabbix/zabbix_agentd.d/
FILE UPLOADER :
Current File : //proc/2/cwd/etc/zabbix/zabbix_agentd.d/userparameter_postgresql.conf

# Background writer statistics. http://www.postgresql.org/docs/9.3/static/monitoring-stats.html#PG-STAT-BGWRITER-VIEW
UserParameter=pgsql.bgwriter.checkpoints_timed,sudo sudo -u postgres psql -qAtX  -c "select checkpoints_timed from pg_stat_bgwriter"
UserParameter=pgsql.bgwriter.checkpoints_req,sudo sudo -u postgres psql -qAtX  -c "select checkpoints_req from pg_stat_bgwriter"
UserParameter=pgsql.bgwriter.checkpoint_write_time,sudo sudo -u postgres psql -qAtX  -c "select checkpoint_write_time from pg_stat_bgwriter"
UserParameter=pgsql.bgwriter.checkpoint_sync_time,sudo sudo -u postgres psql -qAtX  -c "select checkpoint_sync_time from pg_stat_bgwriter"
UserParameter=pgsql.bgwriter.buffers_checkpoint,sudo sudo -u postgres psql -qAtX  -c "select buffers_checkpoint from pg_stat_bgwriter"
UserParameter=pgsql.bgwriter.buffers_clean,sudo sudo -u postgres psql -qAtX  -c "select buffers_clean from pg_stat_bgwriter"
UserParameter=pgsql.bgwriter.maxwritten_clean,sudo sudo -u postgres psql -qAtX  -c "select maxwritten_clean from pg_stat_bgwriter"
UserParameter=pgsql.bgwriter.buffers_backend,sudo sudo -u postgres psql -qAtX  -c "select buffers_backend from pg_stat_bgwriter"
UserParameter=pgsql.bgwriter.buffers_backend_fsync,sudo sudo -u postgres psql -qAtX  -c "select buffers_backend_fsync from pg_stat_bgwriter"
UserParameter=pgsql.bgwriter.buffers_alloc,sudo sudo -u postgres psql -qAtX  -c "select buffers_alloc from pg_stat_bgwriter"

# General info
UserParameter=pgsql.ping,/bin/echo -e "\\\timing \n select 1" | sudo sudo -u postgres psql -qAtX  | tail -n 1 |cut -d' ' -f2
UserParameter=pgsql.uptime,sudo sudo -u postgres psql -qAtX  -c "select date_part('epoch', now() - pg_postmaster_start_time())::int"
UserParameter=pgsql.cache.hit,sudo sudo -u postgres psql -qAtX  -c "select round(sum(blks_hit)*100/sum(blks_hit+blks_read), 2) from pg_stat_database"

# Connections 
UserParameter=pgsql.connections.active,sudo sudo -u postgres psql -qAtX  -c "select count(*) from pg_stat_activity where state = 'active'"
UserParameter=pgsql.connections.idle,sudo sudo -u postgres psql -qAtX  -c "select count(*) from pg_stat_activity where state = 'idle'"
UserParameter=pgsql.connections.idle_in_transaction,sudo sudo -u postgres psql -qAtX  -c "select count(*) from pg_stat_activity where state = 'idle in transaction'"
UserParameter=pgsql.connections.total,sudo sudo -u postgres psql -qAtX  -c "select count(*) from pg_stat_activity"
UserParameter=pgsql.connections.total_pct,sudo sudo -u postgres psql -qAtX  -c "select count(*)*100/(select current_setting('max_connections')::int) from pg_stat_activity"
UserParameter=pgsql.connections.waiting,sudo sudo -u postgres psql -qAtX  -c "select count(*) from pg_stat_activity where waiting"
UserParameter=pgsql.connections.prepared,sudo sudo -u postgres psql -qAtX  -c "select count(*) from pg_prepared_xacts"

# Size of database, table or indexes of specified table
UserParameter=pgsql.db.size[*],sudo sudo -u postgres psql -qAtX  -c "select pg_database_size('$1')"
UserParameter=pgsql.table.size[*],sudo sudo -u postgres psql $1 -qAtX  -c "select pg_relation_size('$2')"
UserParameter=pgsql.index.size[*],sudo sudo -u postgres psql $1 -qAtX  -c "select pg_total_relation_size('$2') - pg_relation_size('$2')"

# Summary database statistics
UserParameter=pgsql.dbstat.sum.numbackends,sudo sudo -u postgres psql -qAtX  -c "select sum(numbackends) from pg_stat_database"
UserParameter=pgsql.dbstat.sum.xact_commit,sudo sudo -u postgres psql -qAtX  -c "select sum(xact_commit) from pg_stat_database"
UserParameter=pgsql.dbstat.sum.xact_rollback,sudo sudo -u postgres psql -qAtX  -c "select sum(xact_rollback) from pg_stat_database"
UserParameter=pgsql.dbstat.sum.blks_read,sudo sudo -u postgres psql -qAtX  -c "select sum(blks_read) from pg_stat_database"
UserParameter=pgsql.dbstat.sum.blks_hit,sudo sudo -u postgres psql -qAtX  -c "select sum(blks_hit) from pg_stat_database"
UserParameter=pgsql.dbstat.sum.tup_returned,sudo sudo -u postgres psql -qAtX  -c "select sum(tup_returned) from pg_stat_database"
UserParameter=pgsql.dbstat.sum.tup_fetched,sudo sudo -u postgres psql -qAtX  -c "select sum(tup_fetched) from pg_stat_database"
UserParameter=pgsql.dbstat.sum.tup_inserted,sudo sudo -u postgres psql -qAtX  -c "select sum(tup_inserted) from pg_stat_database"
UserParameter=pgsql.dbstat.sum.tup_updated,sudo sudo -u postgres psql -qAtX  -c "select sum(tup_updated) from pg_stat_database"
UserParameter=pgsql.dbstat.sum.tup_deleted,sudo sudo -u postgres psql -qAtX  -c "select sum(tup_deleted) from pg_stat_database"
UserParameter=pgsql.dbstat.sum.conflicts,sudo sudo -u postgres psql -qAtX  -c "select sum(conflicts) from pg_stat_database"
UserParameter=pgsql.dbstat.sum.temp_files,sudo sudo -u postgres psql -qAtX  -c "select sum(temp_files) from pg_stat_database"
UserParameter=pgsql.dbstat.sum.temp_bytes,sudo sudo -u postgres psql -qAtX  -c "select sum(temp_bytes) from pg_stat_database"
UserParameter=pgsql.dbstat.sum.deadlocks,sudo sudo -u postgres psql -qAtX  -c "select sum(deadlocks) from pg_stat_database"

# Specified database statistics
UserParameter=pgsql.dbstat.numbackends[*],sudo sudo -u postgres psql -qAtX  -c "select numbackends from pg_stat_database where datname = '$1'"
UserParameter=pgsql.dbstat.xact_commit[*],sudo sudo -u postgres psql -qAtX  -c "select xact_commit from pg_stat_database where datname = '$1'"
UserParameter=pgsql.dbstat.xact_rollback[*],sudo sudo -u postgres psql -qAtX  -c "select xact_rollback from pg_stat_database where datname = '$1'"
UserParameter=pgsql.dbstat.blks_read[*],sudo sudo -u postgres psql -qAtX  -c "select blks_read from pg_stat_database where datname = '$1'"
UserParameter=pgsql.dbstat.blks_hit[*],sudo sudo -u postgres psql -qAtX  -c "select blks_hit from pg_stat_database where datname = '$1'"
UserParameter=pgsql.dbstat.tup_returned[*],sudo sudo -u postgres psql -qAtX  -c "select tup_returned from pg_stat_database where datname = '$1'"
UserParameter=pgsql.dbstat.tup_fetched[*],sudo sudo -u postgres psql -qAtX  -c "select tup_fetched from pg_stat_database where datname = '$1'"
UserParameter=pgsql.dbstat.tup_inserted[*],sudo sudo -u postgres psql -qAtX  -c "select tup_inserted from pg_stat_database where datname = '$1'"
UserParameter=pgsql.dbstat.tup_updated[*],sudo sudo -u postgres psql -qAtX  -c "select tup_updated from pg_stat_database where datname = '$1'"
UserParameter=pgsql.dbstat.tup_deleted[*],sudo sudo -u postgres psql -qAtX  -c "select tup_deleted from pg_stat_database where datname = '$1'"
UserParameter=pgsql.dbstat.conflicts[*],sudo sudo -u postgres psql -qAtX  -c "select conflicts from pg_stat_database where datname = '$1'"
UserParameter=pgsql.dbstat.temp_files[*],sudo sudo -u postgres psql -qAtX  -c "select temp_files from pg_stat_database where datname = '$1'"
UserParameter=pgsql.dbstat.temp_bytes[*],sudo sudo -u postgres psql -qAtX  -c "select temp_bytes from pg_stat_database where datname = '$1'"
UserParameter=pgsql.dbstat.deadlocks[*],sudo sudo -u postgres psql -qAtX  -c "select deadlocks from pg_stat_database where datname = '$1'"

# Table statistics (pg_stat_user_tables and pg_statio_user_tables) 
UserParameter=pgsql.table.stat.heap_blks_read[*],sudo sudo -u postgres psql $1 -qAtX  -c "select coalesce(heap_blks_read,0) from pg_statio_user_tables where relname = '$2'"
UserParameter=pgsql.table.stat.heap_blks_hit[*],sudo sudo -u postgres psql $1 -qAtX  -c "select coalesce(heap_blks_hit,0) from pg_statio_user_tables where relname = '$2'"
UserParameter=pgsql.table.stat.idx_blks_read[*],sudo sudo -u postgres psql $1 -qAtX  -c "select coalesce(idx_blks_read,0) from pg_statio_user_tables where relname = '$2'"
UserParameter=pgsql.table.stat.idx_blks_hit[*],sudo sudo -u postgres psql $1 -qAtX  -c "select coalesce(idx_blks_hit,0) from pg_statio_user_tables where relname = '$2'"
UserParameter=pgsql.table.stat.toast_blks_read[*],sudo sudo -u postgres psql $1 -qAtX  -c "select coalesce(toast_blks_read,0) from pg_statio_user_tables where relname = '$2'"
UserParameter=pgsql.table.stat.toast_blks_hit[*],sudo sudo -u postgres psql $1 -qAtX  -c "select coalesce(toast_blks_hit,0) from pg_statio_user_tables where relname = '$2'"
UserParameter=pgsql.table.stat.tidx_blks_read[*],sudo sudo -u postgres psql $1-qAtX  -c "select coalesce(tidx_blks_read,0) from pg_statio_user_tables where relname = '$2'"
UserParameter=pgsql.table.stat.tidx_blks_hit[*],sudo sudo -u postgres psql $1 -qAtX  -c "select coalesce(tidx_blks_hit,0) from pg_statio_user_tables where relname = '$2'"
UserParameter=pgsql.table.stat.seq_scan[*],sudo sudo -u postgres psql $1 -qAtX -c "select coalesce(seq_scan,0) from pg_stat_user_tables where relname = '$2'"
UserParameter=pgsql.table.stat.seq_tup_read[*],sudo sudo -u postgres psql $1 -qAtX  -c "select coalesce(seq_tup_read,0) from pg_stat_user_tables where relname = '$2'"
UserParameter=pgsql.table.stat.idx_scan[*],sudo sudo -u postgres psql $1 -qAtX -c "select coalesce(idx_scan,0) from pg_stat_user_tables where relname = '$2'"
UserParameter=pgsql.table.stat.idx_tup_fetch[*],sudo sudo -u postgres psql $1 -qAtX  -c "select coalesce(idx_tup_fetch,0) from pg_stat_user_tables where relname = '$2'"
UserParameter=pgsql.table.stat.n_tup_ins[*],sudo sudo -u postgres psql $1 -qAtX -c "select coalesce(n_tup_ins,0) from pg_stat_user_tables where relname = '$2'"
UserParameter=pgsql.table.stat.n_tup_del[*],sudo sudo -u postgres psql $1 -qAtX -c "select coalesce(n_tup_del,0) from pg_stat_user_tables where relname = '$2'"
UserParameter=pgsql.table.stat.n_tup_upd[*],sudo sudo -u postgres psql $1 -qAtX -c "select coalesce(n_tup_upd,0) from pg_stat_user_tables where relname = '$2'"
UserParameter=pgsql.table.stat.n_tup_hot_upd[*],sudo sudo -u postgres psql $1 -qAtX -c "select coalesce(n_tup_hot_upd,0) from pg_stat_user_tables where relname = '$2'"
UserParameter=pgsql.table.stat.n_live_tup[*],sudo sudo -u postgres psql $1 -qAtX -c "select coalesce(n_live_tup,0) from pg_stat_user_tables where relname = '$2'"
UserParameter=pgsql.table.stat.n_dead_tup[*],sudo sudo -u postgres psql $1 -qAtX -c "select coalesce(n_dead_tup,0) from pg_stat_user_tables where relname = '$2'"
UserParameter=pgsql.table.stat.vacuum_count[*],sudo sudo -u postgres psql $1 -qAtX -c "select coalesce(vacuum_count,0) from pg_stat_user_tables where relname = '$2'"
UserParameter=pgsql.table.stat.autovacuum_count[*],sudo sudo -u postgres psql $1 -qAtX -c "select coalesce(autovacuum_count,0) from pg_stat_user_tables where relname = '$2'"
UserParameter=pgsql.table.stat.analyze_count[*],sudo sudo -u postgres psql $1 -qAtX -c "select coalesce(analyze_count,0) from pg_stat_user_tables where relname = '$2'"
UserParameter=pgsql.table.stat.autoanalyze_count[*],sudo sudo -u postgres psql $1 -qAtX -c "select coalesce(autoanalyze_count,0) from pg_stat_user_tables where relname = '$2'"

# Transactions
UserParameter=pgsql.transactions.idle,sudo sudo -u postgres psql -qAtX  -c "select coalesce(extract(epoch from max(age(now(), query_start))), 0) from pg_stat_activity where state='idle in transaction'"
UserParameter=pgsql.transactions.active,sudo sudo -u postgres psql -qAtX  -c "select coalesce(extract(epoch from max(age(now(), query_start))), 0) from pg_stat_activity where state <> 'idle in transaction' and state <> 'idle'"
UserParameter=pgsql.transactions.waiting,sudo sudo -u postgres psql -qAtX  -c "select coalesce(extract(epoch from max(age(now(), query_start))), 0) from pg_stat_activity where waiting"
UserParameter=pgsql.transactions.prepared,sudo sudo -u postgres psql -qAtX  -c "select coalesce(extract(epoch from max(age(now(), prepared))), 0) from pg_prepared_xacts"

# Others
UserParameter=pgsql.table.tuples[*],sudo sudo -u postgres psql $1 -qAtX  -c "select count(*) from $2"
UserParameter=pgsql.setting[*],sudo sudo -u postgres psql $1 -qAtX  -c "select current_setting('$2')"
UserParameter=pgsql.trigger[*],sudo sudo -u postgres psql $1 -qAtX  -c "select count(*) from pg_trigger where tgenabled='O' and tgname='$2'"
UserParameter=pgsql.wal.write[*],sudo sudo -u postgres psql $1 -qAtX  -c "select pg_xlog_location_diff(pg_current_xlog_location(),'0/00000000')"
UserParameter=pgsql.wal.count[*],sudo sudo -u postgres psql $1 -qAtX  -c "select count(*) from pg_ls_dir('pg_xlog')"

# Discovery
UserParameter=pgsql.db.discovery,/bin/echo -n '{"data":['; for db in $(sudo sudo -u postgres psql -qAtX  -c "select datname from pg_database where not datistemplate and datallowconn and datname!='postgres'"); do /bin/echo -n "{\"{#DBNAME}\": \"$db\"},"; done |sed -e 's:,$::'; /bin/echo -n ']}'
UserParameter=pgsql.table.discovery[*],/bin/echo -n '{"data":['; for table in $(sudo sudo -u postgres psql $1 -qAtX -c "select table_name from information_schema.tables where table_schema='public' ORDER BY table_name"); do /bin/echo -n "{\"{#TABLENAME}\": \"$table\"},"; done |sed -e 's:\},$:\}:'; /bin/echo -n ']}'

# Replication
UserParameter=pgsql.replication.status[*], psql -qtAX -h "$1" -p "$2" -U "$3" -d "$4" -f "/var/lib/zabbix/pgsql.replication.status.sql"
UserParameter=pgsql.replication.lag.sec[*], psql -qtAX -h "$1" -p "$2" -U "$3" -d "$4" -f "/var/lib/zabbix/pgsql.replication.lag.sql"

SEA-GHOST - SHELL CODING BY SEA-GHOST