How to Integrate Nagios XI with PagerDuty

Introduction

Nagios XI expands upon the capabilities of the Nagios Core software to provide you with detailed host and service monitoring for your critical IT systems. In this guide we will walk you through the process of configuring Nagios XI to work with PagerDuty.

Setting up the PagerDuty / Nagios XI integration

Tested with Nagios XI 2012R1.4 on CentOS 6×64

In PagerDuty:

If you don’t already have a PagerDuty “Nagios” service, you should create one:

  1. In your account, under the Services tab, click “Add New Service” and enter a name for the service and select an escalation policy.
  2. Start typing “Nagios XI” under “Integration Type” to filter your choices. Then, click the “Add Service” button.
    NagiosXI
  3. Once the service is created, you’ll be taken to the service page. On this page, you’ll see the “Service API key”, which will be needed when you configure your Nagios XI to send events to PagerDuty.

From your Nagios XI Server Shell

Perl Script Installation

  1. Install the necessary Perl dependencies:
    yum install perl-libwww-perl perl-Crypt-SSLeay
  2. Download pagerduty_Nagios XI.pl and copy it to /usr/local/nagios/libexec/notifications.
    wget https://raw.github.com/PagerDuty/pagerduty-nagios-pl/master/pagerduty_nagios.pl
    cp pagerduty_nagios.pl /usr/local/bin
  3. Make sure the file is executable by the nagios user.
    chmod 755 /usr/local/bin/pagerduty_nagios.pl
  4. Edit the nagios user’s crontab.
    crontab -u nagios -e
  5. Add the following line to the crontab.
    * * * * *  /usr/local/bin/pagerduty_nagios.pl flush

In Nagios XI:

Create the New Commands

  1. Login to the Core Configuration Manager by going to Configure and clicking on Core Config Manager. Note: This login is separate from your nagiosadmin account.
  2. Click on Commands > Commands.
  3. Click on the Add New button.
  4. Enter the information as follows:
    Command Name:

    notify-service-by-pagerduty

    Command Line:

    /usr/local/bin/pagerduty_nagios.pl enqueue -f pd_nagios_object=service -f CONTACTPAGER="$CONTACTPAGER$" -f NOTIFICATIONTYPE="$NOTIFICATIONTYPE$" -f HOSTNAME="$HOSTNAME$" -f SERVICEDESC="$SERVICEDESC$" -f SERVICESTATE="$SERVICESTATE$"

    Command Type:

    misc command

    Active: Checked

  5. Click on Save.
  6. Repeat the steps to add a second command.
    Command Name:

    notify-host-by-pagerduty

    Command Line:

    /usr/local/bin/pagerduty_nagios.pl enqueue -f pd_nagios_object=host -f CONTACTPAGER="$CONTACTPAGER$" -f NOTIFICATIONTYPE="$NOTIFICATIONTYPE$" -f HOSTNAME="$HOSTNAME$" -f HOSTSTATE="$HOSTSTATE$" 


    Command Type:

    misc command

    Active: Checked

  7. Click the Apply Configuration button.

Create the new Contacts

  1. You’ll need to create a PagerDuty contact. To do so, go to Alerting > Contacts.
  2. Click on Add New.
  3. Enter the following under Common Settings:
    Contact Name:

    pagerduty 


    (Note: If you are connecting with multiple PagerDuty services via Nagios, you will have to use different Contact names (e.g. pagerduty_service1, pagerduty_service2, etc…))
    Description:

    PagerDuty

    Active: Checked

  4. Enter the following under Alert Settings:
    Host Notifications Enabled: on
    Host Notification Timeperiod: 24×7
    Host Notification options: d, r
  5. Click on Manage Host Notification Commands
  6. Select notify-host-by-pagerduty 
from the Hostcommands list.
  7. Click Add Selected.
  8. Click Close.

    Service Notifications Enabled: on
    Service Notification Timeperiod: 24×7
    Service Notification options: w,u,c,r
  9. Click on Manage Service Notification Commands
  10. Select notify-service-by-pagerduty 
 
from the Hostcommands list.
  11. Click Add Selected.
  12. Click Close.
  13. Under Misc Settings, click on Manage Variable Definitions
  14. Enter the following information:
    Variable name:

    pager

    Variable value:

    Enter your service API key

  15. Click Insert.
  16. Click Close.
  17. Click Save.
  18. Click Apply Configuration.

  19. Under Templates > Host Templates:
  20. Select linux-server
  21. Enter a Description.
  22. Click on Alert Settings and enter the following settings:
    Notification period: 24×7
    Notifictaion options: d,u,r
    Notification interval: 1 min
    Notification enabled: on
  23. Click on Manage Contactgroups
  24. Click on admins.
  25. Click Add Selected.
  26. Click Close.
  27. Click Save.
  28. Click on Apply Configuration.

You’ve now added PagerDuty notification to Nagios XI!

FAQ

Since Nagios XI needs my external Internet connection to send failure reports to PagerDuty, how will I receive notification if our site loses external connectivity?

You should configure an external ping check service such as StatusCake or NodePing to monitor your site’s external connectivity. Of course, you can use PagerDuty to forward alerts from these services.