check_mysql_plugin returns NULL value

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
theace18
Posts: 17
Joined: Fri May 31, 2013 11:25 am

check_mysql_plugin returns NULL value

Post by theace18 »

I would like to run query checks on all of our MySQL servers. I am using the check_mysql_plugin. I want to run it from the Nagios server and NOT through NRPE.

Running the plugin through NRPE runs the plugin fine. Running the plugin manually on the server runs fie. However when I try to run it through the actual Nagios app, it returns a NULL value. Permissions for the plugin look fine too, especially since I can run them as both root and the nagios user.

The command is as follows in my commands.cfg file:

Code: Select all

# Added 'check_avgwebusers' Command
define command{
        command_name check_avgwebusers
        command_line $USER1$/check_mysql_query -q "SELECT COUNT(*)/COUNT(DISTINCT(Server)) FROM WebSessions;" -H $HOSTNAME$ -P 3306 -d database -u XXXXX -p XXXXX -w 44 -c 52
        }
The service check is called in my services.cfg file:

Code: Select all

# check_avgwebusers
define service{
        use                     generic-service
        host_name               mysql
        service_description     Check Avg Web Server Users
        check_command           check_avgwebusers
        }
Any thoughts? I am TOTALLY stumped right now. Any help would be appreciated. Thanks!

- Philippe
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: check_mysql_plugin returns NULL value

Post by slansing »

Check the manpage here:

http://nagiosplugins.org/man/check_mysql_query

try swapping some flags around in your check to make it look more like:

Code: Select all

$USER1$/check_mysql_query -H $HOSTNAME$ -P 3306 -d database -u XXXXX -p XXXXX -q "SELECT COUNT(*)/COUNT(DISTINCT(Server)) FROM WebSessions;" -w 44 -c 52
I'd recommend running this from the command line first, more than likely the command will be like so:

Code: Select all

/usr/local/nagios/libexec/check_mysql_query -H <hostaddress> -P 3306 -d database -u username -p pass -q "SELECT COUNT(*)/COUNT(DISTINCT(Server)) FROM WebSessions;" -w 44 -c 52
I'd verify that those warning and critical values do work with the plugin "through the manpage" and that those are values that would be true when running the query you show.
theace18
Posts: 17
Joined: Fri May 31, 2013 11:25 am

Re: check_mysql_plugin returns NULL value

Post by theace18 »

I switched around the flags like you suggested, but Nagios still returns a null value.

This is the command I ran manually from the Nagios server itself, and the result I got:

Code: Select all

[root@nagios libexec]# su nagios
sh-4.1$ ./check_mysql_query -H <host address> -P 3306 -d <database> -u XXXXX -p XXXXX -q "SELECT COUNT(*)/COUNT(DISTINCT(Server)) FROM WebSessions;" -w 44 -c 52
QUERY OK: 'SELECT COUNT(*)/COUNT(DISTINCT(Server)) FROM WebSessions;' returned 30.285700

So as you can see, the plugin runs just fine. Just for some reason won't return a value to Nagios. However if I run it through NRPE, it returns the value (but this isn't what I want to do).
theace18
Posts: 17
Joined: Fri May 31, 2013 11:25 am

Re: check_mysql_plugin returns NULL value

Post by theace18 »

I rearranged them like you said, but I am still getting a NULL value. It's just not making any sense why it works if I run it manually, but not when Nagios runs it.

BTW, if I run this through NRPE, it works fine. However, I don't want to run it through NRPE. I want to be able to run it on the server and generate a custom notification based on its results.
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: check_mysql_plugin returns NULL value

Post by slansing »

Can you try swapping:
"SELECT COUNT(*)/COUNT(DISTINCT(Server)) FROM WebSessions"
For:

Code: Select all

 'SELECT COUNT(*)/COUNT(DISTINCT(Server)) FROM WebSessions'
Alternatively you can try leaving the command with the double quotes, but still removing the semicolon.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: check_mysql_plugin returns NULL value

Post by scottwilkerson »

I noticed that in your command you have $HOSTNAME$ and in your test you list <host address>

Are these the same? I see in your service you have

Code: Select all

# check_avgwebusers
define service{
        use                     generic-service
        host_name               mysql
        service_description     Check Avg Web Server Users
        check_command           check_avgwebusers
        }
Which means this will execute

Code: Select all

./check_mysql_query -H mysql -P 3306 -d <database> -u XXXXX -p XXXXX -q "SELECT COUNT(*)/COUNT(DISTINCT(Server)) FROM WebSessions;" -w 44 -c 52
mysql may not be resolvable
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
theace18
Posts: 17
Joined: Fri May 31, 2013 11:25 am

Re: check_mysql_plugin returns NULL value

Post by theace18 »

Yeah mysql is a resolvable hostname. Still stumped
theace18
Posts: 17
Joined: Fri May 31, 2013 11:25 am

Re: check_mysql_plugin returns NULL value

Post by theace18 »

WOW! I must need some sleep or something.

So it turned out that on my service check I still had it doing a NRPE check.

Thank you everyone SO MUCH for your help. This falls under System Administrator error. DOH! :roll:
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: check_mysql_plugin returns NULL value

Post by slansing »

Great to hear it was that simple, :) we all make mistakes like this.
Locked