Hi,
We have an issue were the nrpe_user is configured to use nagios. However when the nagios user is called, it ignores the environment variables configured in bash.bashrc and profile.d/appenv.sh.
When the environment variable is hardcoded within our scripts this then does work.
I have seen messages about this happening in the event the nrpe_user has been assigned a numeric variable but as you can see in the below configuration (npre.cfg) this is not the case:
log_file=/var/log/nrpe.log
debug=1
pid_file=/var/run/nagios/nrpe.pid
server_port=5666
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=127.0.0.1,::1
dont_blame_nrpe=1
allow_bash_command_substitution=0
command_timeout=60
connection_timeout=300
command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib/nagios/plugins/check_load -r -w .15,.10,.05 -c .30,.25,.20
command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1
command[check_zombie_procs]=/usr/lib/nagios/plugins/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/lib/nagios/plugins/check_procs -w 150 -c 200
include=/etc/nagios/nrpe_local.cfg
include_dir=/etc/nagios/nrpe.d/
TIA - any help would be gratefully received
nrpe.cfg not passing through a global environment variable.
-
- Posts: 3
- Joined: Tue Mar 26, 2019 6:02 am
Re: nrpe.cfg not passing through a global environment variab
Commands executed by NRPE do not run in a shell -- Bash or otherwise. They are executed via popen. They therefore do not inherit environment variables defined in a particular shell.CrazyHorse019 wrote:However when the nagios user is called, it ignores the environment variables configured in bash.bashrc and profile.d/appenv.sh.
Here's the environment variables that get set on the latest NRPE version:
https://github.com/NagiosEnterprises/nr ... #L320-L338
Code: Select all
setenv("PATH", path, 1);
setenv("IFS", " \t\n", 1);
setenv("LOGNAME", nrpe_user, 0);
setenv("USER", nrpe_user, 0);
...
setenv("HOME", pw->pw_dir, 0);
setenv("SHELL", pw->pw_shell, 0);
Code: Select all
[Unit]
Description=Xinetd A Powerful Replacement For Inetd
After=syslog.target network.target NetworkManager-wait-online.service
[Service]
Type=forking
PIDFile=/var/run/xinetd.pid
EnvironmentFile=-/etc/sysconfig/xinetd
ExecStart=/usr/sbin/xinetd -stayalive -pidfile /var/run/xinetd.pid "$EXTRAOPTIONS"
ExecReload=/usr/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
Code: Select all
FOO="bar"
Code: Select all
command[echo_foo]=/usr/bin/echo hello $FOO; exit 0
Code: Select all
[root@capra_nag ~]# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c echo_foo
hello bar
TL;DR you can totally do this, but it depends on how both your operating system and your init system are handling environment variables because the NRPE process itself ... doesn't aside from the few I mentioned
Former Nagios employee
https://www.mcapra.com/
https://www.mcapra.com/
-
- Support Tech
- Posts: 3457
- Joined: Mon May 15, 2017 5:00 pm
Re: nrpe.cfg not passing through a global environment variab
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
-
- Posts: 3
- Joined: Tue Mar 26, 2019 6:02 am
Re: nrpe.cfg not passing through a global environment variab
Hi,
Thanks for the replies.
I should have mentioned the versions of services and OS that I am currently using - apologies that you've had to make assumptions.
So I am using nagios-nrpe-server service on ubuntu 18.04 - neither inetd or xinetd are installed on the system. The purpose of using nagios nrpe is to to serve my icinga 1.x installation in conjunction with pnp4nagios.
I am using nagios-nrpe-server 3.2.1-1ubuntu1.
Are there any caveats to this installation or do the same instructions still apply - would I just install xinetd and add the environment variable and have it referenced in the nrpe config?
Thanks for the replies.
I should have mentioned the versions of services and OS that I am currently using - apologies that you've had to make assumptions.
So I am using nagios-nrpe-server service on ubuntu 18.04 - neither inetd or xinetd are installed on the system. The purpose of using nagios nrpe is to to serve my icinga 1.x installation in conjunction with pnp4nagios.
I am using nagios-nrpe-server 3.2.1-1ubuntu1.
Are there any caveats to this installation or do the same instructions still apply - would I just install xinetd and add the environment variable and have it referenced in the nrpe config?
-
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: nrpe.cfg not passing through a global environment variab
As mcapra mentioned
Additionally, this is a Nagios forum and we cannot support icinga installations.
Locking thread
If you want to add variables they need to be added to the command, such asmcapra wrote:Commands executed by NRPE do not run in a shell -- Bash or otherwise. They are executed via popen. They therefore do not inherit environment variables defined in a particular shell.
Code: Select all
command[echo_foo]=/usr/bin/env FOO="bar" /usr/bin/echo hello $FOO; exit 0
Locking thread