====== [SCRIPT] Nagios plugin for PostgreSQL ====== ====== Description ====== A script for montiring nagios (like the oracle one). ====== Instructions ====== ===== OS user ===== Avoiding a privileged user for connecting to Postgre, I'll create an unprivileged user with a restricted shell (rbash): useradd -d /home/nagios -m -N -s /bin/bash nagios cat > /home/nagios/.bash_profile<> /home/nagios/.ssh/authorized_keys< ===== Database user ===== CREATE ROLE nagios LOGIN PASSWORD '****' ; ====== check_remote_postgres ====== ===== specific notes for each control ===== ==== sessions & asessions ==== Nagios db user does not have enough permissions to query the pg_stat_activity view. So I've created a "public" function to access that data (I hope improve it soon): With the dba user: CREATE OR REPLACE FUNCTION public.nagios_stat_activity() RETURNS SETOF pg_catalog.pg_stat_activity AS $BODY$ DECLARE rec RECORD; BEGIN FOR rec IN SELECT * FROM pg_stat_activity LOOP RETURN NEXT rec; END LOOP; RETURN; END; $BODY$ LANGUAGE plpgsql SECURITY DEFINER; And check with the nagios user: select * from public.nagios_stat_activity() ; ===== script code ===== #!/bin/bash