Nagios 2-Way Integration with Nginx

nagios
webhooks
doc-review
nginx
official

(Demitri Morgan) #1

The bi-directional integration with Nagios requires a webhook receiving point to process updates from PagerDuty, which is where the CGI script comes into play.

The integration guide covers installation on a RHEL-based or Ubuntu-based Linux system. On such systems, the Nagios package assembled and supplied by the distribution’s community, installed via the package manager, uses Apache for the Nagios administrative web UI, and automatically creates Apache directory aliases for the UI as well as CGI scripts.

Let’s assume, in this case, that the default web ports on the host running Nagios are already in use by Nginx. Our goal here will be to still be able to run the Nagios CGI scripts (including pagerduty.cgi).

Using Apache

You can run Apache on the same host as Nginx, but listening on a different port.

Advantages:

  • If installing from a package manager, this will also grant access to the Nagios web UI via Nginx
  • Easier to set up if Nagios and Apache were installed via package manager.

Disadvantages:

  • More steps to configure
  • Separate service to maintain, which also means an additional point of failure

With the barest initial Apache configuration provided by package installation will come a “default” virtual host. One can either modify this host or create a new one, but modifying the existing one is a bit easier (I recommend just make a backup/reference copy of it first).

The location of the directive that is in use as the default virtual hosts may differ between systems. One can find it using:

grep -r 'VirtualHost' /etc/apache2 # Debian-based
grep -r 'VirtualHost' /etc/httpd # RHEL-based 

In your Apache config: in the default virtual host declaration, change the VirtualHost definition so that the listen port is 8080 and address is the local host. For instance:

<VirtualHost 127.0.0.1:8080>

You may set it to something different in the event that the port is also already in use.

Note: it was observed on Ubuntu 16.04, there’s a file /etc/apache2/ports.conf file that globally sets the listen address for all virtual hosts, in which you will need to set:

Listen 8080

This may apply to other Debian-based distributions of Linux.

In your Nginx config: inside of the server directive for the Nginx virtual host listening on the default HTTP port(s), add this:

    location /nagios3 {
        proxy_pass http://127.0.0.1:8080/nagios3;
    }

Note, in the above, the path will be “/nagios” as opposed to “/nagios3” on RHEL-based distributions.

Using nginx and a FastCGI server.

This method configures nginx for running CGI scripts.

Advantages:

  • No need to create an unnecessary additional HTTP service
  • Having a FastCGI service configured can serve other purposes

Disadvantages:

  • More complex setup compared to first method; prepackaged Apache often has out-of-box CGI support
  • No HTTP basic auth to password protect the webhook endpoint (that comes with using Nagios’ Apache-based web UI); this needs to be configured separately.

Follow the instructions in Nginx’s knowledge base, Setting up Perl FastCGI with Nginx. This will involve starting a FastCGI service to run CGI scripts on behalf of Nginx.

Once done with that, copy the pagerduty.cgi script into the web root of the host. The URL you can use for the webhook will then be http(s)://[your server]/pagerduty.cgi


(system) #2