Call Us! 1-800-383-5193
Call Us! 1-800-383-5193
Call Us! 1-800-383-5193

Need Help?

Emergency Response Time custom

Our experts have had an average response time of 11.98 minutes in June 2021 to fix urgent issues.

We will keep your servers stable, secure and fast at all times for one fixed price.

Define Global Environment Variables in Nagios – How we do it

by | Apr 8, 2021

Wondering how to Define Global Environment Variables in Nagios? We can help you.

Recently, we had a customer who came across a plugin error. In such a case, we define variables required for plugins globally.

As part of our Server Management Services, we assist our customers with several Nagios queries.

Today, let us discuss the error and resolution.


The Nagios Error

While we set up a check-in Nagios, we may come across an error similar to the following:

[Can’t locate Monitoring/ in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl
/usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/local/nagios/libexec/check_rabbitmq_aliveness l
BEGIN failed–compilation aborted at /usr/local/nagios/libexec/check_rabbitmq_aliveness line 15.]

However, the execution of check-in and SSH session as the Nagios user executes perfectly.

When we test the plugin in an SSH session, we use a session that has loads of environment variables from the bash profile. This has an extended PATH which allows bash to find the required modules.

In certain scenarios, when the plugin executes by the monitoring engine, these environment variables may not load. Hence the plugin fails to find them.


Define Global Environment Variables in Nagios

Moving ahead, we will define variables required for plugins globally.


  • Add the path /usr/local/important_application to the PATH environment
  • Add the variable ORACLE_HOME=/usr/lib/oracle/11.2/client64

Initially, we edit a specific file that Nagios checks when it starts:


By default, this file does not exist. We create it.

Open an SSH session to Nagios host and type:

vi /etc/sysconfig/nagios

Then we add the following lines to the file:

export PATH=$PATH:/usr/local/important_application
export ORACLE_HOME=/usr/lib/oracle/11.2/client64

Now we restart Nagios:

RHEL 7+|CentOS 7+|Debian|Ubuntu 16/18/20

systemctl restart nagios.service

If we have Mod-Gearman, we have to perform the following steps on all of our workers.

The methods for workers are different depending on the operating system they run on.

  • RHEL 7+|CentOS 7+|Debian|Ubuntu 16/18/20

Since the use systemd which has a different method, referencing existing environment variables like $PATH will not work. If we wish to define the path, we need to define the entire path variable.

To do so, we:

  1. Re-define the PATH environment to include /usr/local/important_application
  2. Add the variable ORACLE_HOME=/usr/lib/oracle/11.2/client64

We can do this by editing a specific file that mod-gearman2-worker checks when the service starts:


Then we open an SSH session to Mod-Gearman worker and type:

vi /etc/sysconfig/mod-gearman2-worker

Add the following to the end of the file:


Now we reload the daemons and restart the Mod-Gearman worker:

systemctl daemon-reload
systemctl restart mod-gearman2-worker.service
  • RAM Disk

If we later configure Nagios with a RAM Disk, we will lose the settings we just added. We have to re-add the environment variables and it will work again.

How Can We See The Environment Variables

One way is to create a simple plugin that will output them. From this, we create a command and service, and then we can see the result in the GUI.

Bash script:

env | grep -v ‘|’
exit 0

[Need help to define Variables? We can help you]



To conclude, sometimes, when the plugin is executed, environment variables may not load. In such a scenario, our Support Techs define Global Environment Variables in Nagios.


Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.


var google_conversion_label = "owonCMyG5nEQ0aD71QM";


Submit a Comment

Your email address will not be published. Required fields are marked *