I have defined the following command for one of my service checks:

define command{
        command_name    mycommand
        command_line    $USER1$/check_by_ssh -p $ARG1$ -l nagios -i /etc/nagios2/keys/key1 -H $HOSTADDRESS$ -v -C 'source $USER10$ ; command.py -a get --alert-name $ARG2$ -q'

The problem is that it seems that nagios is parsing the command with the semicolon, and producing garbage which can not be executed. I have tried also putting a backslash \;, to no avail.

If I run the command directly on the shell, it works. Which means that this is not a problem with check_by_ssh, but a problem on the parsing of the nagios configuration file.

How can I debug this? Is there a way to get a listing of all the commands that nagios has parsed when reading the configuration files?

  • 6
    What if you just wrap your shell commands into a script, and have Nagios call the script? – cjc Apr 6 '12 at 10:46
  • That is an option that I can try, but it makes my nagios installation difficult to maintain. I have over 100 services, and creating a script for each will not be practical (actually, the problem is not that big, since most of my checks are running fine). Nevertheless I would really like to learn how to debug this kind of problems: how can I list all configured services / hosts, and related commands, from a running nagios instance? Is this at all possible? Can I do it by querying nagios? Can I do this during startup? – dangonfast Apr 6 '12 at 11:17
  • The config.cgi in the web interface will let you view the running config. The "-v" option for the nagios command will check a configuration file for errors, e.g., "/usr/sbin/nagios3 -v /etc/nagios3/nagios.cfg" – cjc Apr 6 '12 at 11:35
  • config.cgi was the way to go. With it I have confirmed that nagios is eating up anything after the semicolon, so I have created a wrap-up script where I can use the semicolon as it was meant to be. – dangonfast Apr 6 '12 at 12:52
  • Sure, please do. – dangonfast Apr 6 '12 at 13:04

From comments discussion:

Nagios is apparently eating up anything after the semicolon in the "command" definition. The easiest way to manage this is to wrap up the complex command into a shell script that will be called by Nagios.

As part of debugging, the running Nagios configuration can be viewed using the CGI from the web interface, specifically the config.cgi (e.g., https://nagios.example.com/cgi-bin/nagios3/config.cgi). This will show the current set of commands, hosts, etc.

  • This is obviously more simple than NRPE, +1 – Josh Apr 6 '12 at 13:18
  • It's possible there would be similar issues with NRPE command definitions. I'm not sure off-hand how NRPE parses the configuration file, but I wouldn't rule out weird behavior. We've tended to wrap things inside shell or Perl scripts in general rather than shoehorn the script contents into Nagios/NRPE configuration. – cjc Apr 6 '12 at 13:30

You may not like my answer based on your comment

I have over 100 services, and creating a script for each will not be practical

But I think you should look into using NRPE, the Nagios Remote Plugin Executor.

From their site:

NRPE allows you to remotely execute Nagios plugins on other Linux/Unix machines. This allows you to monitor remote machine metrics (disk usage, CPU load, etc.). NRPE can also communicate with some of the Windows agent addons, so you can execute scripts and check metrics on remote Windows machines as well

I switched to NRPE from a setup similar to yours a while ago, and yes, it was a bit of a pain to install and set up new software on many serves which I wanted to monitor. However the benefit was worth it; it was a much more reliable setup and once set up it's easy to manage the Nagios checks on each server.

  • I have NRPE installed, and I am using it for some services. I do not want to move to a full NRPE solution unless completely necessary. I understand that NRPE has some advantages (mainly, lower overhead), but changing now is more work than what I can take at the moment. – dangonfast Apr 6 '12 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.