3

I have installed Nagios® Core™ 3.5.1 and NRPE v2.14 on my client which running RHEL 6.3

I have this error message on my Nagios

NRPE: Command 'check_mysql_connections' not defined

On my nrpe.cfg I already set up the allowed_host, include_dir:

allowed_hosts=xx.xx.xx.xx
dont_blame_nrpe=1
include_dir=/etc/nagios/services

my command is on /etc/nagios/services/check_mysql_connections.cfg

command[check_mysql_connections]=/usr/lib64/nagios/plugins/check_mysql_all -K connections -H myHOST -u myUSERNAME -p myPASSWORD

On Nagios Server, I already set up the nagios.cfg file, and add the commands-custom.cfg on /etc/nagios/objects which contains like this:

define command {
command_name    check_mysql_connections
command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c check_mysql_connections
}

and on /etc/nagios/servers I have add the mysql.cfg

## Define Host Group ##

define hostgroup {
hostgroup_name          mysql-databases
alias                   MySQL Databases
}

#######################
## Define Hosts ##

define host {
use             linux-server
host_name       bdgbnbpmydb02
alias           MySQL Database
address         xx.xx.xx.xx
hostgroups      mysql-databases
contact_groups  admins
check_command   check-host-alive
}

#######################
## Define Service ##

define service {
use                     generic-service
hostgroup_name          mysql-databases
service_description     MySQL Connections
check_command           check_mysql_connections
}

I already kill the NRPE process, removing /var/run/nrpe.pid, and start the NRPE process again. And also my NRPE is NOT running under xinet.d

When I try to execute the command locally on the remote host, it gives result. And when I try to execute from the nagios server using this command:

/usr/lib64/nagios/plugins/check_nrpe -H xx.xx.xx.xx -c check_mysql_connections

it also gives result. I don't know what went wrong, because all of my other commands running normally.

UPDATE & SOLVED

after so many years, I recall how to solve this problem.

I need to edit the custom commands (on Nagios Server) commands-custom.cfg on /etc/nagios/objects, so it will be like this:

define command {
command_name         check_nrpe
command_line         $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ 
}

and under the "Define Service" it was like this:

## Define Service ##

define service {
use                     generic-service
hostgroup_name          mysql-databases
service_description     MySQL Connections
check_command           check_nrpe!check_mysql_connections
}

In summarize, I need to separate the command to check the service to be check_nrpe and call the custom commands using check_nrpe!check_mysql_connections

Reference: https://support.nagios.com/forum/viewtopic.php?f=7&t=33448

