2

I have recently installed nagios on Debian 9 and don't know how to define States.

I have a shellscript which determines if a process is running if true it echoes out '1' if false it echoes out '0'

Nagios does process the information and shows the 1 or 0 in the 'Status Information', but whether its 0 or 1 Nagios will state OK.

How can i define Nagios to state critical if 0 and OK if 1?

flopana
  • 23

1 Answers1

5

Nagios uses the exit status of the plugin to determine what state to show:

  • 0 = OK
  • 1 = Warning
  • 2 = Critical
  • 3 = Unknown

So if you have a shell script as a plugin, ensure that the last thing executed is

exit 0

for OK, and replace the 0 with 1, 2 or 3 depending on the detected status. As you want OK for 1 and critical for 0:

#!/bin/sh

# do whatever tests here, and set variable X to 0 or 1

if [ "$X" = 0 ]; then exit 2; fi
if [ "$X" = 1 ]; then echo 0; fi
exit 3

The output text is indeed used to show the detail in "status information". You can also have performance data in the output.

See https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/3/en/pluginapi.html for more info.

wurtel
  • 1,575