Problem with return variables value from custom script

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
dberlenda
Posts: 19
Joined: Thu May 23, 2019 5:05 am

Problem with return variables value from custom script

Post by dberlenda »

Hi experts ,
I created a custom script that does not use the plugins check_by_ssh or chek_nrpe etc ...
My script is created in the nagios server and if i start the script from command line the output of script variables are returned :
OK - GAP: 0 | LOG_PRIM: 34098 - LOG_STANBY: 34098

the last lines of my scripts are :
echo "OK - GAP: $DIFF_LOG- LOG_PRIM: $LOGPRIMARIO - LOG_STANBY: $LOGSTANDBY"
EXIT=0

The problem is in the Nagios web interface ( column Status Information ) where for this service i have only the texts of the script output without the return variables values :
OK - GAP: - LOG_PRIM: LOG_STANBY:

the value of variables $DIFF_LOG , $LOGPRIMARIO and $LOGSTANDBY are missing .

I suppose that the problem is on nagios configuration but i dont' have any idea about what Nagios parameters i have to check ...

Do you have any suggestions ?
Thanks in advace
Davide
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

Re: Problem with return variables value from custom script

Post by cdienger »

Can you simplify the script and test? I haven't reproduced it yet and a simple bash script(assumed that's what your script is written in) doesn't show the same behavior:

Code: Select all

#!/bin/bash
DIFF_LOG=1
LOG_PRIM=2
LOG_STANDBY=3

echo "OK - GAP:  $DIFF_LOG - LOG_PRIM: $LOG_PRIM - LOG_STANBY: $LOG_STANDBY"
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
dberlenda
Posts: 19
Joined: Thu May 23, 2019 5:05 am

Re: Problem with return variables value from custom script

Post by dberlenda »

Hi ,
I created the test script and the the output is returned successfull to Nagios web interface.
I suppose that the problem is that the results of my sql queries have some black space in the left side of the numbers that i assigned to the script varialbles .
The outputs of the Oracle sql queries are numbers but they are some black space at the left and i don't know how to delete they.

My script is the follow :

Code: Select all

# Imput Parameters
username_prim=$1
password_prim=$2
SID_prim=$3
####
username_standby=$4
password_standby=$5
SID_standby=$6
WARNING=$7
CRITICAL=$8


# Controllo a che log e' arrivato il primary
LOGPRIMARIO=$(sqlplus -s $username_prim/$password_prim@$SID_prim as sysdba << EOF
set heading off
set pagesize 0
SELECT max(sequence#) from V\$LOG_HISTORY;
EOF
)
#echo "LOG DB PRIM =" $LOGPRIMARIO
ORAERROR=$(echo "$LOGPRIMARIO" | grep ORA-)
ORAERRORCODE=$?
#echo "Ret ORAerrprim =" $ORAERRORCODE
if [ $ORAERRORCODE -eq 0 ]; then
        echo "Connection trouble with PrimaryDB - $(echo "$LOGPRIMARIO" | grep ORA- | head -1)"
        EXITCODE=3
fi


# Controllo ultimo log applicato sullo standby
LOGSTANDBY=$(sqlplus -s $username_standby/$password_standby@$SID_standby as sysdba << EOF
set heading off
set pagesize 0
SELECT max(sequence#) from V\$LOG_HISTORY;
EOF
)
#echo "LOG DB STANDBY =" $LOGSTANDBY
ORAERROR=$(echo "$LOGPRIMARIO" | grep ORA-)
ORAERRORCODE=$?
#echo "Ret ORAerrsec =" $ORAERRORCODE
if [ $ORAERRORCODE -eq 0 ]; then
        echo "Connection trouble with StanbyDB - $(echo "$LOGSTANDBY" | grep ORA- | head -1)"
        EXITCODE=3
fi

export LOGPRIMARIO LOGSTANDBY

#Controllo differenza fra log del primario e secondario
DIFF_LOG=$(expr $LOGPRIMARIO - $LOGSTANDBY)
#echo "DIFF LOG = " $DIFF_LOG

if [ $DIFF_LOG -gt $CRITICAL ]; then
            echo "Critical - GAP: $DIFF_LOG - LOG_PRIM: $LOGPRIMARIO - LOG_STANBY: $LOGSTANDBY"
            EXIT=2
        else
          if [ $DIFF_LOG -gt $WARNING ]; then
              echo "Warning - GAP: $DIFF_LOG - LOG_PRIM: $LOGPRIMARIO - LOG_STANBY: $LOGSTANDBY"
              EXIT=1
          else
            echo "OK - GAP: $DIFF_LOG - LOG_PRIM: $LOGPRIMARIO - LOG_STANBY: $LOGSTANDBY"
            ##printf "OK - GAP: $DIFF_LOG LOG_PRIM: $LOGPRIMARIO  LOG_STANBY: $LOGSTANDBY"
            EXIT=0
          fi
fi
Thanks
Davide
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

Re: Problem with return variables value from custom script

Post by cdienger »

What are the permissions on sqlplus? When you run the script from the command line, make sure you're running it as the nagios user:

Code: Select all

su - nagios
./script
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Locked