Seite wählen

Quick Tip: Testing Nagios Plugins

von | 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:~$

1 Kommentar

  1. Berny

    And again users of the zsh are in advantage. In the same situation they do what? Correct: They do nothing!
    Zsh by default prints the return code of each command – if not zero – in front of the next prompt.
    And only at the *next* prompt, not on every following…

    Antworten

Einen Kommentar abschicken

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Mehr Beiträge zum Thema 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,...