Start Using PagerDuty Today
Try PagerDuty free for 14 days — no credit card required.
Nagios is one of the leading providers of open source and enterprise-grade IT infrastructure monitoring tools. Used by hundreds of thousands of users worldwide, Nagios allows it’s users to monitor their entire IT infrastructure, spot problems before they occur, detect security breaches and plan/budget for IT upgrades.
By integrating PagerDuty into your existing Nagios monitoring solution, you can have Nagios alerts go directly to the the person on-call in your PagerDuty schedule.
The guide below describes how to integrate your Nagios 2, 3 or 4 installation with PagerDuty using a simple Perl-based plugin. Note that you must be logged in as root
to complete the installation. You might need to slightly alter these instructions depending on your exact Linux distribution, Nagios configuration and Nagios version. Please contact our support team if you have any trouble completing the integration.
Note: This guide has been replaced by the Nagios Two-Way Integration Guide that uses the PagerDuty Agent. Please try following the steps in the new integration guide first, and use this one only if you have a system which the PagerDuty Agent can not be installed on. Also be aware that the two-way integration script from the new integration guide can not be used with the Perl-based integration as-is; the two-way integration is only supported when using the new integration.
This guide includes steps for Debian-based (i.e. Ubuntu) and RHEL-based (i.e. CentOS, Fedora) Linux distributions. You do not need to execute all commands in this guide, only the ones for your type of system. Note that all commands provided are intended to be run as the root
user.
apt-get install libwww-perl libcrypt-ssleay-perl
For RHEL-based systems:
yum install perl-libwww-perl perl-Crypt-SSLeay
pagerduty_nagios.cfg
from GitHub:
wget https://raw.github.com/PagerDuty/pagerduty-nagios-pl/master/pagerduty_nagios.cfg
pagerduty_nagios.cfg
in a text editor.pager
field. The key is a 32-character string that can be found on the service’s detail page (step 3 in the PagerDuty section above).If you’re using Nagios 4: Slight modifications are needed for the commands specified in pagerduty_nagios.cfg
as shown below. Do not make these changes if you are using Nagios 2 or 3.
define command { 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$" -f HOSTDISPLAYNAME="$HOSTDISPLAYNAME$" -f SERVICEDISPLAYNAME="$SERVICEDISPLAYNAME$" -f SERVICEPROBLEMID="$SERVICEPROBLEMID$" } define 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$" -f HOSTDISPLAYNAME="$HOSTDISPLAYNAME$" -f HOSTPROBLEMID="$HOSTPROBLEMID$" }
/etc/nagios3/conf.d
:
cp pagerduty_nagios.cfg /etc/nagios3/conf.d
For RHEL-based systems this is usually /etc/nagios
:
cp pagerduty_nagios.cfg /etc/nagios
/etc/nagios/nagios.cfg
and add this line to the file:
cfg_file=/etc/nagios/pagerduty_nagios.cfg
/etc/nagios3/conf.d/contacts_nagios2.cfg
(for Debian-based systems) or /etc/nagios/localhost.cfg
(for RHEL-based systems) and look for the “admins” contact group. Then, simply add the “pagerduty” contact.
define contactgroup{ contactgroup_name admins alias Nagios Administrators members root,pagerduty ; Add pagerduty here }
pagerduty_nagios.pl
from GitHub and copy it to /usr/local/bin
.
wget https://raw.github.com/PagerDuty/pagerduty-nagios-pl/master/pagerduty_nagios.pl cp pagerduty_nagios.pl /usr/local/bin
chmod 755 /usr/local/bin/pagerduty_nagios.pl
/etc/nagios3/nagios.cfg
(for Debian-based systems) or /etc/nagios/nagios.cfg
(for RHEL-based systems):
enable_environment_macros=1
This step is required. The integration will not work if you do not have environment macros enabled.
nagios
user’s cron table:
crontab -u nagios -e
* * * * * /usr/local/bin/pagerduty_nagios.pl flush
/etc/init.d/nagios3 restart
For RHEL-based systems:
service nagios restart
This integration uses a Perl script which is compatible with older Linux distributions than the newer agent-based integration, however it lacks the two-way functionality of the new integration. You can not use the two-way script from the agent-based integration with the Perl script as-is; the two-way integration is only supported when using the new integration. For this reason, we recommend using the agent-based integration unless you are using a system which the agent is not compatible with (i.e. CentOS 5).
The Perl script works by adding events received from Nagios to a queue at /tmp/pagerduty_nagios
. The script tries to flush the queue (send events to PagerDuty) immediately after receiving them from Nagios. If the script is unable to reach PagerDuty for any reason (i.e. due to connectivity issues), events are kept in the queue. The cron job exists to retry flushing the queue if there’s anything that hasn’t been sent.
The script has a few options you can set when executing it, including the ability to change the directory used for the queue or to set a proxy. The options are documented in the script. Note that you must set any options in both of the commands defined in your Nagios configuration as well as the cron job.
Tip: If you run in to issues with the integration and accumulate several events in the queue that you do not want to be sent to PagerDuty, simply remove the event files in /tmp/pagerduty_nagios
to prevent them from being sent when the script is able to send alerts to PagerDuty successfully.
This is easy to do with the current integration, as a Nagios service in PagerDuty is directly mapped to a “contact” in Nagios. By default, this contact is named pagerduty
and defined in the pagerduty_nagios.cfg
file. In order to configure multiple services, just duplicate the existing contact definition and rename it (i.e. pagerduty_database
, pagerduty_network
, etc.). Then copy and paste the corresponding Integration Key from PagerDuty into the pager
field. Don’t forget to restart your Nagios for the changes to take effect.
If a PagerDuty server can’t be reached for any reason, events will be stored to an on-disk queue. The cron job will attempt to re-send the events once every minute.
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 as well.
First, check syslog for messages containing pagerduty_nagios
.
For Debian-based systems:
grep pagerduty_nagios /var/log/syslog
For RHEL-based systems:
grep pagerduty_nagios /var/log/messages
More troubleshooting tips can be found in our Nagios Troubleshooting Guide.
PagerDuty can process PROBLEM
, ACKNOWLEDGEMENT
, and RECOVERY
messages. All other messages, including FLAPPINGSTART
and FLAPPINGSTOP
, are ignored.
We have a guide for Customizing Notifications Sent to PagerDuty from Nagios to help you get started.
Try PagerDuty free for 14 days — no credit card required.