Adding Contacts to Nagios

Home Adding Contacts to Nagios
| by TheIneptOne | 1 comment

Adding Contacts to Nagios

Contacts are created in Nagios for email alerts. They can be setup for individual users or a distribution list. They can also be setup to alert at different times of the day and can send alerts based on severity of the issue.

If you don’t already have a Nagios server setup, you can follow my previous post here: Nagios 4.4.6 on Ubuntu 20.04

When editing a file with Nano, to save your changes to do the following:

  • Ctrl+X to Exit
  • Y to save the edits currently stored in the buffer
  • Enter to write to the current file name

Contact Creation

For my setup, contacts are stored in /opt/nagios/contacts. I keep a template file in the same directory called contact-template that can be used to easily add a new contact. The template file contains the following

define contact{
    contact_name                    [username]
    alias                           [full name]
    service_notification_period     24x7
    service_notification_options    w,c,r
    service_notification_commands   notify-service-by-email
    host_notification_period        24x7
    host_notification_options       d,r
    host_notification_commands      notify-host-by-email
    email                           [email address]
}

To use the template file, create a copy giving it the username of the contact

sudo cp contact-template username.cfg

Note: the file needs to end with .cfg. If the file does not have that extension, Nagios will not read and process it as a contact

Use Nano to edit the file and change the contact_namealias, and email

sudo nano username.cfg
define contact{
    contact_name                    inepttech
    alias                           Inept Tech
    service_notification_period     24x7
    service_notification_options    w,c,r
    service_notification_commands   notify-service-by-email
    host_notification_period        24x7
    host_notification_options       d,r
    host_notification_commands      notify-host-by-email
    email                           inept@domain.com
}

Save the changes by pressing Ctrl+XY for Yes, and Enter to select the file name to write (by default is the file we have opened)

Repeat this process for any additional contacts

Contact Group

Once the contact is created, the contact will need to be added to a contact group. Contact groups are used for ease of management when it comes to how notifications are sent for checks or commands

For my setup, contact groups are stored in a single contact-groups.cfg file located at /opt/nagios/groups

cd /opt/nagios/groups

Use Nano to edit the file

sudo nano contact-groups.cfg

Add the username to the members line. This line is comma separated

define contactgroup{
    contactgroup_name   network-admins
    alias Network       Administrators
    members             inepttech,anotheruser
}

Save the changes by pressing Ctrl+XY for Yes, and Enter to select the file name to write (by default is the file we have opened)

Checking and Restarting Nagios

Once the contact(s) have been created, we’ll need to do a sanity check to verify there are no errors in the files that were edit and then restart the Nagios service. If the sanity check is not ran and there are errors in the file, the Nagios service will fail to start.

The sanity check can be run with the following command

sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

As long as Total Warnings and Total Errors are both 0, we’re good to restart the service

To restart the nagios service, run the following command

sudo systemctl restart nagios.service

Typically you will not get any feedback upon successful restart. To verify the service is running, run the following command: (If necessary, type q to exit)

 

 

1 Comment

Nagios 4.4.6 on Ubuntu 20.04 – Inept Tech

February 1, 2022 at 11:13 pm Reply

[…] Adding Contacts to Nagios […]

Leave a Reply