File not found while running /etc/snmp/mysql

Hi,

I have been trying to enable the MySQL application on my LibreNMS server but no data is being loaded into RRD. I have tried to run the /etc/snmp/mysql script manually, but got this error:

root@server2:/etc/snmp# ./mysql
ERROR: No such file or directory

I really don’t know anything about PHP to debug this error, could anyone with more experience give me a hand with fixing this?

Thanks!

have you downloaded mysql script from https://github.com/librenms/librenms-agent/tree/master/snmp to /etc/snmp directory?

I was using the version from raw instead of tree. The version you suggest provided a different error:

root@server2:/etc/snmp# ./mysql
./mysql: line 6: syntax error near unexpected token `newline'
./mysql: line 6: `<!DOCTYPE html>'
root@server2:/etc/snmp#

are all dependencies installed/done?

https://docs.librenms.org/Extensions/Applications/#mysql

I was actually going for SNMP extend, but I will deploy the agent to see if it works.

all dependencies installed, but I am still getting the same error:

root@server2:/etc/snmp# /usr/lib/check_mk_agent/local/mysql
ERROR: No such file or directory

root@server2:/etc/snmp#

“”
Unlike most other scripts, the MySQL script requires a configuration file mysql.cnf in the same directory as the extend or agent script with following content:

<?php
$mysql_user = 'root';
$mysql_pass = 'toor';
$mysql_host = 'localhost';
$mysql_port = 3306;

“”

and then check it with running your
mysql script you located in /etc/snmp/ or whereever you placed it

Yes, I have checked that:

root@server2:/etc/snmp# ls -la
total 112
drwxr-xr-x    2 root root   190 Sep 10 15:41 .
drwxr-xr-x. 108 root root  8192 Sep 10 15:26 ..
-rw-r--r--    1 root root     0 Sep  8 09:49 apache
-rwxr-xr-x    1 root root  2894 Sep  8 09:54 apache-stats
-rwxr-xr-x    1 root root  2627 Sep  8 16:14 apache-stats.py
-rw-r--r--    1 root root  8876 Sep 10 13:28 index.html
-rwxr-xr-x    1 root root 60264 Sep 10 15:41 mysql
-rw-r--r--    1 root root    97 Sep 10 13:41 mysql.cnf
-rwxr-xr-x    1 root root   130 Sep  8 11:46 rrdcached
-rw-------    1 root root   852 Sep  8 09:56 snmpd.conf
-rw-------    1 root root   783 Sep  7 14:12 snmpd.conf.bkp
-rw-------    1 root root   220 Apr  1 03:31 snmptrapd.conf
root@server2:/etc/snmp# cat mysql.cnf
<?php
$mysql_user = 'root';
$mysql_pass = 'root';
$mysql_host = 'localhost';
$mysql_port = 3306;
root@server2:/etc/snmp# ./mysql
ERROR: No such file or directory
root@server22:/etc/snmp#

have you tried it with 755 for mysql.cnf? Scripts often need execute flag on their config files

Just tried now, still not working.

caching directory exists ?

“”
Create the cache directory, ‘/var/cache/librenms/’ and make sure that it is owned by the user running the SNMP daemon.

mkdir -p /var/cache/librenms/

“”

Yes, it does:

root@server2:/etc/snmp# ls -la /var/cache/librenms/
total 4
drwxr-xr-x  2 root root  50 Sep 11 08:16 .
drwxr-xr-x. 9 root root 109 Sep  8 09:50 ..
-rw-r--r--  1 root root   0 Sep 11 08:16 agent-local-mysql
-rw-r--r--  1 root root 431 Sep 11 08:13 apache-snmp
root@server2:/etc/snmp#

is your snmpd running as root?
in my /var/cache/librenms/ all files have owner and group in which snmpd is running
also /var/cache/librenms directory is owned by snmpd user, which isn’t
i opened /var/cache/librenms up to 775 so snmpd user and root is able to do all stuff in it

which OS are you using?

Yes, snmpd is running as root.
I have changed the /var/cache/librenms and its files to 777 and am still getting the same error.

I am using RHEL7

just to be sure, a little conclusion …

you’ve got in /etc/snmp/
mysql script with 755 as mode and owned by root or snmpd user
also you’ve got there:
mysql.conf with login credentials to mysql server in it and it has also mode 755 and is owned by snmpd user?

