mikaku / Monitorix

Monitorix is a free, open source, lightweight system monitoring tool.
https://www.monitorix.org
GNU General Public License v2.0
1.12k stars 167 forks source link

pgsql module using user with limited access fails. #404

Closed whotopia closed 2 years ago

whotopia commented 2 years ago
 ERROR: while updating /var/lib/monitorix/pgsql.rrd: /var/lib/monitorix/pgsql.rrd: Function update_pdp_prep, case DST_GAUGE - Cannot convert '' to float
Use of uninitialized value $tsize in concatenation (.) or string at /usr/lib/monitorix/pgsql.pm line 459.

I have tested the new pgsql module. It works great when using postgres admin user. However, I created a postgres user with limited access specifically for monitoring.

CREATE USER aos_monitor WITH PASSWORD 'XXXX' INHERIT; GRANT pg_monitor TO aos_monitor;

With this user, the tsize operation fails during SELECT SUM(pg_database_size(datid)) AS total_size FROM pg_stat_database;

as postgres user, this returns valid data. However as a user with only pg_monitor access the SQL query returns ERROR: database with OID 0 does not exist

Reviewing all of the $dbh-prepare() calls in /usr/lib/monitorix/pgsql.pm, it looks to me like the pg_monitor constraint should be sufficient in postgres to get all the data Monitorix needs.

So, either, I guess I'm either reporting a bug here, or requesting that someone share what the minimal permissions are that need to be assigned to postgres pgsql monitorix user for all query operations in pgsql.pm to work?

Thanks!

whotopia commented 2 years ago

I noted updated change to line in pgsql.pm from

$sth = $dbh->prepare("SELECT SUM(pg_database_size(datid)) AS total_size FROM pg_stat_database");

to

$sth = $dbh->prepare("SELECT SUM(pg_database_size(datid)) AS total_size FROM pg_stat_database WHERE datid>0");

This fixed the problem for me.

mikaku commented 2 years ago

Yes, you're right, this was a bug and has been already addressed in #384. You might want to apply the small patch to fix this problem.

Thanks for your feedback!