How to use Nagios plugins

How can I use Nagios plugins to perform monitoring?

Q: Can I use Nagios plugins for monitoring?

A: Yes, you can, it only requires one-time setup.

1. Possible scenarios

Generally speaking, Nagios plugin is any executable program or script that conforms to Nagios plugins guidelines (output structure and exit codes). Since there is no native Nagios plugins for Windows, several scenarios can be used, depending on monitoring environment.

Nagios plugins are compact and multi-functional checking units for several most commonly used protocols and technologies; instead of writing a custom script, you can consider first using the plugins, if built-in IPHost monitor types do not meet your needs.

Out of several possible scenarios, use the one most convenient for you. Note that in case you use Cygwin-based environment, it will be your responsibility to keep the plugins setup and underlying Cygwin environment properly updated.

The possible list of setups:

Setup type Monitor type Requirements Comments

Cygwin-based

“Script or Program”

Any Windows type supporting Cygwin (Vista and newer).

Only a subset of official Nagios plugin distribution is supported (see below).

Windows Subsystem for Linux (WSL)

“Script or Program”, or “SSH Script or Program”

Compatible Windows type and version:

  • Windows 10 starting from version 1607
  • Windows Server 2019

One of the below is required:

  • IPHost monitoring service running under user account that has WSL access
  • SSH server should be set up and running on WSL
Quickest compared to other scenarios.

Unix-like host based

“SSH Script or Program”

A Unix-like system (physical or virtual), supporting Nagios plugins (that includes variety of Linux distributions, MacOS, BSD-like etc), running SSH server.

Depending on Unix-like host type, subset of Nagios plugins might be supported.

More detailed instructions follow.

1.1. Cygwin-based

Cygwin is a POSIX-compatible environment, providing capability to port and run Unix-like applications (both console and GUI-based) on Windows systems. The details of setting up Cygwin is outside of this how-to; please contact us if you would need an assistance.

Assuming you have installed Cygwin environment, below is the short set of instructions to compile and prepare to use Nagios plugins:

1. Make sure you have installed the below Cygwin components (they can require installing additional packages, confirm when asked):

gcc-g++ gd jpeg libgd-devel libpng httpd httpd-devel make autoconf automake

2. Download the latest tarball of Nagios plugins sources (at the moment of writing this article, the file name is nagios-plugins-2.3.0.tar.gz).

3. Run elevated (“Run as Administrator”) Cygwin terminal and type the below commands:

mkdir -p /usr/local/src/install
cd /usr/local/src/install
tar zxf </path/to/nagios-plugins-2.3.0.tar.gz>
cd nagios-plugins-2.3.0
./configure --prefix=/opt/nagios
make -i all
make -i install

The compiled plugins will be placed into Cygwin path /opt/nagios/libexec (Windows path, in case of 64-bit Cygwin, will be “C:\Cygwin64\opt\nagios\libexec” for default Cygwin setup settings).

4. Add /bin Cygwin path (Windows path “C:\Cygwin64\bin” for default 64-bit Cygwin settings) to system PATH (via “This PC > Properties > Advanced system settings > Environment Variables”, under “System variables”, edit Path variable and add the mentioned Windows path).

Note: you might need to restart IPHost monitoring services so that it could run Cygwin-compiled Nagios plugins.

5. The below plugins are available for this scenario:

check_apt check_breeze check_by_ssh check_cluster
check_disk check_disk_smb check_dns check_dummy
check_file_age check_flexlm check_http check_ifoperstatus
check_ifstatus check_ircd check_ldap check_load
check_log check_mailq check_mrtg check_mrtgtraf
check_nt check_ntp check_ntp_peer check_ntp_time
check_nwstat check_oracle check_overcr check_ping
check_real check_rpc check_sensors check_smtp
check_ssh check_swap check_tcp check_time
check_ups check_users check_wave

Note: several plugins are useless in Cygwin environment, such as check_apt (since Windows doesn’t use APT packages manager); check_smb (it requires smbclient, which isn’t available for Cygwin from standard repository).

Note: make sure use are running check_by_ssh and check_ssh plugins under a Windows account that has real home directory (since .ssh configuration directory will be required). That excludes default SYSTEM account.

1.2. Windows Subsystem for Linux