then you’ve got /var/cache/librenms directory which is owned by snmpd user

also you run
yum install php-cli php-mysql
to verify needed packages are installed

what says syntax error check:
php -l /etc/snmp/mysql
and
php -l /etc/snmp/mysql.cnf
?

your root access to database is password secured, so those credentials are matching?

Yes, mysql script is 755 owned by root, and mysql.cnf is 755 owned by root as well.

librenms@server2:/etc/snmp$ ls -latr
total 112
-rw-------    1 root root   220 Apr  1 03:31 snmptrapd.conf
-rw-------    1 root root   783 Sep  7 14:12 snmpd.conf.bkp
-rw-r--r--    1 root root     0 Sep  8 09:49 apache
-rwxr-xr-x    1 root root  2894 Sep  8 09:54 apache-stats
-rw-------    1 root root   852 Sep  8 09:56 snmpd.conf
-rwxr-xr-x    1 root root   130 Sep  8 11:46 rrdcached
-rwxr-xr-x    1 root root  2627 Sep  8 16:14 apache-stats.py
-rw-r--r--    1 root root  8876 Sep 10 13:28 index.html
-rwxr-xr-x    1 root root    97 Sep 10 13:41 mysql.cnf
-rwxr-xr-x    1 root root 60264 Sep 10 15:41 mysql
drwxr-xr-x    2 root root   190 Sep 10 15:41 .
drwxr-xr-x. 108 root root  8192 Sep 11 13:26 ..
librenms@server2:/etc/snmp$ cat mysql.cnf
<?php
$mysql_user = 'root';
$mysql_pass = 'root';
$mysql_host = 'localhost';
$mysql_port = 3306;

/var/cache/librenms is owned by root and set as 777:

librenms@server2:/etc/snmp$ ls -la /var/cache/librenms
total 4
drwxrwxrwx  2 root root  50 Sep 11 13:48 .
drwxr-xr-x. 9 root root 109 Sep  8 09:50 ..
-rwxrwxrwx  1 root root   0 Sep 11 13:48 agent-local-mysql
-rw-r--r--  1 root root 433 Sep 11 13:48 apache-snmp
librenms@server2:/etc/snmp$ ls -la /var/cache/
total 8
drwxr-xr-x.  9 root   root    109 Sep  8 09:50 .
drwxr-xr-x. 21 root   root   4096 Sep  4 10:31 ..
drwxrwxr-x.  2 abrt   abrt      6 Apr  2 17:58 abrt-di
drwx------   3 apache apache   19 Sep  4 10:31 httpd
drwxr-xr-x   2 root   root      6 Aug 20  2019 katello-agent
drwx------.  2 root   root     23 Sep  9 12:54 ldconfig
drwxrwxrwx   2 root   root     50 Sep 11 13:48 librenms
drwxr-xr-x. 40 root   root   4096 Sep 11 03:40 man
drwxr-xr-x.  3 root   root     20 Apr  2 17:56 yum
librenms@server2:/etc/snmp$

Yum responded:

Package php-cli-7.2.33-1.el7.remi.x86_64 already installed and latest version
Package php-mysql-5.4.16-48.el7.x86_64 is obsoleted by php-mysqlnd-7.2.33-1.el7.remi.x86_64 which is already instaled

Syntax check:

root@server2:/etc/snmp# php -l /etc/snmp/mysql
No syntax errors detected in /etc/snmp/mysql
root@server2:/etc/snmp# php -l /etc/snmp/mysql.cnf
No syntax errors detected in /etc/snmp/mysql.cnf
root@server2:/etc/snmp#

Appending:

root@server2:/etc/snmp# mysql -uroot -proot
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 94189
Server version: 5.5.65-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

could you add

$debug = true;

into mysql.cnf file and paste Output here?

Like this?

root@server2:/etc/snmp# cat mysql.cnf
<?php
$debug = true;
$mysql_user = 'root';
$mysql_pass = 'root';
$mysql_host = 'localhost';
$mysql_port = 3306;
root@server2:/etc/snmp# ./mysql
ERROR: No such file or directory
root@server2:/etc/snmp#

yes,
but you should get many lines of output by running mysql