A blog about servers and junk

Configuring Nagios Like a Boss!

I’m tired of configuring Nagios by hand. Just tired. I always forget to do stuff. I’ll add a new host, or stick in a raid card, add a new website, whatever, and forget to add a nagios check for it.

So it happened. You setup a server, put critical infrastructure on it, but forgot to monitor it. It goes down, bad stuff happens. Your boss asks, why weren’t we monitoring this? Let me supply a few options to prevent this from happening in the future:

Enforce draconian punishment for people who forget to do it (one cutoff finger per service check?)

Have strict workflows/bkms/procedures for doing things like adding a vhost, starting a server, etc that include a step for adding them to Nagios

Invent a fake sysadmin named Paco, and blame all the mistake on him.

Automate it with puppet. Then blame puppet when it goes wrong!

A Migration Plan

Let’s do it. Let’s make puppet do the work. After all, puppet is aware of my hosts, and it even knows what services are running them.

You don’t have to switch all at once, you can have a mix of automatically generated and manually configured checks. I like to put my automated definitions go into folders called hosts.d and services.d. Do what makes sense for your environment.

Howto

First, define a “virtual resource” wherever a service is defined. Lets take a really simple, but overlooked example of health-checking raid:

So what is going on here? In this class we define a Nagios plugin, and we copy it over. (I like making things that puppet copies over set to 555 as a reminder that I shouldn’t be editing them)

The virtual resource is “@@nagios_server”. The @@ means that the resource is just saved on the puppet master, and not instantiated on the client. (this assumes you have stored configs enabled in your puppet setup.)

With “target =>” I’m dumping the config into /etc/nagios/services.d/$fqdn-raid.cfg. It’s a good idea to let puppet put service definitions in separate files. Making puppet scan a single file chock full of definitions will be slow.

If this virtual resource is defined on a bunch of clients, on some nagios server we need to let puppet dump these files: