Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
04-15-2009, 07:25 AM
|
#1
|
|
LQ Newbie
Registered: Oct 2007
Location: Pretoria - South Africa
Distribution: Ubuntu 8.10
Posts: 9
Rep:
|
Need Help with Development of Nagios Plugin
Hi There,
I am in the process of developing a script that returns the output of the nagios "check_nt" plugin in a format that is recognized by Splunk.
I have pretty much finished it when I ran into a "snag". When I run the plugin from the command-line, it outputs exactly like I want it to.
However, from inside Nagios - The plugin returns {no output from plugin}. If I remove the actual check results from the plugin's output and replace it with a plain text string - nagios displays this string in the status information area.
I am baffled, as this is not my first plugin I wrote - and according to me - it should work.
Here is my Code:
Code:
#!/bin/sh
PROGNAME='Check NT Perf - Results Splunk Compatible'
SCP="./check_nt"
HOST=$1
PORT=$2
VAR=$3
PARAM=$4
WARN=$5
CRIT=$6
UPTIME=`$SCP -H $HOST -p $PORT -v $VAR|sed 's/System Uptime - //'|sed 's/day(s)/./'|sed 's/hour(s)/./'|sed 's/minute(s)//'`
CPU=`$SCP -H $HOST -p $PORT -v $VAR -l $PARAM|sed 's/CPU Load//'|sed 's/%//'`
MEM=`$SCP -H $HOST -p $PORT -v $VAR $WARN $CRIT|sed 's/Memory usage: total:[0-9][0-9][0-9][0-9].[0-9][0-9] Mb//'|sed 's/ - used: //'|sed 's/[0-9][0-9][0-9][0-9].[0-9][0-9] Mb//'|sed 's/[0-9][0-9][0-9].[0-9][0-9] Mb//'|sed 's/(//'|sed 's/%)/./'|sed 's/- free://'|sed 's/[0-9][0-9][0-9][0-9].[0-9][0-9] Mb//'|sed 's/([0-9][0-9]%)//'|sed 's/. [0-9]//'|sed 's/.//'|sed 's/0.00;0.00;0.00;//'|sed 's/;[0-9][0-9][0-9][0-9].[0-9][0-9]//'`
DRIVE=`$SCP -H $HOST -p $PORT -v $VAR -l $PARAM $WARN $CRIT`
if [ "$VAR" = "UPTIME" ] ; then
OUTPUT="${OUTPUT} 'System_Uptime'=$UPTIME |Format: days.hours.minutes"
STAT=0
elif [ "$VAR" = "CPULOAD" ] ; then
OUTPUT="${OUTPUT} 'CPU_Load'=$CPU |"
#STAT=0
elif [ "$VAR" = "MEMUSE" ] ; then
OUTPUT="${OUTPUT}'Memory_Used_Percent'= `echo $MEM`"
#STAT=0
elif [ "$VAR" = "USEDDISKSPACE" ] ; then
OPT="`echo $DRIVE > drv.tmp`"
OUTPUT="${OUTPUT} `cat drv.tmp |sed \"s/([0-9][0-9]%)//\"|sed \"s/total:/'Total Space'=/\"|sed \"s/used:/'Used Space'=/\"|sed \"s/free/'Free Space'=/\"|sed 's/-//'|sed \"s/([0-9][0-9]%)//\"|sed \"s/([0-9]%)//\"|sed \"s/([0-9][0-9][0-9]%)//\"`"
STAT=0
else
OUTPUT="${OUTPUT} ERROR - Invalid Variable Specified!"
STAT=2
fi
echo $OUTPUT
#echo $DRIVE
exit $STAT
The Command-Line output is as follows:
Code:
c:\ 'Total Space'= 136.72 Gb - 'Used Space'= 83.98 Gb - 'Free Space'= 52.73 Gb | 'c:\ Used Space'=83.98Gb;109.37;0.00;0.00;136.72
Any help would be greatly appriciated.
Regards,
Monkinsane
|
|
|
|
04-15-2009, 07:35 AM
|
#2
|
|
Member
Registered: Feb 2008
Location: JHB South Africa
Distribution: Centos, Kubuntu, Cross LFS, OpenSolaris
Posts: 806
Rep:
|
The problem is you are using a relative path instead of the full path.
|
|
|
|
04-15-2009, 07:40 AM
|
#3
|
|
LQ Newbie
Registered: Oct 2007
Location: Pretoria - South Africa
Distribution: Ubuntu 8.10
Posts: 9
Original Poster
Rep:
|
Quote:
Originally Posted by datopdog
The problem is you are using a relative path instead of the full path.
|
Hi TopDog,
Thanx for the quick reply.
I changed to full paths, still no joy. Any suggestions?
It does work if I run it from command line.
Last edited by monkinsane; 04-15-2009 at 07:42 AM.
|
|
|
|
04-15-2009, 07:43 AM
|
#4
|
|
Member
Registered: Feb 2008
Location: JHB South Africa
Distribution: Centos, Kubuntu, Cross LFS, OpenSolaris
Posts: 806
Rep:
|
Can you post the modified plugin and the check_command you are using to call it from nagios.
|
|
|
|
04-15-2009, 09:56 AM
|
#5
|
|
LQ Newbie
Registered: Oct 2007
Location: Pretoria - South Africa
Distribution: Ubuntu 8.10
Posts: 9
Original Poster
Rep:
|
Quote:
Originally Posted by datopdog
Can you post the modified plugin and the check_command you are using to call it from nagios.
|
Thanx for the assist.
Modified Code:
Code:
#!/bin/sh
PROGNAME='Check NT Perf - Results Splunk Compatible'
SCP="/usr/local/nagios/libexec/check_nt"
SED="/bin/sed"
HOST=$1
PORT=$2
VAR=$3
PARAM=$4
WARN=$5
CRIT=$6
UPTIME=`$SCP -H $HOST -p $PORT -v $VAR|$SED 's/System Uptime - //'|$SED 's/day(s)/./'|$SED 's/hour(s)/./'|$SED 's/minute(s)//'`
CPU=`$SCP -H $HOST -p $PORT -v $VAR -l $PARAM|$SED 's/CPU Load//'|$SED 's/%//'`
MEM=`$SCP -H $HOST -p $PORT -v $VAR $WARN $CRIT|$SED 's/Memory usage: total:[0-9][0-9][0-9][0-9].[0-9][0-9] Mb//'|$SED 's/ - used: //'|$SED 's/[0-9][0-9][0-9][0-9].[0-9][0-9] Mb//'|$SED 's/[0-9][0-9][0-9].[0-9][0-9] Mb//'|$SED 's/(//'|$SED 's/%)/./'|$SED 's/- free://'|$SED 's/[0-9][0-9][0-9][0-9].[0-9][0-9] Mb//'|$SED 's/([0-9][0-9]%)//'|$SED 's/. [0-9]//'|$SED 's/.//'|$SED 's/0.00;0.00;0.00;//'|$SED 's/;[0-9][0-9][0-9][0-9].[0-9][0-9]//'`
DRIVE=`$SCP -H $HOST -p $PORT -v $VAR -l $PARAM $WARN $CRIT`
if [ "$VAR" = "UPTIME" ] ; then
OUTPUT="${OUTPUT} 'System_Uptime'=$UPTIME |Format: days.hours.minutes"
STAT=0
elif [ "$VAR" = "CPULOAD" ] ; then
OUTPUT="${OUTPUT} 'CPU_Load'=$CPU |"
#STAT=0
elif [ "$VAR" = "MEMUSE" ] ; then
OUTPUT="${OUTPUT}'Memory_Used_Percent'= `echo $MEM`"
#STAT=0
elif [ "$VAR" = "USEDDISKSPACE" ] ; then
OPT="`echo $DRIVE > drv.tmp`"
OUTPUT="${OUTPUT} `cat drv.tmp |$SED \"s/([0-9][0-9]%)//\"|$SED \"s/total:/'Total Space'=/\"|$SED \"s/used:/'Used Space'=/\"|$SED \"s/free/'Free Space'=/\"|$SED 's/-//'|$SED \"s/([0-9][0-9]%)//\"|$SED \"s/([0-9]%)//\"|$SED \"s/([0-9][0-9][0-9]%)//\"`"
STAT=0
else
OUTPUT="${OUTPUT} ERROR - Invalid Variable Specified!"
STAT=2
fi
echo $OUTPUT
#echo $DRIVE
#echo $MEMHEAD
exit $STAT
Nagios Command:
Code:
define command {
command_name check_nt_perf
command_line $USER1$/check_nt_perf.sh $HOSTADDRESS$ $ARG1$
}
Service Command:
Code:
check_command check_nt_perf!12489 USEDDISKSPACE c -w 80 -c 90
Executed from Konsole:
Code:
check_nt_perf.sh 10.0.0.1 12489 USEDDISKSPACE c -w 80 -c 90
[ip] [port] [Variable] [par] [warning] [critical]
|
|
|
|
04-16-2009, 02:28 AM
|
#6
|
|
Member
Registered: Feb 2008
Location: JHB South Africa
Distribution: Centos, Kubuntu, Cross LFS, OpenSolaris
Posts: 806
Rep:
|
Okay, it is because your plugin is only coded to return a result when checking for UPTIME, nothing else.
That is what the if statement does.
|
|
|
|
04-16-2009, 08:07 AM
|
#7
|
|
LQ Newbie
Registered: Oct 2007
Location: Pretoria - South Africa
Distribution: Ubuntu 8.10
Posts: 9
Original Poster
Rep:
|
Quote:
Originally Posted by datopdog
Okay, it is because your plugin is only coded to return a result when checking for UPTIME, nothing else.
That is what the if statement does.
|
Well,
It does return the output from the uptime check. Kudo's for that.
I Changed the elif statements to if statements and ended each - still no joy.
Even if I move the Disk Space Check, for example, to the top - it still gives me {no output returned from plugin}
New Code:
Code:
#!/bin/sh
PROGNAME='Check NT Perf - Results Splunk Compatible'
SCP="/usr/local/nagios/libexec/check_nt"
SED="/bin/sed"
HOST=$1
PORT=$2
VAR=$3
PARAM=$4
WARN=$5
CRIT=$6
UPTIME=`$SCP -H $HOST -p $PORT -v $VAR|$SED 's/System Uptime - //'|$SED 's/day(s)/./'|$SED 's/hour(s)/./'|$SED 's/minute(s)//'`
CPU=`$SCP -H $HOST -p $PORT -v $VAR -l $PARAM|$SED 's/CPU Load//'|$SED 's/%//'`
MEM=`$SCP -H $HOST -p $PORT -v $VAR $WARN $CRIT|$SED 's/Memory usage: total:[0-9][0-9][0-9][0-9].[0-9][0-9] Mb//'|$SED 's/ - used: //'|$SED 's/[0-9][0-9][0-9][0-9].[0-9][0-9] Mb//'|$SED 's/[0-9][0-9][0-9].[0-9][0-9] Mb//'|$SED 's/(//'|$SED 's/%)/./'|$SED 's/- free://'|$SED 's/[0-9][0-9][0-9][0-9].[0-9][0-9] Mb//'|$SED 's/([0-9][0-9]%)//'|$SED 's/. [0-9]//'|$SED 's/.//'|$SED 's/0.00;0.00;0.00;//'|$SED 's/;[0-9][0-9][0-9][0-9].[0-9][0-9]//'`
DRIVE=`$SCP -H $HOST -p $PORT -v $VAR -l $PARAM $WARN $CRIT`
if [ "$VAR" = "UPTIME" ] ; then
OUTPUT="${OUTPUT} 'System_Uptime'=$UPTIME |Format: days.hours.minutes"
STAT=0
fi
if [ "$VAR" = "CPULOAD" ] ; then
OUTPUT="${OUTPUT} 'CPU_Load'=$CPU |"
#STAT=0
fi
if [ "$VAR" = "MEMUSE" ] ; then
OUTPUT="${OUTPUT}'Memory_Used_Percent'= `echo $MEM`"
#STAT=0
fi
if [ "$VAR" = "USEDDISKSPACE" ] ; then
OPT="`echo $DRIVE > drv.tmp`"
OUTPUT="${OUTPUT} `cat drv.tmp |$SED \"s/([0-9][0-9]%)//\"|$SED \"s/total:/'Total Space'=/\"|$SED \"s/used:/'Used Space'=/\"|$SED \"s/free/'Free Space'=/\"|$SED 's/-//'|$SED \"s/([0-9][0-9]%)//\"|$SED \"s/([0-9]%)//\"|$SED \"s/([0-9][0-9][0-9]%)//\"`"
STAT=0
fi
# OUTPUT="${OUTPUT} ERROR - Invalid Variable Specified!"
# STAT=2
#fi
echo $OUTPUT
#echo $DRIVE
#echo $MEMHEAD
exit $STAT
Thanks for the advice so far.
Last edited by monkinsane; 04-16-2009 at 08:09 AM.
|
|
|
|
04-16-2009, 08:09 AM
|
#8
|
|
Member
Registered: Feb 2008
Location: JHB South Africa
Distribution: Centos, Kubuntu, Cross LFS, OpenSolaris
Posts: 806
Rep:
|
In cases like this you are supposed to use a switch.
|
|
|
|
04-16-2009, 09:42 AM
|
#9
|
|
LQ Newbie
Registered: Oct 2007
Location: Pretoria - South Africa
Distribution: Ubuntu 8.10
Posts: 9
Original Poster
Rep:
|
Quote:
Originally Posted by datopdog
In cases like this you are supposed to use a switch.
|
What I don't get is that some of my other plugins are coded like this - and they work fine.
I think it might be something to do with the fact that the UPTIME check does not require you to specify warning or critical states. It merely displays the uptime of the server. The others have parameters you need to specify.
Anyways, gonna try and figure it out, since I'm fairly certain it is not because of the if statements, if it was none of my other plugins would work.
Thanks for your assistance.
|
|
|
|
04-17-2009, 01:40 AM
|
#10
|
|
Member
Registered: Feb 2008
Location: JHB South Africa
Distribution: Centos, Kubuntu, Cross LFS, OpenSolaris
Posts: 806
Rep:
|
Quote:
Originally Posted by monkinsane
What I don't get is that some of my other plugins are coded like this - and they work fine.
I think it might be something to do with the fact that the UPTIME check does not require you to specify warning or critical states. It merely displays the uptime of the server. The others have parameters you need to specify.
Anyways, gonna try and figure it out, since I'm fairly certain it is not because of the if statements, if it was none of my other plugins would work.
Thanks for your assistance.
|
You are wrong, i cannot tell you why your other plugins work but from the plugin code here, the only thing it will display is the uptime as USEDISKSPACE will never get matched, come on that is clear to see.
|
|
|
|
04-23-2009, 04:55 AM
|
#11
|
|
LQ Newbie
Registered: Oct 2007
Location: Pretoria - South Africa
Distribution: Ubuntu 8.10
Posts: 9
Original Poster
Rep:
|
Quote:
Originally Posted by datopdog
You are wrong, i cannot tell you why your other plugins work but from the plugin code here, the only thing it will display is the uptime as USEDISKSPACE will never get matched, come on that is clear to see.
|
USEDDISKSPACE does get matched. Command-Line The plugin works perfectly - it returns the values from the different checks flawlessly in a console - the problem is that info does not get passed to the nagios process for some odd reason.
Why don't you copy the code and run it command line - you'll see that it does match the different checks.
So I am NOT wrong, the problem is that info does not get passed to the nagios process for some odd reason.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 11:48 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|