ntERLab at AIT: Network Management WorkshopPart 1: Create a a Nagios Plug-in | |
Part 1Create a Nagios Plug-inWe want to create a plug-in for Nagios using a shell script. The shell script is going to do the following:
In order to create a plug-in for Nagios there are several steps you must take. These are (not necessarily in any order):
To start here is the service definition for our plug-in. We will call our plug-in "check_internet": Place this in the file /etc/nagios2/conf.d/localhost_nagios2.cfg:
# Define a new service...
define service {
use generic-service
host_name localhost
service_description External Host Group Check
check_command check_internet!eu.org!yahoo.com!x0.dk!google.com!microsoft.com
}
Notice the machines we have defined. You can define any other set of machines you want. The way our plug-in will be defined you will be able to check up to 5 hosts. This is completely arbitrary to make our exercise easier to do. If you wanted you could define the configuration for your new plug-in so that a single argument is passed, and then you can use the "for i" clause to parse each item on the command line for the script. If you are interested here is an example from the Nagios documenation:http://nagios.sourceforge.net/docs/2_0/eventhandlers.html To start let's describe a script in more detail. We want you to do the following:
Part 2Set Up Nagios Notification for our New Plug-inNow that we have a new plug-in let's set up Nagios to send an email to an account of your specification if the new plug-in generates an alert. That is, if 2, or more, machines are down, then someone needs to be notified. To do this you need to do the following in Nagios:
Once the contactgroup has been created, then you need to define that this contactgroup will receive notifications for processes being monitored on or by localhost. You do this by editing the file /etc/nagios2/conf.d/localhost_nagios2.cfg and updating the "host" section of the file at the top. Once you do this be sure to reload the Nagios process by doing:# /etc/init.d/nagios2 stop Part 3Update Our Plug-in for any Number of HostsUpdate your script and the check_internet plug-in configuration to allow for any number of hosts to be specified for checking. This means that you need to change the following two files:
The script needs to use the "for i in", or just "for i" construct to parse the values on the command line and then act on each. You can find an example of this here: http://tldp.org/LDP/abs/html/loops1.html
|