Control Nagios from bash / script (example script /GitHub/ added!)


The situation:

You have a million host on your nagios monitoring-system. You know that you must to disable 2/3/5/x service-check on all host, as the used method of check was corrupted / the monitoring-script failed / SELinux fix was not implemented until now….. One, common way that you login to nagios’s web-interface then disable check’s notification & check & add comment to it step-by-step, so in separate steps. Another way that you have some kind of premium / paid solution for nagios that solve this problem. I will explain a third built-in poor but effective tool for these kind of tasks. With this knowledge & with a little bit of scripting knowledge you will have ability to do your task within seconds.


With these commands you haven’t got any feedback / result. It is one-way communication. If you declare your command to a non-exist service / host, you will left as blind… no any return-code. But you can check on nagios’s page 🙂

The command (on nagios server as root):

echo "[`date +%s`] ADD_SVC_COMMENT;test-system01;JMX Collection Time on jmx port 9999;1;pmikaczo;Non-working check at the moment" > /var/spool/nagios/cmd/nagios.cmd
Note: Please don’t use “;” character inside of command (for example inside of add service comment) as this character also used to separate variables in command.

Clarify it:

echo “[`date +%s`] To log nagios, when the command was applied (disable notification, add comment,….
ADD_SVC_COMMENT Command what I want to do. You can find all of it in here.

test-system01 Define Host, where I want to work with command.

JMX Collection Time on jmx port 9999 Define, which service will be affected.

1 Command will be set until nagios will be restarted (0) or this change will be constant (1) so remain after nagios service restart also.

pmikaczo Author who will be the owner of change.

Non-working check at the moment Comment, what I want to add to the service.

>/var/spool/nagios/cmd/nagios.cmd It depends on what is the path of external-command’s interpretative file.

Tested in:


CentOS release 6.6 (Final)

Nagios :
Nagios® Core
Version 3.5.1
August 30, 2013

You can append more command & these command are scriptable. On GitHub I uploaded my script, you can use it & of course improve it.Check it:


Leave a Reply