Environment Variables

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
Maxwellb99
Posts: 97
Joined: Tue Jan 26, 2016 5:29 pm

Environment Variables

Post by Maxwellb99 »

Hi Nagios,

I'm trying to set some environment variables LD_LIBRARY_PATH (for DB2 & Oracle) ORACLE_HOME, DB2_HOME. Right now I'm passing them in as part of the command. I'm looking for a more elegant solution.

Commands (I'm passing the Environment Variables via env)
/usr/bin/env LD_LIBRARY_PATH=/opt/dsdriver/lib /usr/local/nagios/libexec/check_db2_health $ARG1$
/usr/bin/env LD_LIBRARY_PATH=/usr/lib/oracle/18.3/client64/lib ORACLE_HOME=/usr/lib/oracle/18.3/client64 $USER1$/check_oracle_health $ARG1$

LD_LIBRARY_PATH="/usr/lib/oracle/18.3/client64/lib:/opt/dsdriver/lib:$LD_LIBRARY_PATH"
ORACLE_HOME="/usr/lib/oracle/18.3/client64"
DB2_HOME="/opt/dsdriver"

I added the Nagios file to /etc/sysconfig/nagios. (My syntax inside the file may be off). That wasn't doing anything so I added the EnvironmentFile & eventually Environment arguments to /etc/systemd/system/multi-user.target.wants/nagios.service.

I set up the service to grab the environment. It shows that the variables are in there.
Ok
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
PWD=/tmp
LANG=en_US.UTF-8
Environment=LD_LIBRARY_PATH="/usr/lib/oracle/18.3/client64/lib:/opt/dsdriver/lib:$LD_LIBRARY_PATH" ORACLE_HOME="/usr/lib/oracle/18.3/client64" DB2_HOME="/opt/dsdriver"
SHLVL=1
_=/usr/bin/env

I'm still getting that missing linked library when I run the check_db2_health plugin & check_oracle plugin. The message goes away when the LD_LIBRARY_PATH variable is there & set. So, what's the best practice for getting environment variables in Nagios?

I saw that Nagios has the Oracle environment variables in /usr/local/nagiosxi/etc/configwizards/oracle/oracle. who is calling that & how does that work?

Thanks,
Max Ramirez
gsmith
Posts: 1253
Joined: Tue Mar 02, 2021 11:15 am

Re: Environment Variables

Post by gsmith »

Hi Max,


These commands are calling /usr/local/nagiosxi/etc/configwizards/oracle/oracle:
check_xi_oracleserverspace = . /usr/local/nagiosxi/etc/configwizards/oracle/oracle && $USER1$/check_oracle_health $ARG1$
check_xi_oracletablespace = . /usr/local/nagiosxi/etc/configwizards/oracle/oracle && $USER1$/check_oracle_health $ARG1$
check_xi_oraclequery = . /usr/local/nagiosxi/etc/configwizards/oracle/oracle && $USER1$/check_oracle_health $ARG1$

So what it is saying is:
from here . (the dot)
run: /usr/local/nagiosxi/etc/configwizards/oracle/oracle
and if /usr/local/nagiosxi/etc/configwizards/oracle/oracle executes successfully then run $USER1$/check_oracle_health $ARG1$

Does that make sense to you?

Thanks
Maxwellb99
Posts: 97
Joined: Tue Jan 26, 2016 5:29 pm

Re: Environment Variables

Post by Maxwellb99 »

Hi Nagios,

Oh ok, so, I think we're saying the same thing. I'm using the legacy way & running env. (see below).

Ok, correct me if I'm wrong but that's exporting/setting LD_LIBRARY_PATH every time check_oracle_health is being run & in my case check_db2_health?

if that's the case, my question is: do you have any documentation for setting the environment variables one-time, say, when Nagios restarts then simply calling check_oracle_health/check_db2_health (without the export)?
Would that be within the purview of Apache? I tried changing /etc/systemd/system/multi-user.target.wants/nagios.service

Commands (I'm passing the Environment Variables via env)
/usr/bin/env LD_LIBRARY_PATH=/opt/dsdriver/lib /usr/local/nagios/libexec/check_db2_health $ARG1$
/usr/bin/env LD_LIBRARY_PATH=/usr/lib/oracle/18.3/client64/lib ORACLE_HOME=/usr/lib/oracle/18.3/client64 $USER1$/check_oracle_health $ARG1$

Thanks,
Max R
gsmith
Posts: 1253
Joined: Tue Mar 02, 2021 11:15 am

Re: Environment Variables

Post by gsmith »

Hi

Here's what worked for me:


vi /etc/systemd/system/multi-user.target.wants/nagios.service
add:
Environment=ORACLE_HOME=/usr/lib/oracle/21/client64LD_LIBRARY_PATH=/usr/lib/oracle/21/client64/libTNS_ADMIN=/usr/lib/oracle/21/client64/lib/network/admin

Then run:

Code: Select all

sudo systemctl daemon-reload
sudo systemctl restart nagios
To check the envionment variables of Nagios first get it's id and then cat out the environ for that process:

Code: Select all

[root@gs-rhel8-23-84 ~]# ps -ef | grep nagios
nagios      1115       1  0 Jan28 ?        00:00:00 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -f
nagios      1706       1  0 Jan28 ?        00:00:27 /usr/local/ncpa/ncpa_passive --start
nagios      2335       1  0 Jan28 ?        00:00:07 /usr/lib/systemd/systemd --user
nagios      2337    2335  0 Jan28 ?        00:00:00 (sd-pam)
nagios    102029       1  0 Jan28 ?        00:00:09 /usr/local/nagios/bin/npcd -d -f /usr/local/nagios/etc/pnp/npcd.cfg
nagios    129117       1  0 Jan28 ?        00:00:56 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
nagios    129122  129117  0 Jan28 ?        00:00:01 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
nagios    129123  129117  0 Jan28 ?        00:00:01 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
 
[root@gs-rhel8-23-84 ~]# cat /proc/129117/environ
LANG=en_US.UTF-8PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/binINVOCATION_ID=16648885aac24c9c85204d97fcb0d035JOURNAL_STREAM=9:952378ORACLE_HOME=/usr/lib/oracle/21/client64LD_LIBRARY_PATH=/usr/lib/oracle/21/client64/libTNS_ADMIN=/usr/lib/oracle/21/client64/lib/network/admin
Thanks!
Locked