LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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

Reply
 
Search this Thread
Old 04-15-2009, 07:25 AM   #1
monkinsane
LQ Newbie
 
Registered: Oct 2007
Location: Pretoria - South Africa
Distribution: Ubuntu 8.10
Posts: 12

Rep: Reputation: 0
Question 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
 
Old 04-15-2009, 07:35 AM   #2
datopdog
Member
 
Registered: Feb 2008
Location: JHB South Africa
Distribution: Centos, Kubuntu, Cross LFS, OpenSolaris
Posts: 806

Rep: Reputation: 41
The problem is you are using a relative path instead of the full path.
 
Old 04-15-2009, 07:40 AM   #3
monkinsane
LQ Newbie
 
Registered: Oct 2007
Location: Pretoria - South Africa
Distribution: Ubuntu 8.10
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by datopdog View Post
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.
 
Old 04-15-2009, 07:43 AM   #4
datopdog
Member
 
Registered: Feb 2008
Location: JHB South Africa
Distribution: Centos, Kubuntu, Cross LFS, OpenSolaris
Posts: 806

Rep: Reputation: 41
Can you post the modified plugin and the check_command you are using to call it from nagios.
 
Old 04-15-2009, 09:56 AM   #5
monkinsane
LQ Newbie
 
Registered: Oct 2007
Location: Pretoria - South Africa
Distribution: Ubuntu 8.10
Posts: 12

Original Poster
Rep: Reputation: 0
Question

Quote:
Originally Posted by datopdog View Post
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]
 
Old 04-16-2009, 02:28 AM   #6
datopdog
Member
 
Registered: Feb 2008
Location: JHB South Africa
Distribution: Centos, Kubuntu, Cross LFS, OpenSolaris
Posts: 806

Rep: Reputation: 41
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.
 
Old 04-16-2009, 08:07 AM   #7
monkinsane
LQ Newbie
 
Registered: Oct 2007
Location: Pretoria - South Africa
Distribution: Ubuntu 8.10
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by datopdog View Post
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.
 
Old 04-16-2009, 08:09 AM   #8
datopdog
Member
 
Registered: Feb 2008
Location: JHB South Africa
Distribution: Centos, Kubuntu, Cross LFS, OpenSolaris
Posts: 806

Rep: Reputation: 41
In cases like this you are supposed to use a switch.
 
Old 04-16-2009, 09:42 AM   #9
monkinsane
LQ Newbie
 
Registered: Oct 2007
Location: Pretoria - South Africa
Distribution: Ubuntu 8.10
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by datopdog View Post
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.
 
Old 04-17-2009, 01:40 AM   #10
datopdog
Member
 
Registered: Feb 2008
Location: JHB South Africa
Distribution: Centos, Kubuntu, Cross LFS, OpenSolaris
Posts: 806

Rep: Reputation: 41
Quote:
Originally Posted by monkinsane View Post
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.
 
Old 04-23-2009, 04:55 AM   #11
monkinsane
LQ Newbie
 
Registered: Oct 2007
Location: Pretoria - South Africa
Distribution: Ubuntu 8.10
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by datopdog View Post
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.
 
  


Reply

Tags
scripting, shell


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
How to use Nagios plugin? dwarf007 Linux - Software 20 10-03-2011 06:11 AM
Nagios Help ---cisco plugin tgridley Linux - Software 2 08-11-2011 08:42 AM
Nagios Plugin fullgore *BSD 3 10-22-2008 08:52 AM
Nagios: Raid Plugin kegwell Linux - Software 2 05-01-2005 11:38 AM
Nagios Plugin Compile Anarusis Linux - Software 3 04-10-2005 02:31 PM


All times are GMT -5. The time now is 02:07 AM.

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