LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   nagios plugin working fine but in web it is giving different message (https://www.linuxquestions.org/questions/linux-software-2/nagios-plugin-working-fine-but-in-web-it-is-giving-different-message-786612/)

sarathveera 02-03-2010 03:08 AM

nagios plugin working fine but in web it is giving different message
 
Hi,

i wrote a Plugin for the number of open files for a perticular process

it is working fine when we give in the command in the libexec folder

#./check_fd
is working fine

but when i use the command from the root
#/usr/local/nagios/libexec/check_nrpe -H localhost -c check_fd

it is giving the different message and the status also showing wrong

if faced this type of problem tell me and how u rectified that problem


pls tell me how to rectify this problem

thanks in advance

sohail0399 02-03-2010 04:57 AM

please check is your NRP service is running because it is checking through nrp?


if you have nagios user then nagios should have permission to execute the sript.

and also the permissions for that script using other system commands etc.

EricTRA 02-03-2010 05:18 AM

Hello and Welcome to LinuxQuestions,

The most important part of your question/problem is missing, namely, what's the error you get? If you want people to help you it's always very important to provide as much info as possible.

Kind regards,

Eric

sarathveera 02-03-2010 07:07 AM

#!/bin/bash
USAGE="`basename $0` [-w|--warning]<percent free> [-c|--critical]<percent free>"
THRESHOLD_USAGE="CRITICAL threshold must be greater than WARNING: `basename $0` $*"
percent_free=/tmp/mempercent
critical=""
warning=""
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
# print usage
if [[ $# -lt 4 ]]
then
echo ""
echo "Wrong Syntax: `basename $0` $*"
echo ""
echo "Usage: $USAGE"
echo ""
exit 0
fi
# read input
while [[ $# -gt 0 ]]
do
case "$1" in
-w|--warning)
shift
warning=$1
;;
-c|--critical)
shift
critical=$1
;;
esac
shift
done
# verify input
if [[ $warning -eq $critical || $warning -gt $critical ]]
then
echo ""
echo "$THRESHOLD_USAGE"
echo ""
echo "Usage: $USAGE"
echo ""
exit 0
fi
percent=`lsof -c java|wc -l {'print $1'}`
if [[ "$percent" -gt $critical ]]
then
echo "CRITICAL - ($percent)no. of open files used by java"
exit 2
fi
if [[ "$percent" -gt $warning ]]
then
echo "WARNING - ($percent)no. of open files used by java"
exit 1
fi
if [[ "$percent" -le $warning ]]
then
echo "OK - ($percent)no. of open files used by java"
exit 0
fi


i wrote the above script and gave all permitions to it
i placed it in the
/usr/local/nagios/libexec

and gave command
./check_fd -w 600 -c 700
i got out put
ok- 594 no. of openfiles used by java .
here the result is correct

so then i went to the root there i gave
#/usr/local/nagios/libexec/check_nrpe -H localhost -c check_fd
i got

0k- 5 no. of openfiles used by java

if i change the warning value and critical vale the message is not changing with this command
#/usr/local/nagios/libexec/check_nrpe -H localhost -c check_fd

but if go to the libexec folder the i gave
the ./check_fd -w 500 -c 600
i got
warning - 593 no. of openfiles used by java

this the problem.

EricTRA 02-03-2010 07:26 AM

Did you run the command as root or as nagios user and the same on both servers? On the Nagios server the commands are per default executed by the nagios user.

Kind regards,

Eric

sarathveera 02-03-2010 09:50 PM

i run the command as the root and as well as in nagios user there is no change in the out i checked in the nagios server also there also the same out pet is comming .

sohail0399 02-04-2010 02:33 AM

whats the output of ?

#/usr/local/nagios/libexec/check_nrpe -H localhost -c check_fd


and check the configuration of nrpe, Verify that the command definition in your NRPE configuration file is correct.

sohail0399 02-04-2010 02:36 AM

set the debug=1 in nrpe configuration file, restart the nrpe and see the log.

sarathveera 02-04-2010 04:10 AM

how to see the log ?
which log file i have to see?

sohail0399 02-04-2010 04:24 AM

Log Files:
/var/log/syslog

Set debug to 1 in :
# vim /usr/local/nagios/etc/nrpe.cfg
debug=1

open another terminal and execute:
# tail -f /var/log/syslog

then start querying the server with check_nrpe commands

sarathveera 02-04-2010 04:58 AM

i check the log nothing is coming in that log


i want a new script for monitoring the number of open files for perticular process
If any one wrote script pls paste that scipt here.

EricTRA 02-04-2010 05:03 AM

Hi,

Here you have one from NagiosExchange.

Kind regards,

Eric

sarathveera 02-04-2010 05:10 AM

i didn't find the plugin for the number of open files for particular process
there is a plugin for total no of open files in the system i don't want that i want for a particular process

EricTRA 02-05-2010 12:49 AM

Hi,

If your script is working locally then you should be able to get it to work with Nagios too. Looking for another script will not solve any problem you have in communication between your Nagios server and the one you're monitoring.

I'll put your script in my test server and Nagios and see what I get. If I encounter problems I'll try to fix them and post here.

And please ask a mod to delete your 'double post'. You're not doing yourself any favors in double posting the same thing and worse if you do it in the same forum.

Kind regards,

Eric

EricTRA 02-05-2010 01:20 AM

Hello sarathveera,

I just copied your script without changing anything on my Nagios server (since it has Java installed), set permissions to allow execute and owner to nagios:nagios and ran it as is. I got an error with this command:
Code:

lsof -c java|wc -l {'print $1'}
The wc -l command doesn't work that way in my opinion, it just counts. After deleting the {'print $1'} part I ran it again as root and got correct result:
Code:

CRITICAL - (322)no. of open files used by java
Next I configured the command in Nagios and tested it from within Nagios (default uses nagios user). I got the same result in Nagios so it works and you'll have to look more into the communication between your Nagios server and the one you are monitoring.

One tip though: change the output and usage description in your script because they are very confusing. For example if you execute the command without options to trigger the usage it states
Code:

Wrong Syntax: openfiles

Usage: openfiles [-w|--warning]<percent free> [-c|--critical]<percent free>

but when you put in like 30 for warning and 20 for critical (since you state percent free, warning should be greater than critical because it's the percentage of free) you get an error stating that critical must be greater than warning. Furthermore you are not doing any percentage calculations in that script since it concerns number of open files. So I'd change the 'percent free' to 'open files' or something. And also put some alignment in your script in order to make it easier to read.

Kind regards,

Eric


All times are GMT -5. The time now is 04:40 PM.