buzzing_bee
  • 33
  • 1
  • 1
  • 5
  • When you run the command manually from your Nagios server, are you root user or nagios user ? – krisFR Dec 21 '13 at 10:25
  • It's an aside, but: `bdgbnbpmydb02`? What a hostname! See also http://serverfault.com/questions/479945/choosing-between-meaningful-and-meaningless-hostnames/479947#479947 . – MadHatter Dec 21 '13 at 11:46
  • Sorry to belabour the obvious, but - since you are kind enough to confirm you've restarted NRPE on the client - have you also restarted the NAGIOS server since your last edit to the config files? – MadHatter Dec 21 '13 at 11:47
  • I'd say "check SELinux", but you'd be getting different error messages if that were interfering with the plugin. I assume that `nrpe` is running as the "nrpe" user; what does `ls -ldZ /etc/nagios/services /etc/nagios/services/check_mysql_connections.cfg` show? – asciiphil Dec 21 '13 at 13:38
  • How did you install NRPE? EPEL? Repoforge? Compiled? – Keith Dec 21 '13 at 16:11
  • @user2196728 : i try both of user and all of it gives result – buzzing_bee Dec 22 '13 at 13:53
  • @MadHatter: yes, definitely i already restart the nagios server – buzzing_bee Dec 22 '13 at 13:55
  • @asciiphil: i can't do it right at this moment, but i will give you the result once i can check that – buzzing_bee Dec 22 '13 at 13:56
  • @Keith: i compile it manually – buzzing_bee Dec 22 '13 at 13:57
  • Is there a reason you compile NRPE yourself? Can you try the one in EPEL? (Or repoforge, but I've had better experiences overall with EPEL; just don't use them both at the same time unless you're very careful.) – asciiphil Dec 23 '13 at 13:49
  • @asciiphil : this is the result: `-rw-r--r--. root root unconfined_u:object_r:nagios_etc_t:s0 /etc/nagios/services/check_mysql_connections.cfg` the reason is, this server is not connected to internet connection, so I have to download the package manually, then compile it. – buzzing_bee Dec 24 '13 at 01:55

6 Answers6

2

Follow these steps for adding a remote client disk check. These steps can be followed for the setup of mysql also.

Client


vi /etc/nagios/nrpe.cfg

allowed_hosts=127.0.0.1,nagios_server_ip_here
dont_blame_nrpe=1
#checking root  partion
command[check_disk]=/usr/lib/nagios/plugins/check_disk -w 25% -c 20% -p /

Server


From the file /usr/local/nagios/etc/resource.cfg its given as $USER1$=/usr/local/nagios/libexec:

So, run the commands in terminal:

locate check_nrpe                              //find the location of check_nrpe
cp /usr/lib/nagios/plugins/check_nrpe /usr/local/nagios/libexec/
cd /usr/local/nagios/libexec/
chown nagios:nagios check_nrpe

Edit the file /usr/local/nagios/etc/objects/commands.cfg:

define command{
    command_name    check_disk
    command_line    $USER1$/check_nrpe -H '$HOSTADDRESS$' -t 30 -c check_disk
     }

Edit /usr/local/nagios/etc/servers/clients.cfg:

define service {
    use                             generic-service
    host_name                       BI Server
    service_description             Disk
    check_command                   check_disk
    notifications_enabled           1
    }

Restart services

/etc/init.d/nagios restart                          //server side
/etc/init.d/nagios-nrpe-server restart             //client side

You can also check the commands in terminal as nagios user,

su - nagios
cd /usr/local/nagios/libexec/
./check_nrpe -H nagios_client_ip_here -t 30 -c check_mysql
./check_nrpe -H nagios_client_ip_here -t 30 -c check_disk
sebix
  • 4,175
  • 2
  • 25
  • 45
Amol
  • 151
  • 5
1

Start at one end and work your way back.

  • You said "/usr/lib64/nagios/plugins/check_mysql_all -K connections -H myHOST -u myUSERNAME -p myPASSWORD" works on the command line.
  • You said that NRPE works on that server with other commands.
  • You said that the command fails on the command line from the nagios server.

This suggests to me that the problem is in the definition on the NRPE server. Is it possible that your obfuscated variables for myHOST, myUSERNAME, or myPASSWORD contain a character that is interpreted non-literally by NRPE? (I'm assuming you've already checked for typos and duplicate definitions!)

Katherine Villyard
  • 18,510
  • 4
  • 36
  • 59
  • All command both success from Nagios server and client. And no, all of myHOST,myUSERNAME, & myPASSWORD, do not contain strange character, all pure alphabetical characters. – buzzing_bee Dec 27 '13 at 09:53
  • Oh, I'm sorry. I must have misread. :( Check for duplicate command definitions on the Nagios server itself. They may be hidden in /etc/nrpe. – Katherine Villyard Dec 27 '13 at 15:15
  • I am sure there is no duplicate command definitions, since I've done installing nagios and nrpe, and I create it myself...maybe i just have to reinstall both nagios and nrpe?? – buzzing_bee Dec 28 '13 at 01:46
  • They're working for the other plugins. I assume you've already looked in /var/log/messages and /var/log/nagios3/nagios.log or the equivalent on your system... – Katherine Villyard Dec 28 '13 at 03:14
  • 1
    your comment "This suggests to me that the problem is in the definition on the NRPE server" what bothers me at that time. So I try to re-define the commands, and it works. Thanks a lot – buzzing_bee Nov 14 '19 at 04:16
0

Normally, I would suspect a permissions problem with that plugin. Be sure to run your manual tests as the nagios (or nrpe) user.

But in this case, it's claiming the NRPE command isn't even defined, so it's not even getting as far as running it...

Put the NRPE command def directly into nrpe.cfg, not in an included file. (And then restart NRPE.)

I recall having a similar problem (but with the NRPE from EPEL), a few years ago, where it wouldn't include another file in nrpe.cfg for some reason. I never did figure out why the include file didn't work, though.

Keith
  • 4,627
  • 14
  • 25
  • i've done that, and it's just the same, i put command definition to `/etc/nagios/nrpe.cfg` and it got the same error – buzzing_bee Dec 28 '13 at 01:44
  • Then either you're looking at the wrong box, or the NRPE daemon isn't using that config file. – Keith Dec 29 '13 at 16:56
0

I had same issue for one of new checks I had implemented. Tried running check manually from Nagios Server

[foo@nagios.example.com]$ /usr/lib64/nagios/plugins/check_nrpe -H db1.example.com -c check_mysql
NRPE: Command 'check_mysql' not defined

Turned out that Nagios NRPE Daemon on Nagios Client Server needed to restarted since it sources everything from nrpe.d into program memory

[foo@db1.example.com]$ sudo  /etc/init.d/nrpe restart
Shutting down Nagios NRPE daemon (nrpe):                   [  OK  ]
Starting Nagios NRPE daemon (nrpe):                        [  OK  ]

Ran the check again and was succeeding this time

[foo@nagios.example.com]$ /usr/lib64/nagios/plugins/check_nrpe -H db1.example.com -c check_mysql
OK: MySQL is running fine.
0

I had the same symptom. So maybe this will save someone else some time. My problem was that I was missing the .cfg extension on the files in the include directory.

My include dir was include_dir=/etc/nagios/nrpe.d

The machine is running Ubuntu 14.04 for reference, using NRPE v2.15

Justin Fortier
  • 750
  • 5
  • 9
-1

I had a similar issue sometime ago, it turned out that someone already installed NRPE in the server (i didn't know), and when i tried to access it took the old NRPE version and configuration, the solution was look for the old NRPE and redirect the access...

Alonimus
  • 36
  • 5