Postgres SNMP Application

Hi,

I’m having trouble configuring postgres application in libreNMS

Environment

Device:

Linux hveficent-ThinkPad-E570 4.13.0-31-generic #34~16.04.1-Ubuntu SMP Fri Jan 19 17:11:01 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

psql (PostgreSQL) 10.1

NET-SNMP version: 5.7.3

Steps to reproduce

1: Copy the shell script, postgres, to the desired host (the host must be added to LibreNMS devices)

wget https://github.com/librenms/librenms-agent/raw/master/snmp/postgres -O /etc/snmp/postgres

2: Make the script executable

chmod +x /etc/snmp/postgres

3: Install the Nagios check check_postgres.pl on your system.

git clone https://github.com/bucardo/check_postgres.git
cd check_postgres
perl Makefile.PL
make
env -i make test
make install
check_postgres.pl --version # check_postgres.pl version 2.23.0

4: Edit postgres file, I modified this script because I wasn’t unable to configure .pgpass properly:

#set the user here to use
#be sure to set up the user in .pgpass for the user snmpd is running as
DBuser=postgres
password=postgres
host=localhost
port=5432
# You may want to disable totalling for the postgres DB as that can make the total graphs artificially noisy.
# 1 = don't total stats for the DB postgres
# 0 = include postgres in the totals
ignorePG=1;

#make sure the paths are right for your system
cpg='/usr/local/bin/check_postgres.pl'


$cpg -u $DBuser --dbpass=$password -H $host -p $port --action dbstats | awk -F ' ' '

After save script I run it and suppose it works

>./postgres 
5
860
8
1798
70907
0
0
0
0
0
0
0
521950
31552
1
86
47
2 2540 4 1652 128073 0 0 0 0 0 0 0 1326119 39680 0 0 0 postgres
5 860 8 1798 70907 0 0 0 0 0 0 0 521950 31552 1 86 47 11.0-account_tax_balance
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 template1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 template0

5: Edit snmpd.conf file and add following line in extending the agent section.

extend postgres /etc/snmp/postgres

6: Restart snmpd service

sudo systemctl restart snmpd

Then I go to MyDevice/Edit/Add postgres App, but when I go to see the app it is like this:

Note: I’m running LibreNMS dockerized

https://github.com/hveficent/docker-librenms.git

Validate output

root@librenms:/opt/librenms# ./validate.php

Component Version
LibreNMS 1.35-142-g2755763
DB Schema 232
PHP 7.0.22-0ubuntu0.16.04.1
MySQL 10.2.12-MariaDB-10.2.12+maria~jessie
RRDTool 1.5.5
SNMP NET-SNMP 5.7.3
====================================
[OK]    Database connection successful
[OK]    Database schema correct
[FAIL]  You have a different system timezone () than the php configured timezone (CET)
	[FIX] Please correct either your system timezone or your timezone set in php.ini.
[WARN]  IPv6 is disabled on your server, you will not be able to add IPv6 devices.
[WARN]  Your local git contains modified files, this could prevent automatic updates.
	[FIX] You can fix this with ./scripts/github-remove
	Modified Files:
	 html/plugins/Test/Test.inc.php
	 html/plugins/Test/Test.php
[FAIL]  We have found some files that are owned by a different user than librenms, this will stop you updating automatically and / or rrd files being updated causing graphs to fail.
	[FIX] chown -R librenms:librenms /opt/librenms
	Files:
	 /opt/librenms/composer.phar
	 /opt/librenms/cache/os_defs.cache
[FAIL]  The rrd folder has improper permissions.
	[FIX] chmod ug+rw /opt/librenms/rrd

After fixing chmod issues same is happening

What am I doing wrong??

Thanks!

I was having a similar problem with PHP-FPM that was related to the file that generates the graphs and for what I look into the code for the php scripts that generates the postgres graphics, it could be the same problem.

Can you do a simple test?

Edit the following file:
/opt/librenms/html/includes/graphs/application/postgres_backends.inc.php

Look for this line (line 23):

if (is_file($rrd_filename)) {

Change is_file to rrdtool_check_rrd_exists:

if (rrdtool_check_rrd_exists($rrd_filename)) {

Save the file and reload the page to see if some graph appears.

Thank you for the advice @leandrojmp.

Yes, now graphs structure is displayed but no information inside. I think problem is not directly related by this issue. Anyway this is the result.

I’ve modify check_postgres.pl path from /etc/snmp/postgres:
From:

cpg='check_postgres.pl'

To:

cpg='/usr/local/bin/check_postgres.pl'

because I was trying to call snmp manually and it doesn’t respond.

snmpget -u bootstrap -l authPriv -a MD5 -x DES -A temp_password -X temp_password 172.18.0.1 .1.3.6.1.4.1.8072.1.3.2.3.1.2.8.112.111.115.116.103.114.101.115
NET-SNMP-EXTEND-MIB::nsExtendOutputFull."postgres" = STRING: 4
11890
48
6678
2109670
0
0
0
0
0
0
0
20412031
996803
46441
13868
290
2 3881 22 2035 193994 0 0 0 0 0 0 0 1994832 60388 0 7 0 postgres
0 6511 39 2802 383920 0 0 0 0 0 0 0 4745623 68621 1 601 47 11.0-account_tax_balance
0 195 0 157 8621 0 0 0 0 0 0 0 99464 2314 0 7 0 template1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 template0
4 5184 9 3719 1717129 0 0 0 0 0 0 0 15566944 925868 46440 13260 243 10.0-mrp_bom_structure_xlsx

Following @leandrojmp tip I’ve changed that line in all /opt/librenms/html/includes/graphs/application/postgres_*.inc.php

and now is working :smiley:

Thank you so much!

oh, great!

I will make a pull request changing the is_file function to rrdtool_check_rrd_exists on the postgres files.

Until it is merged, maybe you will have problem updating, it will gives an warning that some files are different.

1 Like