Windows Subsystem for Linux (WSL) is a compatibility layer that runs Linux native applications. In case you have a compatible OS, install WSL. You can use any supported Linux distribution. In the below instructions we assume you have installed Ubuntu. Use appropriate Nagios plugins installation instructions if another distribution has been selected.

After you have installed WSL and created your Linux user (for the sake of example, we assume the user name is “monitor” hereinafter), start Bash window and run the below commands:

sudo apt-get update -y
sudo apt-get install nagios-plugins -y

In our example, plugins binaries will be placed into /usr/lib/nagios/plugins , and the below plugins are available:

check_apt check_breeze check_by_ssh check_clamd
check_cluster check_dbi check_dhcp check_dig
check_disk check_disk_smb check_dns check_dummy
check_file_age check_flexlm check_fping check_ftp
check_game check_host check_hpjd check_http
check_icmp check_ide_smart check_ifoperstatus check_ifstatus
check_imap check_ircd check_jabber check_ldap
check_ldaps check_load check_log check_mailq
check_mrtg check_mrtgtraf check_mysql check_mysql_query
check_nagios check_nntp check_nntps check_nt
check_ntp check_ntp_peer check_ntp_time check_nwstat
check_oracle check_overcr check_pgsql check_ping
check_pop check_procs check_real check_rpc
check_rta_multi check_sensors check_simap check_smtp
check_snmp check_spop check_ssh check_ssmtp
check_swap check_tcp check_time check_udp
check_ups check_users check_wave

Important: by default, the Bash executable (C:\Windows\System32\bash.exe) is inaccessible for third-party programs in its default location. Copy that executable into arbitrary folder where it can be accessible by any user (in the example below, “C:\Scripts” ).

Note: to run Nagios plugins via Bash (quickest setup), you must ensure monitoring service is being run under Windows account with access to WSL. Yo cannot run Bash version if monitoring service is run under SYSTEM account (by default). Make sure the account in question belongs to “Administrators” group.

If you cannot or may not run the monitoring service under WSL-enabled Windows administrator account, you can either run SSH server within your WSL installation (make sure it’s started at boot time by running appropriate scheduled task), or use an external SSH-enabled Unix-like system (see below).

1.3. Unix-like host running SSH service

Depending on OS type and version, different commands can be used to install the Nagios plugins. Please refer to the OS guides for that; in case of Ubuntu, see the commands from the above 1.2 section.

2. Monitor setup details

Below the general instructions are provided for running Nagios plugins monitors. For specific instructions, please refer to Nagios plugins manual pages.

2.1. Script or Program

Typical “Script or Program” monitor definition would look like below

Nagios plugin Script or Program

Scenario-specific settings follow.

Cygwin-based monitor would have following definition (if you were following the above mentioined setup steps):
Path: C:\Cygwin64\bin\bash.exe
Arguments: -c "/opt/nagios/libexec/plugin_name plugin-specific parameters"
WSL (Bash)-based monitor would have following definition:
Path: C:\Scripts\bash.exe
Arguments: -c "/usr/lib/nagios/plugins/plugin plugin-specific parameters"

2.2. SSH Script or Program

Typical “SSH Script or Program” monitor definition would look like below

Nagios plugin SSH Script or Program

3. Upgrading plugins

As Nagios plugins are updated (you might wish to create a monitor to check that), one could need to upgrade locally installed plugins.

In case of Cygwin-powered plugins, just download the fresh plugins tarball and repeat the installation steps. Stop monitoring service, if you are usign Cygwin-based Nagios plugins, before running “make -i install” command.

In case of WSL-based Nagios plugins, similarly repeat steps to install them.

If you are running Nagios plugins installed on a remote host, consult the corresponding OS manuals on upgrading/reinstalling the plugins executables.

4. Tips and tricks

1. Nagios plugins have their own ways to control switching to Warning or Down state. In most cases, this is done by using the below parameters:

-w timevalue
Set interval of time (in seconds; can be fractional, e.g. 0.05 means 50 milliseconds) after which monitor should switch to Warning state
-c timevalue
Set interval of time (in seconds; can be fractional, e.g. 1.25 means one and a quarter of second) after which monitor should switch to Down (Critical, in Nagios terms) state

2. We recommend running Nagios plugins in command line first; it will show their output and allow to understand better whatever could go wrong.

Use “-v” command-line parameter to provide verbose plugin output.

Related links