Autocreating Nagios Configuration with Nmap and Nmap2Nagios.pl
From Nagios Wiki
Contents |
[edit] Purpose
This HOWTO will show users how to use CentOS 4, nmap, and nmap2nagops.pl to autocreate config files. We will first build the necessary components of the LAMP stack (perl modules, in this case), then we install and run nmap. The nmap2nagios.pl script will then convert the XML file generated by nmap to Nagios-friendly cfg files that will be called in our main nagios.cfg file. If nmap checks are carefully thought out, this approach can save a lot of time.
Caveat: nmap2nagios converts to Nagios 1.x files, and if you're using later versions of Nagios, then you should pay special note to the troubleshooting tips at the end of this HOWTO.
[edit] CentOS Requirements
yum install nmap nagios-* perl-XML-Simple perl-XML-SAX
[edit] NMap
[edit] Nmap2Nagios
[edit] Installing Nmap2Nagios
cd /tmp wget http://easynews.dl.sourceforge.net/sourceforge/nmap2nagios/nmap2nagios-0.1.2.tar.gz tar zxfv nmap2nagios-0.1.2.tar.gz cd nmap2nagios-0.1.2 vim nmap2nagios.pl
optional: on CentOS, change
##!/usr/local/bin/perl -w
to
#/usr/bin/perl
(type in "perldoc nmap2nagios.pl" for more information on how to use program)
[edit] Nmap2Nagios Examples
[edit] Comprehensive Service Checks
e.g. map out 10net block, make Nagios configs for it
nmap -sS -O -oX /tmp/nmap.xml 10.1.1.0/24 -v -v perl nmap2nagios.pl -v -r /tmp/10net.xml -o /etc/nagios/10net.cfg
add following line to nagios.cfg
cfg_file=/etc/nagios/10net.cfg
[edit] Quick Host Checks
only make ping checks for hosts that reply with ICMP traffic
nmap -sP -oX /tmp/test.xml 10.1.1.0/24 -v -v perl nmap2nagios.pl -v -r /tmp/pingable-hosts.xml -o /etc/nagios/pingable-hosts.cfg
add following line to nagios.cfg
cfg_file=/etc/nagios/pingable-hosts.cfg
[edit] Troubleshooting / Known Issues
Once you create the cfg files and add the appropriate cfg_file=/path/to/file.cfg entry to nagios.cfg, you will notice quite a few errors. Most (if not all) of these are due to the the fact that the script was developed for Nagios 1.x. If you have problems, try some of the following tips:
- change contact_groups from "admin" to "admins". "admins" might be your default group in localhosts.cfg.
- define contact_groups in the host definition, rather than the hostgroup definition.
- edit out address (address -> #address)

