How to Configure Nagios on a Raspberry

There are host templates and service templates. Host templates control settings for host objects and service templates control settings for service objects. A best practice is to set as many of the settings as possible via templates so changes are centralized later on down the road. A little foresight and planning can save hours.

Sample Nagios Host template

define host {
name webs
alias Template for rasp webs
hostgroups webservers
check_command check_http
max_check_attempts 3
check_interval 15
retry_interval 5
check_period 24x7
event_handler_enabled 1
flap_detection_enabled 1
process_perf_data 1
retain_status_information 1
retain_nonstatus_information 1
contact_groups admins
notification_interval 0
notification_period 24x7
first_notification_delay 15
notification_options d,r,
notifications_enabled 1
icon_image web.png
statusmap_image servers.png
register 0
}

After I’ve defined the host template I then define a host. But, because I’ve set so many things up already in the template, I only need to define a few things on my Host object.

define host {
host_name oneofthewebservers
use webs
address 10.10.10.23
parents servers
register 1
}

Notice I’m referencing the Host Template from within the Host object via the use variable. Any settings that are set on the Host, and the Template, will be overridden by the settings on the host itself. So if I define my check_interval on both the host (15) object and the template (5), the host objects settings will override the settings within the template, and the check_interval will be set to 15.

The same basic concept goes for services. The way I do it is to have a template for every type of host I’m going to configure. Routers get one template, servers get another template, and switches have their own host templates. The only things that I configure for the host objects themselves are name, IP, template, and parents. If you set things up like this, later on down the road you may have a few hundred devices of the same type you’re monitoring, and you want/need to change let’s say the check interval within Nagios for all those objects. If you’re using templates correctly, that can be as simple as making a single change on a template. 

RTFM

Templates have inheritance and this can be tricky. Read this.

One way to use inheritance is to use multiple templates to get granular in the settings. Perhaps you want to use one template for your host check intervals, and another for your alert settings.

Reference this doc for how the configuration files on the backend relate to each other. I’m including this because it can be a helpful doc to have on hand for reference.

Author: John

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.