Select Page

Quick Tip: Testing Nagios Plugins

by | Feb 15, 2010 | Nagios

Sometimes when testing a Nagios Plugin on the command line, it’s useful to know the exit code.
You can always use echo $?, but that becomes tedious if you have to type it often.
Additionally you have to remember what the exit codes mean.
The following snippet adds a prompt that changes colour according to the exit code; 0 is green, 1 is yellow, 2 is red and 3 is grey. This makes it easy to see at a glance what the exit code was.
Add the following to a file e.g. debug.sh

export colormap=([0]=32 [1]=33 [2]=31 [3]=37)
export PS1='\[\e[${colormap[$?]}m\]\u@\h:\w\$\[\e[30m\] '

Then source it in .bashrc or on the command line with

source debug.sh

and enjoy.

nagios@localhost:~$ ./check_plugin 192.168.0.1
OK - 1824 bytes in 0.002 seconds
nagios@localhost:~$ ./check_plugin 192.168.0.2
Unable to open TCP socket
nagios@localhost:~$

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

More posts on the topic Nagios

Be a speaker at the OS Monitoring Conference this year!

  We have some strong points for you to be a speaker at the Open Source Monitoring Conference 2018. Add new research to your list - Talk about your newest findings in development at the OSMC. Increase your productivity -  Writing a paper with your findings, tips,...