In diesem Artikel geht es um die Implementierung einer Scan-Automatik für Icinga. Dies dient zum einen dazu, Server, Workstations und andere Geräte nicht alle von Hand anlegen zu müssen, zum anderen hat man bei dieser Inventur auch die Chance Geräte ausfindig zu machen, die eigentlich nichts im Intranet zu suchen haben.
Man kann das Perl Script wie üblich von monitoringexchange.org beziehen.
Installation
1 2 3 4 5 6 7 8 | # herunterladen wget http://www.monitoringexchange.org/attachment/download/Utilities/AddOn-Projects/Configuration/nmap2nagios-ng/nmap2nagios_ng.rar # entpacken ins plugin Verzeichnis tar xvfz nmap2nagios-ng.tar -C /usr/local/icinga/libexec # nmap und xml Bibliothek für perl installieren aptitude install nmap libxml-simple-perl |
Aufruf von nmap
Mit Hilfe von nmap wird das Netzwerk oder wahlweise nur ein Host nach offenen Ports gescannt und das Ergebnis in eine xml Datei geschrieben.
nmap für einen Node:
# nmap -sS -O -oX 192.168.100.1.xml 192.168.100.1nmap für ein subnet:
# nmap -sS -O -oX subnet.xml 192.168.1.0/24Aufruf von nmap2nagios-ng
Jetzt wird die xml Datei eine Konfigurationsdatei für Nagios konvertiert.
# ./nmap2nagios-ng.pl -i -e -r subnet.xml -o newhosts.cfgWeitere Parameter von namp2nagios-ng
# icinga1:/usr/local/icinga/libexec/nmap2nagios-ng# ./nmap2nagios-ng.pl -h nmap2nagios-ng.pl: -v -i -z||d -r {'nmap_results_file'} -o {'output_file'} -i Ignore Unknown Services -v Verbose -V Serious Verbose -z Nagios Version 2.x -d Nagios Version 3.x -e Icinga Version 1.x -h This screen
Einbindung in Icinga
Jetzt muss die newhost.cfg nur noch in das entsprechende Konfigurationsverzeichnis kopiert werden hier /etc/icinga
Binde die Datei in icinga.cfg ein
1 | cfg_file=/etc/icinga/newhosts.cfg |
Lade die Icinga config neu:
# /etc/init.d/icinga reloadTips:
In der Datei nmap2nagios-ng_3x.conf kann man die Erstellung der .cfg Datei anpassen. Man sollte auf jeden Fall die Default Domain ändern.
Bei mir hat noch das Plugin check_dig gefehlt. Auch dieses kann man hier auf monitoringexchange.org herunterladen. Anschließend entpacken und ab ins libexec Verzeichnis. Natürlich muss man noch die commands.cfg erweitern.
1 2 3 4 5 6 7 | # nano /etc/icinga/objects/commands.cfg
# 'check_dig' command definition
define command {
command_name check_dig
command_line $USER1$/check_dig -H $HOSTADDRESS$ -l $ARG1$
} |