{"id":42026,"date":"2016-12-21T17:38:03","date_gmt":"2016-12-21T12:08:03","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=42026"},"modified":"2016-12-22T13:45:34","modified_gmt":"2016-12-22T08:15:34","slug":"how-to-integrate-nagios-with-pagerduty","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/how-to-integrate-nagios-with-pagerduty\/","title":{"rendered":"How to Integrate Nagios with PagerDuty"},"content":{"rendered":"<p><a title=\"Getting started with Nagios\" href=\"http:\/\/www.tothenew.com\/blog\/getting-started-with-nagios\/\">Nagios<\/a> is an open-source <a title=\"DevOps Tools\" href=\"http:\/\/www.tothenew.com\/devops-chef-puppet-docker\">infrastructure monitoring tool<\/a>. It monitors your Hosts &amp; Services that are defined\u00a0and\u00a0alerts you if any of the hosts or services go down by the different alert mechanism like email, SMS, etc.<\/p>\n<p>PagerDuty\u00a0is an enterprise incident resolution service that gives you an\u00a0alert on email, SMS &amp; call. By integrating PagerDuty\u00a0with Nagios\u00a0you can get an\u00a0alert on call and can resolve or escalate it to the next level from the call directly.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-42780\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/download-300x57.png\" alt=\"download\" width=\"437\" height=\"83\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/download-300x57.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/download.png 513w\" sizes=\"(max-width: 437px) 100vw, 437px\" \/>\u00a0 \u00a0 \u00a0\u00a0<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-42781\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/Nagios-Logo-300x88.jpg\" alt=\"Nagios-Logo\" width=\"300\" height=\"88\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/Nagios-Logo-300x88.jpg 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/Nagios-Logo.jpg 555w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>Steps to integrate\u00a0PagerDuty with Nagios:<\/p>\n<p>1. Create a new service or edit existing service in your PagerDuty account.<\/p>\n<p>2. Add an Integration policy and select Nagios as an Integration\u00a0Type.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-42027 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/Screen-Shot-2016-11-06-at-8.13.30-PM.png\" alt=\"Integrating Nagios with PagerDuty\" width=\"2537\" height=\"966\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/Screen-Shot-2016-11-06-at-8.13.30-PM.png 2537w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/Screen-Shot-2016-11-06-at-8.13.30-PM-300x114.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/Screen-Shot-2016-11-06-at-8.13.30-PM-1024x389.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/Screen-Shot-2016-11-06-at-8.13.30-PM-624x237.png 624w\" sizes=\"(max-width: 2537px) 100vw, 2537px\" \/><\/p>\n<p>3. Copy your integration key to configure alerts in Nagios server.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-42029 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/Screen-Shot-2016-11-06-at-8.32.21-PM.png\" alt=\"Integrate Nagios with PagerDuty\" width=\"2010\" height=\"724\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/Screen-Shot-2016-11-06-at-8.32.21-PM.png 2010w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/Screen-Shot-2016-11-06-at-8.32.21-PM-300x108.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/Screen-Shot-2016-11-06-at-8.32.21-PM-1024x368.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/Screen-Shot-2016-11-06-at-8.32.21-PM-624x224.png 624w\" sizes=\"(max-width: 2010px) 100vw, 2010px\" \/><\/p>\n<p>4. Install PagerDuty on your Nagios Server:<\/p>\n<p>[code]<br \/>\nwget -O &#8211; https:\/\/packages.pagerduty.com\/GPG-KEY-pagerduty | sudo apt-key add &#8211;<br \/>\nsudo sh -c &#8216;echo &amp;quot;deb  deb\/&amp;quot; &amp;gt; \/etc\/apt\/sources.list.d\/pdagent.list&#8217;<br \/>\nsudo apt-get update<br \/>\nsudo apt-get install pdagent pdagent-integrations<br \/>\n[\/code]<\/p>\n<p>5. Create a new contact group on your Nagios server and add the code below. Enter your PagerDuty integration key that you copied in step 3, at the place of PAGERDUTY-SERVICE-KEY.<\/p>\n<p>[code]<br \/>\ndefine contact {<br \/>\ncontact_name pagerduty<br \/>\nalias PagerDuty<br \/>\nContact service_notification_period 24&#215;7<br \/>\nhost_notification_period 24&#215;7<br \/>\nservice_notification_options w,u,c,r<br \/>\nhost_notification_options d,r<br \/>\nservice_notification_commands notify-service-by-pagerduty<br \/>\nhost_notification_commands notify-host-by-pagerduty<br \/>\npager PAGERDUTY-SERVICE-KEY<br \/>\n}[\/code]<\/p>\n<p>6. Create a new command file or edit the existing command file and add the below code to it. If you are not creating a new command file in your Nagios config directory, you need to add the complete path of your command file in the Nagios main config file and restart the Nagios service.<\/p>\n<p>[code]define command {<br \/>\ncommand_name notify-service-by-pagerduty<br \/>\ncommand_line \/usr\/share\/pdagent-integrations\/bin\/pd-nagios -n service -k $CONTACTPAGER$ -t &amp;quot;$NOTIFICATIONTYPE$&amp;quot; -f SERVICEDESC=&amp;quot;$SERVICEDESC$&amp;quot; -f SERVICESTATE=&amp;quot;$SERVICESTATE$&amp;quot; -f HOSTNAME=&amp;quot;$HOSTNAME$&amp;quot; -f HOSTDISPLAYNAME=&amp;quot;$HOSTDISPLAYNAME$&amp;quot; -f SERVICEDISPLAYNAME=&amp;quot;$SERVICEDISPLAYNAME$&amp;quot; -f SERVICEPROBLEMID=&amp;quot;$SERVICEPROBLEMID$&amp;quot; -f SERVICEOUTPUT=&amp;quot;$SERVICEOUTPUT$&amp;quot;<br \/>\n}<br \/>\ndefine command {<br \/>\ncommand_name notify-host-by-pagerduty<br \/>\ncommand_line \/usr\/share\/pdagent-integrations\/bin\/pd-nagios -n host -k $CONTACTPAGER$ -t &amp;quot;$NOTIFICATIONTYPE$&amp;quot; -f HOSTNAME=&amp;quot;$HOSTNAME$&amp;quot; -f HOSTSTATE=&amp;quot;$HOSTSTATE$&amp;quot; -f HOSTDISPLAYNAME=&amp;quot;$HOSTDISPLAYNAME$&amp;quot; -f HOSTPROBLEMID=&amp;quot;$HOSTPROBLEMID$&amp;quot;<br \/>\n}[\/code]<\/p>\n<p>7. Add &#8216;Pagerduty&#8217; user which you have created in step 5, in the main contact group that you are using to send alerts. \u00a0By default\u00a0Nagios uses &#8216;\/etc\/nagios3\/conf.d\/contacts_nagios2.cfg&#8217; file and uses the admin contact group.<\/p>\n<p>[code]define contactgroup{<br \/>\n     contactgroup_name admins<br \/>\n     alias Nagios Administrators<br \/>\n     members root,pagerduty    \/\/ Adding PagerDuty User<br \/>\n}[\/code]<\/p>\n<p>8. Restart your Nagios service and you will start getting alerts if any host or service goes down.<\/p>\n<p><strong>TroubleShooting:<\/strong><\/p>\n<p>1. You can check your PagerDuty Agent status running on your Nagios\u00a0server and stop\/start\/restart it too.<\/p>\n<p>[code]sudo service pdagent status \/\/ Check Agent Status<br \/>\nsudo service pdagent restart  \/\/ Restart Agent[\/code]<\/p>\n<p>2. Send events manually on PagerDuty to check your integration key.<\/p>\n<p>[code]pd-send -k PD_SERVICE_KEY -t trigger -d &amp;quot;Service Description&amp;quot;<br \/>\npd-send &#8211;help    \/\/ for more help[\/code]<\/p>\n<p>3. Check your Agent queue status by using below command.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-42168 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/Screen-Shot-2016-11-09-at-2.45.41-PM.png\" alt=\"Integrate Nagios with PagerDuty\" width=\"994\" height=\"160\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/Screen-Shot-2016-11-09-at-2.45.41-PM.png 994w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/Screen-Shot-2016-11-09-at-2.45.41-PM-300x48.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/Screen-Shot-2016-11-09-at-2.45.41-PM-624x100.png 624w\" sizes=\"(max-width: 994px) 100vw, 994px\" \/><\/p>\n<p>If you have configured multiple keys on your Nagios server, it will show you multiple entries against each key.<\/p>\n<p>4. To send error events again you can use retry command as below.<\/p>\n<p>[js]pd-queue retry -k YOUR-PAGERDUTY-KEY   \/\/ retry givens key&#8217;s alert<br \/>\npd-queue retry -a                      \/\/ retry all keys&#8217; alert[\/js]<\/p>\n<p>By following the above steps, you can use both the services as per your use case. Here is another blog giving\u00a0some useful configuration <a title=\"Tips for configuring Nagios\" href=\"http:\/\/www.tothenew.com\/blog\/tips-for-configuring-nagios-wildcards-and-cfg-dir\/\">tips for configuring Nagios monitoring system<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Nagios is an open-source infrastructure monitoring tool. It monitors your Hosts &amp; Services that are defined\u00a0and\u00a0alerts you if any of the hosts or services go down by the different alert mechanism like email, SMS, etc. PagerDuty\u00a0is an enterprise incident resolution service that gives you an\u00a0alert on email, SMS &amp; call. By integrating PagerDuty\u00a0with Nagios\u00a0you can [&hellip;]<\/p>\n","protected":false},"author":678,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":34},"categories":[1174,2348,1],"tags":[4315,4316,1500,4314,4313],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/42026"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/678"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=42026"}],"version-history":[{"count":1,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/42026\/revisions"}],"predecessor-version":[{"id":53733,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/42026\/revisions\/53733"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=42026"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=42026"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=42026"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}