lesovsky / zabbix-extensions

Zabbix additional monitoring modules
BSD 3-Clause "New" or "Revised" License
316 stars 230 forks source link

Error restarting zabbix agent after adding Postgresql #85

Closed MichaelDBA closed 2 years ago

MichaelDBA commented 3 years ago

I followed the instructions for adding Postgresql from the readme.md file here: https://github.com/lesovsky/zabbix-extensions/blob/master/files/postgresql/README.md

Then when i tried to restart the zabbix agent (I'm using zabbix 5.2 and PostgreSQL 13), I got this error:

zabbix_agentd [3555]: ERROR: cannot add user parameter "pgsql.bgwriter[*],psql -qAtX $1 -c "SELECT row_to_json(j) FROM (SELECT checkpoints_timed, checkpoints_req, checkpoint_write_time, ch>
Nov 01 09:09:23 michaelv2 systemd[1]: zabbix-agent.service: Control process exited, code=exited status=1
Nov 01 09:09:23 michaelv2 systemd[1]: zabbix-agent.service: Failed with result 'exit-code'.
Nov 01 09:09:23 michaelv2 systemd[1]: Failed to start Zabbix Agent.
-- Subject: Unit zabbix-agent.service has failed

I have trust turned on for everything in pg_hba.conf.

I tested using zabbix_get and here is the output:

zabbix_get -s 127.0.0.1 -k pgsql.ping['-h 127.0.0.1 -p 5432 -U postgres -d postgres']
-->
-h 127.0.0.1 -p 5432 -U postgres -d postgres: - no response
stephankn commented 3 years ago

This sounds like you have a general problem accessing the PostgreSQL server from the zabbix user account and not something with the scripts. Configuration parameters are set in the macro PG_CONNINFO.

You can verify connection manually from the command line. Assuming that you installed as user zabbix, you can try this, which should list all available databases:

sudo -u zabbix psql -h 127.0.0.1 -p 5432 -U postgres -d postgres -l

If this fails, then something is not in order with your PostgreSQL connection setup. Refer to PostgreSQL documentation on how to configure access to the database. Things to check is whether it connects using IP on localhost (your database is on the same server, right?) and permissions. Please also double-check that the server is actually up and running.

It should listen on localhost, otherwise you need to change either your connection mode or server configuration:

netstat -ln4 | grep 5432
MichaelDBA commented 3 years ago

Well that command works for me: sudo -u zabbix psql -h 127.0.0.1 -p 5432 -U postgres -d postgres -l

Apparently the problem is related to what I am pulling in with this from zabbix_agentd.conf: Include=/etc/zabbix/zabbix_agentd.d/*.conf

And this is what I have in /etc/zabbix/zabbix/zabbix_agentd.d:

template_db_postgresql.conf
userparameter_pgsql.conf
zabbix-extensions.conf

If I change the include to use only one of those files, it works: Include=/etc/zabbix/zabbix_agentd.d/zabbix-extensions.conf

stephankn commented 3 years ago

The PostgreSQL template I maintain brings the postgresql.conf config with UserParameter scripts for the individual items. Your failing zabbix_get call hints toward a connection issue to your database server. The systemd error more towards an issue with the config.

Maybe check the config first. Did you have any additional errors logged? zabbix agent log or other entries in the journal? What are the other files in your zabbix_agent.d folder? Do some of them configure items with a conflicting name? Which file is from here? You have two which point towards Postgresql.

MichaelDBA commented 2 years ago

Sorry for not closing this earlier. I am using zabbix 5.4 now and I don't have this problem anymore.