LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   [NAGIOS] problems with mainscript and subscript (https://www.linuxquestions.org/questions/linux-newbie-8/%5Bnagios%5D-problems-with-mainscript-and-subscript-872322/)

brownie_cookie 04-01-2011 04:20 AM

[NAGIOS] problems with mainscript and subscript
 
Hi all

I've made a mainscript and a subscript that must be implemented in NAGIOS.
What do those scripts do, well:
situation:
the mainscript makes connection to a remote server, then it copies another script (=subscript) to it and executes it, then the result of that subscript is redirected to a variable on the local server where the mainscript can do something with it (e.g. if the variable contains a 1 -> OK, 2 -> WARNING, ...)

code:
Code:

mainscript
# Initiliaze variables
EXITSTATUS=$STATE_OK

# Copying a file to the remote server
# Then executing the script I just copied
scp /folder/scriptname user@host:/home/vusbe
VAR=$(ssh user@host './scp_cd.sh')
echo $VAR

if [ $VAR = 2 ]; then
                EXITSTATUS=$STATE_CRITICAL
                echo STATE_ERROR
               
        elif [ $VAR = 1 ]; then
                EXITSTATUS=$STATE_WARNING
                echo STATE_WARNING
else
        echo niks aan de hand
        EXITSTATUS=$STATE_OK
fi

# End of script
echo script is finished

subscript:
Code:

#!/usr/bin/ksh
echo subscript

error=`ls /some/folder/ | grep error* | wc -w`

if [ $error -gt 0 ]; then
        i="2" # ERROR MESSAGE
else
        i="0" # OK MESSAGE
fi

echo $i

the result (NAGIOS):
Code:

niks aan de hand
script is finished

but it should give me the STATE_ERROR !!
so, can anyone say what i'm doing wrong (i'm not experienced with NAGIOS, i'm a first-timer to this ;))
is it also possible to copy another script in a NAGIOS plugin?

I know it's a lot of information/code and it can be a little tricky to answer, but i hope you guys are up for the challenge :D

Thx

brownie_cookie 04-01-2011 06:43 AM

can anyone explain this ?
Code:

use vars qw($host $opt_V $opt_h $opt_v $verbose $PROGNAME $pattern $opt_p $mmin $opt_m $opt_w $opt_e $opt_c $opt_t $opt_H $status $state $msg $msg_q $MAILQ $SHELL $device $used $avail $percent $fs $blocks $CMD $RMTOS);

$pattern = $opt_p;
$mmin = $opt_m;

if ( $RMTOS eq "Linux" ) {
        $CMD = "/usr/local/bin/find " . $pattern . " -type f -mmin " . $mmin . " 2>/dev/null| /usr/bin/wc -l";
}

i've found this in a nagios plugin, but i don't know why it's for...
it's written in PERL and i don't know anything about perl


All times are GMT -5. The time now is 11:43 AM.