ORACLE_HOME in PATH variable missing

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
nagios-typ
Posts: 2
Joined: Mon Aug 01, 2016 8:23 am

ORACLE_HOME in PATH variable missing

Post by nagios-typ »

Hello everybody,

I have a problem with nagios and an oracle client.

My set up is the following:

OS: Oracle Linux Server release 6.5
Nagios: Nagios Core 4.0.6

I installed an oracle client on my nagios and try to login on a database via sqlplus. If I use CLI everything will work fine. If nagios try to login itself, it is not possible. I checked environment variables on CLI, which looks good.

Code: Select all

[nagios@nagiosxi-test ~]$ env
HOSTNAME=nagiosxi-test.ber.mytoys.de
SHELL=/bin/bash
TERM=xterm
HISTSIZE=1000
PERL5LIB=/usr/local/nagios/perl/lib
QTDIR=/usr/lib64/qt-3.3
QTINC=/usr/lib64/qt-3.3/include
USER=nagios
LD_LIBRARY_PATH=/usr/lib/oracle/12.1/client64/lib/
TNS_ADMIN=/usr/lib/oracle/12.1/client64/lib/network/admin/
MAIL=/var/spool/mail/nagios
PATH=/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/nagios/bin:/usr/lib/oracle/12.1/client64//bin
PWD=/usr/local/nagios
LANG=en_US.UTF-8
HISTCONTROL=ignoredups
SHLVL=1
HOME=/usr/local/nagios
LOGNAME=nagios
QTLIB=/usr/lib64/qt-3.3/lib
CVS_RSH=ssh
LESSOPEN=|/usr/bin/lesspipe.sh %s
ORACLE_HOME=/usr/lib/oracle/12.1/client64/
G_BROKEN_FILENAMES=1
_=/bin/env
I checked environmet variables, which nagios use, but they do not look the same. The ORACLE_HOME is missing in PATH variable.

Code: Select all

[nagios@nagiosxi-test ~]$ tail -50f /var/tmp/db.log 
TERM=linux
LD_LIBRARY_PATH=/usr/lib/oracle/12.1/client64/lib
PATH=/sbin:/usr/sbin:/bin:/usr/bin
TNS_ADMIN=/usr/lib/oracle/12.1/client64/lib/network/admin/
runlevel=3
RUNLEVEL=3
LANGSH_SOURCED=1
PWD=/tmp
LANG=en_US.UTF-8
previous=N
PREVLEVEL=N
CONSOLETYPE=vt
SHLVL=3
UPSTART_INSTANCE=
UPSTART_EVENTS=runlevel
UPSTART_JOB=rc
ORACLE_HOME=/usr/lib/oracle/12.1/client64/
_=/bin/env
Error Message:

Code: Select all

ERROR: ORA-12154: TNS:could not resolve the connect identifier specified SP2-0306: Invalid option. Usage: CONN[ECT] [{logon|/|proxy} [AS {SYSDBA|SYSOPER|SYSASM|SYSBACKUP|SYSDG|SYSKM}] [edition=value]] where <logon> ::= <username>[/<password>][@<connect_identifier>] <proxy> ::= <proxyuser>[<username>][/<password>][@<connect_identifier>] SP2-0306: Invalid option. Usage: CONN[ECT] [{logon|/|proxy} [AS {SYSDBA|SYSOPER|SYSASM|SYSBACKUP|SYSDG|SYSKM}] [edition=value]] where <logon> ::= <username>[/<password>][@<connect_identifier>] <proxy> ::= <proxyuser>[<username>][/<password>][@<connect_identifier>] SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus
I added the environment variables in /etc/sysconfig/nagios and restarted nagios but nothing changed.

Code: Select all

[nagios@nagiosxi-test ~]$ cat /etc/sysconfig/nagios
export LD_LIBRARY_PATH=/usr/lib/oracle/12.1/client64/lib
export TNS_ADMIN=/usr/lib/oracle/12.1/client64/lib/network/admin/
export ORACLE_HOME=/usr/lib/oracle/12.1/client64/
export PATH=$PATH:$ORACLE_HOME/bin
I don't know what to do now. Hopefully somebody can help me with this problem.

Kind regards,

nagios-typ
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: ORACLE_HOME in PATH variable missing

Post by rkennedy »

Can you show us your service, and command definition associated that you're attempting?

You most likely need to define the ORACLE_HOME path in the command definition, when executing it. We have a guide that is for Nagios XI, but nothing specifically for Core. Take a look at how the commands are defined in our walk through (bottom of page 2) - https://assets.nagios.com/downloads/nag ... ios-XI.pdf
Former Nagios Employee
nagios-typ
Posts: 2
Joined: Mon Aug 01, 2016 8:23 am

Re: ORACLE_HOME in PATH variable missing

Post by nagios-typ »

Hello,

enclosed the informations:

Service Definition

Code: Select all

define service{
        use                             generic-service         ; Name of service template to use
        host_name                       xxxxxx
        service_description             ORACLE DB ALIVE 
        is_volatile                     0
        check_period                    24x7
        max_check_attempts              3
        normal_check_interval           5
        retry_check_interval            1
        contact_groups                  admins_betrieb, dba_pager, pager, dwh_email
        notification_interval           120
        notification_period             24x7
        notification_options            w,u,c,r
        check_command                   check_ext_db_alive!test!test
}
Command Definition

Code: Select all

define command{
        command_name    check_ext_db_alive
        command_line    $USER1$/check_database_alive.sh $USER3$ $USER4$ $ARG1$ $ARG2$
}
Skript behind

Code: Select all

. /usr/local/nagios/libexec/utils.sh

if [ $# -ne 4 ]
then
  echo "Use: ./check_database_alive.sh user passwd DB-Name"
  echo "Example: ./check_database_alive2.sh nagios *** KRIMI"
  echo 
  echo "Fehler bei der Parameteruebergabe!"
  exit $STATE_UNKOWN
else
  USER=$1
  PASSWORD=$2
  DATABASE=$3
  DATABASE_COMP=$4
fi

env > /var/tmp/db.log

# Hier fragen wir mal die DB ab.
STATUS=`sqlplus -s ${USER}/${PASSWORD}@${DATABASE} << EOF
set head off
select name from v\\$database;
exit;
EOF`

echo $STATUS >> /var/tmp/db.log

TEST_VALUE=""
TEST_VALUE=`echo "$STATUS" | grep $DATABASE_COMP`

if [ "$TEST_VALUE" != "$DATABASE_COMP" ]
then
  echo "CRITICAL: Fehler bei sqlplus-Abfrage der Datenbank $3!"
  exit $STATE_CRITICAL
else
  echo "OK: Erfolgreiche sqlplus-Abfrage der Datenbank $3."
  exit $STATE_OK
fi
So I have to add the Variables in command_line or the script itself. I think this is dirty, because I have to add this into a lot of scripts. Why is it not possible to set the PATH variable with /etc/sysconfig/nagios?

Kind Regards
nagios-typ
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: ORACLE_HOME in PATH variable missing

Post by mcapra »

nagios-typ wrote:So I have to add the Variables in command_line or the script itself. I think this is dirty, because I have to add this into a lot of scripts.
The plugins that we use in Nagios XI follow the same convention (see page 2 under "Configure Oracle Plugin Commands"). Unfortunately there isn't a very good way to scale this problem in Core currently.
nagios-typ wrote:Why is it not possible to set the PATH variable with /etc/sysconfig/nagios?
The best way to get changes made is to file it as an issue through Github:

https://github.com/NagiosEnterprises/nagioscore
Former Nagios employee
https://www.mcapra.com/
Locked