Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 10-25-2006, 08:11 AM   #1
LQ Newbie
Registered: Sep 2006
Posts: 3

Rep: Reputation: 0
Nagios - nrpe plugin configuration


I have configured Nagios with nrpe plugin for checking the remote hosts.
it is configured and working fine for common plugins,

NAGIOS SERVER libexec $ /usr/local/nagios/libexec/check_nrpe -H
NRPE v2.5.1

NAGIOS SERVER libexec $ /usr/local/nagios/libexec/check_nrpe -H -c check_load
OK - load average: 0.01, 0.00, 0.00|load1=0.010;15.000;30.000;0; load5=0.000;10.000;25.000;0; load15=0.000;5.000;20.000;0;

I have writed down a plugin(in bash),

Now, when i checked that plugin through Nagios server it gives me the old values,

NAGIOS SERVER libexec $ /usr/local/nagios/libexec/check_nrpe -H -c alarm
ALARM OK Errors = 0 Warns = 0

But when i run that plugin manually on the remotehost and try the same again on Nagios Server,
It gives me the correct values,

REMOTE libexec $ /usr/local/nagios/libexec/
ALARM WARNING Errors = 5 Warns = 2

NAGIOS SERVER libexec $ /usr/local/nagios/libexec/check_nrpe -H -c alarm
ALARM WARNING Errors = 5 Warns = 2

Please suggest,
Old 10-27-2006, 01:50 PM   #2
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,829
Blog Entries: 15

Rep: Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668
Nagios/NRPE base their settings on exit values of the command rather than literal text. That is to say if the shell script completes successfully it will have an exist status of 0 (successful) even though you echo the word "ALARM".

You have to build your script so it gives the appropriate exit status AND the text you want to see. Another gotcha is to be sure it only returns ONE line of text.

Typically you go ahead and define the various statuses as variables then return them.

A short example script from one of my servers:
# This script is used to check running tomcat processes.  Written for NAGIOS.
# cnt returns the number of processes.
# 01/05/03 jda - Original write of
# 06-Feb-2006 jlightiner - Adapted to
#                          Modified ps command for cnt.


cnt=`ps -fxu www |grep java |grep tomcat |grep -c catalina`

if [ $cnt -eq 0 ]
        echo "CRITICAL: $1 is DOWN!"
        exit $CRITICAL_STATE

echo "OK: $1 is up"
exit $OK_STATE
As you can see in the script the WARNING_STATE was defined as 1 but it is never actually used in this one. In more sophisticated scripts I have used it and also do a fair amount more testing.

So it is the "exit 2" (exit $CRITICAL_STATE) that would exit with a status of 2 which Nagios recognizes as "CRITICAL". (I could have name the variable FUNNY_STATE if I'd wanted - it is the value of the exit not the name that matters.)

Similarly it is the "exit 0" (exit $OK_STATE) that would exit with a status of 0 which Nagios recognizes as "OK". (Again I could have named this variable something like ALL_IS_GOOD because it is the value rather than the name that is important.)

In fact you don't have to create the variable names at all - you can just put "exit 0", "exit 1" or "exit 2" at the appropriate places. The variables are used mainly so when you look back at the script you'll know which area of it likely caused the state you're seeing in your Nagios web page.

The default exit status for successful commands is 0 and for unsuccessful is 1. If you don't define them then the status you see is the status of the final command in the script. (This is shell scripting basic - not a Nagios thing per se.)

So say you had a script that did something like:
ls -l /billybob
ls -l /suzybob
ls -l /jimmybob

If there were no /billybob or /suzybob directory on your system each of those commands would have an exit 1 (file not found). However if there IS a /jimmybob on your system the exit status of that command would be 0 (successful - and it would show the file). The status of the script that ran all three lines would be 0 because that was the last status it saw even though two thirds of the commands failed.

So to make if you want it to fail if ANY of the directories does you'd have to do:
if ! ls -l /billybob
then echo it failed
exit 1
if ! ls -l /suzybob
then echo It failed
exit 1
ls -l /jimmybob
then echo It failed
exit 1
echo it succeeded
exit 0

Basically the "exit 1" says to fail with exit code 1 which means the script failed. It would never get to the next name in the list because you told it to exit at the point it failed. It would therefore only go to the "it succeeded" message if all 3 had succeeded and would then do the exit 0. (As noted above you wouldn't need the exit 0 as that would be the state of the last command anyway.)

Last edited by MensaWater; 10-27-2006 at 01:59 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Nagios Event Handler not running - NRPE: Unable to read output notque Linux - Software 7 04-05-2013 06:27 AM
Nagios Addon NRPE didnt start? dwarf007 Linux - Software 3 04-27-2011 01:38 AM
Nagios/nrpe: SSL Issues Killbot_5000 Linux - Security 18 09-21-2010 05:27 PM
Nagios/NRPE issue JF1980 Linux - Security 1 05-18-2006 02:59 PM
Nagios NRPE twantrd Linux - Software 1 10-20-2004 08:24 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:55 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration