{"id":318,"date":"2019-05-14T14:05:52","date_gmt":"2019-05-14T14:05:52","guid":{"rendered":"https:\/\/blog.iabsolute.com\/?p=318"},"modified":"2019-05-14T14:05:52","modified_gmt":"2019-05-14T21:05:52","slug":"define-nagios-contacts-with-email-and-pager-notification","status":"publish","type":"post","link":"https:\/\/blog.iabsolute.com\/?p=318","title":{"rendered":"Define Nagios Contacts With Email and Pager Notification"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">1. Define Generic Contact Template in templates.cfg<\/h3>\n\n\n\n<p>Nagios installation gives a default generic contact template that can be used as a reference to build your contacts. Please note that all the directives mentioned in the generic-contact template below are mandatory. So, if you\u2019ve decided not to use the generic-contact template definition in your contacts, you should define all these mandatory definitions inside your contacts yourself.<br>\n<br>\nThe following generic-contact is already available under \/usr\/local\/nagios\/etc\/objects\/templates.cfg. Also, the templates.cfg is included in the nagios.cfg by default as shown below.<br>\n<br>\nPlease note that any of these directives mentioned in the templates.cfg can be overridden when you define a real contact using this generic-template.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># grep templates \/usr\/local\/nagios\/etc\/nagios.cfg\ncfg_file=\/usr\/local\/nagios\/etc\/objects\/templates.cfg\n\n<strong>Note<\/strong>: generic-contact is available under\n      \/usr\/local\/nagios\/etc\/objects\/templates.cfg\n\ndefine contact{\n        name                            generic-contact\n        service_notification_period     24x7\n        host_notification_period        24x7\n        service_notification_options    w,u,c,r,f,s\n        host_notification_options       d,u,r,f,s\n        service_notification_commands   notify-service-by-email\n        host_notification_commands      notify-host-by-email\n        register                        0\n        }<\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Name <\/strong>&#8211; This defines the name of the contact template (generic-contact).<\/li><li><strong>service_notification_period<\/strong> \u2013 This defines when nagios can send notification about services issues (for example, Apache down). By default this is 24\u00d77 timeperiod, which is defined under \/usr\/local\/nagios\/etc\/objects\/timeperiods.cfg<\/li><li><strong>host_notification_period<\/strong> \u2013 This defines when nagios can send notification about host issues (for example, server crashed). By default, this is 24\u00d77 timeperiod.<\/li><li><strong>service_notification_options<\/strong> \u2013 This defines the type of service notification that can be sent out. By default this defines all possible service states including flapping events. This also includes the scheduled service downtime activities.<\/li><li><strong>host_notification_options<\/strong> \u2013 This defines the type of host notifications that can be sent out. By default this defines all possible host states including flapping events. This also includes the scheduled host downtime activities.<\/li><li><strong>service_notification_commands<\/strong> \u2013 By default this defines that the contact should get notification about service issues (for example, database down) via email. You can also define additional commands and add it to this directive. For example, you can define your own notify-service-by-sms command.<\/li><li><strong>host_notification_commands<\/strong> \u2013 By default this defines that the contact should get notification about host issues (for example, host down) via email. You can also define additional commands and add it to this directive. For example, you can define your own notify-host-by-sms command.<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. Define Individual Contacts in contacts.cfg<\/h3>\n\n\n\n<p>One you\u2019ve confirmed that the generic-contact templates is defined properly, you can start defining individual contacts definition for all the people in your organization who would ever receive any notifications from nagios. Please note that just by defining a contact doesn\u2019t mean that they\u2019ll get notification. Later you have to associate this contact to either a service or host definition as shown in the later sections below. So, feel free to define all possible contacts here. (for example, Developers, DBAs, Sysadmins, IT-Manager, Customer Service Manager, Top Management etc.)<br>\n<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Note:<\/strong> Define these contacts in \/usr\/local\/nagios\/etc\/objects\/contacts.cfg\ndefine contact{\n        contact_name                    sgupta\n        use                             generic-contact\n        alias                           Sanjay Gupta (Developer)\n        email                           sgupta@thegeekstuff.com\n        pager                           333-333@pager.thegeekstuff.com\n        }\ndefine contact{\n        contact_name                    jbourne\n        use                             generic-contact\n        alias                           Jason Bourne (Sysadmin)\n        email                           jbourne@thegeekstuff.com\n        }<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. Define Contact Groups with Multiple Contacts in contacts.cfg<\/h3>\n\n\n\n<p>Once you\u2019ve defined the individual contacts, you can also group them together to send the appropriate notifications. For example, only DBAs needs to be notified about the database down service definition. So, a db-admins group may be required. Also, may be only Unix system administrators needs to be notified when Apache goes down. So, a unix-admins group may be required. Feel free to define as many groups as you think is required. Later you can use these groups in the individual service and host definitions.<br>\n<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Note<\/strong>: Define contact groups in \/usr\/local\/nagios\/etc\/objects\/contacts.cfg\n\ndefine contactgroup{\n<strong>contactgroup_name          db-admins\n<\/strong>alias                      Database Administrators\nmembers                    jsmith, jdoe, mraj\n}\n\ndefine contactgroup{\n<strong>contactgroup_name          unix-admins<\/strong>\nalias                      Linux System Administrator\nmembers                    jbourne, dpatel, mshankar\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4. Attach Contact Groups or Individual Contacts to Service and Host Definitions<\/h3>\n\n\n\n<p>Once you\u2019ve defined the individual contacts and contact groups, it is time to start attaching them to a specific host or service definition as shown below.<br>\n<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Note<\/strong>: Following host is defined under\n     \/usr\/local\/nagios\/etc\/objects\/servers\/email-server.cfg.\n     This can be any host definition file.\n\ndefine host{\nuse                     linux-server\nhost_name               email-server\nalias                   Corporate Email Server\naddress                 192.168.1.14\n<strong>contact_groups          unix-admins<\/strong>\n}\n\n<strong>Note<\/strong>: Following is defined under\n      \/usr\/local\/nagios\/etc\/objects\/servers\/db-server.cfg.\n      This can be any host definition file.\n\ndefine service{\nuse&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; generic-service\nhost_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; prod-db\nservice_description&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CPU Load\n<strong>contact_groups&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unix-admins<\/strong>\ncheck_command&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; check_nrpe!check_load\n}\n\ndefine service{\nuse&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; generic-service\nhost_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; prod-db\nservice_description&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MySQL Database Status\n<strong>contact_groups&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db-admins<\/strong>\ncheck_command&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; check_mysql_db\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1. Define Generic Contact Template in templates.cfg Nagios installation gives a default generic contact template that can be used as a reference to build your contacts. Please note that all the directives mentioned in the generic-contact template below are mandatory. &hellip; <a href=\"https:\/\/blog.iabsolute.com\/?p=318\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-318","post","type-post","status-publish","format-standard","hentry","category-nagios"],"_links":{"self":[{"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=\/wp\/v2\/posts\/318","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=318"}],"version-history":[{"count":1,"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=\/wp\/v2\/posts\/318\/revisions"}],"predecessor-version":[{"id":319,"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=\/wp\/v2\/posts\/318\/revisions\/319"}],"wp:attachment":[{"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.iabsolute.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}