Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have spent days reading through pages of cryptic and unintelligible documentation, and incomplete or poorly documented examples.

I cant find where to start - its bewildering!

Basially, I just want to run a simple shell script on a target server and have nagios act on the result. I dont want to have to learn "C" and spend months developing a plugin, which is how it is looking.

E.g. I want to say write a script which executes "select count(*) from logged_in_users"

and have nagios graph draw the resultant number (and even alert on it)

I can write a 5 line script on the Database machine which returns the status and info in about 10 seconds. The problem is how to get Naigos to read this value.

I have read a lot of information about plugins, and seen a lot of plugin "scripts", but the information never says where the plugsin run, do they run on the Srever, The client or both, now how they are configured. I dont want the server to have the DB passwords, so I just want to write an abitrary shell script on the target server and have the result monitored.

The target servers already have something called nrpe installed, which I was hoping would allow me to write a simple shell script, but all its "commands" are in binary, and it is completely cryptic, and I cant find any overview documentation.

Can anyone suggest where to start? Has someone writen a "hello world" script? I have not been able to find a google search string which returns any relvant hits. Does noone on the planet want to monitor the results of a simple custom script via nagios?

Even better would be a mysql plugin, which allows you to insert your own bit of sql, but I cant find anything like this.


share|improve this question
You want write a script for nagios or nagiosgraph? Also you can write it python,perl or bash, C is not the only option. – Lucas Kauffman Apr 29 '12 at 14:15
Many thanks for Everyones help on this. I spent about 8h trying to get it working with nagios, and gave up. As a novice nagios user, the complexity of getting this working with no complete exmaple was too much. Instead I installed prtg, and had it working in about 10 minutes using point and click. Shame prtg only runs on windows. – John Little Jun 13 '12 at 10:00

Yes, you can run nrpe server on the target server. On nagios server, you can use check_nrpe plugin which takes a command as argument. This command should be defined nrpe server on the target server. So, you script will be executed on the target server by nrpe server.

Here is an example:

You can define a command like this in nrpe.cfg file on target server:


You need to write the script /usr/lib/nagios/plugins/ on the target server. Of course, you can pass any needed parameters as normal.

On nagios server, you define the check command as follows:

define service{
        use                             generic-service
        host_name                       My_Target_Server
        service_description             My_Query
        check_command                   check_nrpe_1arg!check_my_query
        notifications_enabled           1

You need to use the proper name of check_nrpe_1arg you find in your nagios configuration. It can be already defined like:

define command {
        command_name    check_nrpe_1arg
        command_line    /usr/lib/nagios/plugins/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ -t 15
share|improve this answer
Hi, The problem is I cant find any resource which documents how to add your own commadn to the client side to be run by nrpe. The nrpe pdf documentation doenst mention if it is possible to write your own nrpe scripts. – John Little Apr 29 '12 at 15:02
@JohnLittle: I included an example in my answer. Have another look. – Khaled Apr 30 '12 at 7:03

It sounds like you really want to be walked through how to use check_nrpe with a custom defined set of parameters applied to an existing plugin.

First install the mysql check plugin on your mysql server. Figure out the command that you want to execute and whatever parameters you need. Write these settings down.

Install the NRPE daemon on your mysql server. Open port 5666 in iptables if necessary. Edit the file /etc/nagios/nrpe.cfg and add a line like the following.

command[annoying_mysql_check]=/usr/lib/nagios/plugins/check_mysql -w 5 -c 10 "select top 10 from .. order by"

From your Nagios server (at the command line)

check_nrpe -H <your mysql host> -c annoying_mysql_check

This will return the results that you found in the very first set of instructions above.

Once you have this working from the command line on your Nagios server convert this to the syntax and configuration files used by Nagios to automate the scheduling of the checks. This is part of the core Nagios documentation.

share|improve this answer which is part of the Nagios package on Ubuntu. Not sure if it's in the Nagios package in CentOS (it might be in a different package than the straight Nagios server package).

Checking the output is a matter of putting the check_mysql_query as a "command" in Nagios and having the Nagios server run it. You can execute the command from any machine that has access to the MySQL server, be it the Nagios server or some other machine (in which case you'd set up NRPE on that machine, which the Nagios server would hit to run the command).

Graphing is kind of another matter. You can use nagiosgraph, which I find an absolute pain to set up. There's also Munin.

share|improve this answer
Thanks! I saw that page you linked to. Its a link to a command usage man page. I cant find anywhere which actually defines how to get the command itself, nor if the command is actually a nagios plugin which can only be installed on a server (so is no use), or if its a plugin which through some other means can be installed on a target machine (so is not a plugin, is an agent) using some thrid party piece like nrpe to communicate with the server. I cant find any installation, usage or setup documentation for check_mysql_query. There seems to be no guide, unless I am missing something major. – John Little Apr 29 '12 at 15:07
@JohnLittle OK, for CentOS, add the EPEL repository ( and then do yum install nagios-plugins-mysql. This will give you /usr/lib/nagios/plugins/check_mysql_query. If you Nagios server can query against the MySQL server, then there's no need to set up NRPE. Just define a command in the Nagios server to execute check_mysql_query with the right options. – cjc Apr 29 '12 at 22:00
Oh, Nagios in the CentOS wiki: That talks about Nagios 2.x. If you're running CentOS6, you'll be running Nagios 3.x, which will be a little different, but should follow the same general principles. You can compare that to the Nagios Quickstart docs: – cjc Apr 29 '12 at 22:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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