Need help?

Our experts have had an average response time of 13.52 minutes in October 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/Plugin.pm 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.

Specifically:

  • 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:

/etc/sysconfig/nagios

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
Mod-Gearman

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:

/etc/sysconfig/mod-gearman2-worker

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:

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/important_application
ORACLE_HOME=/usr/lib/oracle/11.2/client64

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:

#!/bin/bash
env | grep -v ‘|’
exit 0

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

 

Conclusion

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.

PREVENT YOUR SERVER FROM CRASHING!

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.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

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

Reviews

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF