Home » Categories » Multiple Categories

Nagios XI - Defining Global Environment Variables

Problem Description

When setting up a check in Nagios, you may get a 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 when you execute the check in an SSH session as the nagios user, it executes correctly.

 

 

Explanation

When you test the plugin in an SSH session, you are using a session that has environment variables loaded from your bash profile. This includes an extended PATH which allows bash to find the require modules.

In some environments, when the plugin is executed by the monitoring engine, these environment variables are not loaded and hence the plugin does not know where to find them and fails.

 

 

Define Global Environment Variables

In this solution, you will define variables required for you 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

 

This is performed by editing a specific file that nagios checks when it starts:

/etc/sysconfig/nagios

 

By default, this file does not exist, but you will create it just by opening vi to the file.

 

Open an SSH session to your Nagios XI host

Type:

vi /etc/sysconfig/nagios

 

Press i to start editing the file

Add the following lines to the file:

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

 

Press esc to stop the editing mode

Type:

:wq

 

Now restart Nagios:

 

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

systemctl restart nagios.service

 

 

Warning: Mod-Gearman is an unsupported third-party utility.

Nagios Enterprises provides this KB article to customers in good faith. However, an attempted integration with Mod-Gearman is not supported by Nagios Enterprises and future problems caused by using this method are beyond our control.

Multiple Nagios XI instances can be used if the size of your infrastructure or monitoring needs require you to create a distributed monitoring environment. Federated or distributed Nagios XI instances empower you to scale your infrastructure while making it easier to manage large environments and future changes. For more information on using multiple Nagios XI instances to distribute check load, visit Distributed Monitoring with Nagios XI.

Mod-Gearman

If you have Mod-Gearman, the following steps will need to be performed on all of your workers (including the XI server if it is a worker).

Note: The method for workers are different depending on the operating system they are running on.

 

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

These operating systems use systemd which has a different method, referencing existing environment variables like $PATH will not work. If you wish to define the path, you will need to define the entire path variable (which is shown below).

The following is being applied:

  • Re-define the PATH environment to include /usr/local/important_application

  • Add the variable ORACLE_HOME=/usr/lib/oracle/11.2/client64

 

This is performed by editing a specific file that mod-gearman2-worker checks when the service starts:

/etc/sysconfig/mod-gearman2-worker

 

Open an SSH session to your Mod-Gearman worker.

Type:

vi /etc/sysconfig/mod-gearman2-worker

 

Press i to start editing the file

Add the following lines 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

 

Press esc to stop the editing mode

Type:

:wq

 

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

systemctl daemon-reload
systemctl restart mod-gearman2-worker.service

 

 

RAM Disk

If you later configure Nagios XI with a RAM Disk using our installation script, the settings you just added will be lost. You will need to follow the steps above (Define Global Environment Variables) to re-add the environment variables and it will work again.

Nagios XI - Utilizing a RAM Disk in Nagios XI

 

 

How Can I See The Environment Variables ?

One way to see what environment variables are present when the plugin executes is to create a simple plugin that will output them. From this you create a command and service and then you can see the result in the XI GUI.

Bash script:

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

 

 

Final Thoughts

For any support related questions please visit the Nagios Support Forums at:

http://support.nagios.com/forum/

1.75 (4)
Article Rating (4 Votes)
Rate this article
  • Icon PDFExport to PDF
  • Icon MS-WordExport to MS Word
Attachments Attachments
There are no attachments for this article.
Related Articles RSS Feed
Nagios XI - Configuration Applies, No Changes Take Place
Viewed 7331 times since Tue, Jan 27, 2015
Nagios XI - MK Livestatus Problems With Mod-Gearman
Viewed 4861 times since Thu, Feb 25, 2016
Installation errors on customized corporate builds of CentOS or RHEL
Viewed 9773 times since Tue, Jan 26, 2016
Nagios XI - How To Delete A Data Source From An RRD File
Viewed 11474 times since Wed, Apr 27, 2016
VMWare checks timing out or slow
Viewed 2654 times since Fri, Feb 11, 2022
Nagios XI - Empty Screen for Wizard, Component, Dashlet
Viewed 5832 times since Wed, Jan 27, 2016
Nagios XI - Best Practices - NWC15
Viewed 7397 times since Thu, Feb 4, 2016
Nagios XI - Host Still Visible After Deletion (Ghost Hosts)
Viewed 10459 times since Tue, Jan 27, 2015
Nagios XI - Apply Configuration Fails - Backend login to the Core Configuration failed
Viewed 17158 times since Tue, Aug 2, 2016
Nagios XI - Unable To Login Using Two Factor Authentication
Viewed 7460 times since Tue, Apr 10, 2018