Retrospective IT

Install Nagios 4 on Ubuntu 16.04 LTS – Part Two

Install Nagios 4 on Ubuntu 16.04 LTS - Part 2

I spent a lot of time over the past few months learning Nagios inside and out so I could monitor our infrastructure of close to 200 servers across 75+ locations. Since learning how to install and use Nagios can be daunting and intimidating to new Nagios users, I wanted to document my setup in hopes of helping others out. Please note that some of these settings are based on person preference and can be changed.

This post is part two of a four part series and will utilize Nagios version 4.2.1, Nagios Plugins version 2.13, and the NCPA client (latest versions at the time of writing).

If you haven’t already, check out Part One.

This post assumes the following:

  • A base install of Ubuntu 16.04 LTS with a static IP address
  • This post assumes you are root (i.e. sudo su – )
  • This post assumes you have Nagios installed according to part one of this series.

Configuring Contacts

Contacts and Contact Groups are created for notification purposes. Contacts can be created for certain time periods, hosts/hostgroups, services, and type of notifications. The following notification types for Hosts are available:

  • D – notify when Down
  • U – notify when Unreachable
  • R – notify when Recovered (UP)
  • F – notify when host is Flapping
  • S – notify when Scheduled Downtime ends or begins

The following notification types for Services are available:

  • W – notify when Warning
  • U – notify when Unknown
  • C – notify when Critical
  • R – notify when Recovered (OK)
  • F – notify when host is Flapping
  • N – no service notifications

Contact Groups

A contact group is used to group one or more contacts together for notifications. For more info, check out the Nagios documentation.

Create a file called contactgroups.cfg to allow grouping of contacts

nano /usr/local/nagios/etc/contacts/contractgroups.cfg

To define a contact group, use the following template

define contactgroup{
    contactgroup_name                  network-admins
    alias                              Network Administrators
    members                            user1,user2,user3
}

I then create a cfg file for each member. For user1, create a user1.cfg file and use the following template.

define contact{
    contact_name                       user1
    alias                              Full Name
    service_notification_period        24x7
    service_notification_options       w,u,c,r
    service_notification_commands      notify-service-by-email
    host_notification_period           24x7
    host_notification_options          d,u,r
    host_notification_commands         notify-host-by-email
    email                              [email protected]
}

Once you have your contacts configured, you’ll be able to add them to services and hosts; which will be covered later on.

Configuring Time Periods

Time Periods allow you to set when a contact or contact group will receive alerts. It can be set for any time of the day and exclude days such as holidays and weekends. By default, Nagios is setup with time periods with the following names:

  • 24×7 – Alerts are sent out all hours, every day of the week
  • workhours – Alerts are sent out between 9:00AM and 5:00PM
  • none – Alerts will not be sent
  • us-holidays – Alerts are sent out all hours, every day except New Years, Memorial, July 4th, Labor Day, Thanksgiving, and Christmas

This file is located at /usr/local/Nagios/etc/objects/timeperiods.cfg and can be adjusted as needed. Time Periods are used in the following configs:

  • contactgroups – service/host_notifiation_period
  • hostsgroups – check_period
  • services – check_period and notification_period

I used the workhours time period as a template and create a new time period cfg called duringwork.cfg. I adjusted the times to 7:00AM – 6:00PM M/F with no alerts on the weekends and holidays.

In the next series, we’ll create templates, hosts, and hostgroups.

Install Nagios 4 on Ubuntu 16.04 LTS – Part One
Install Nagios 4 on Ubuntu 16.04 LTS – Part Two
Install Nagios 4 on Ubuntu 16.04 LTS – Part Three
Install Nagios 4 on Ubuntu 16.04 LTS – Part Four

Leave a Reply

Your email address will not be published. Required fields are marked *