Hier werden die Unterschiede zwischen zwei Versionen gezeigt.
— |
computer:ipcop:nrpe_kompilieren [2017/12/23 12:25] (aktuell) christian angelegt |
||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
+ | ======Vorwort und Voraussetzungen====== | ||
+ | <note>Dieser Artikel stellt ein "//Kochrezept//" für mein fenrtiges IPCop-Plugin **nrpe** (//[[http://ipcop.stankowic-development.net]]//) dar</note> | ||
+ | Mithilfe von NRPE kann ein Host über ein Nagios/Icinga Monitoringsystem bezüglich System-/Status-Veränderungen befragt werden. | ||
+ | |||
+ | Benötigt wird: | ||
+ | * IPCop-Entwicklungssystem, idealerweise über das folgende Abbild installiert: [[http://it-connect-unix.de/index.php?option=com_jdownloads&view=viewcategory&catid=18&Itemid=78]] | ||
+ | * Quellcode der NRPE-Plugins bzw. Monitoring-Plugins: [[https://www.monitoring-plugins.org]] | ||
+ | * Quellcode von **nrpe**: [[http://sourceforge.net/projects/nagios/files/nrpe-3.x/]] | ||
+ | |||
+ | ======Monitoring-Plugins====== | ||
+ | Die Monitoring-Plugins werden heruntergeladen und auf dem Entwicklungssystem entpackt. Anschließend wird die Übersetzung wie folgt vorgenommen: | ||
+ | <code> | ||
+ | # ./configure --prefix=/var/ipcop/addons/nrpe --disable-nls --libexecdir=/var/ipcop/addons/nrpe/plugins --with-nagios-user=nagios --with-nagios-group=nagios | ||
+ | # make | ||
+ | # make install | ||
+ | # rm -rf /var/ipcop/addons/nrpe/include | ||
+ | </code> | ||
+ | |||
+ | ======NRPE====== | ||
+ | Zur Übersetzung von NRPE wird der Quellcode von der Projektseite bezogen und ebenfalls auf dem Entwicklungssystem entpackt. Anschließend erfolgt in bereits bekannter Manier das gleiche Übersetzungsprocedere: | ||
+ | <code> | ||
+ | # ./configure --prefix=/var/ipcop/addons/nrpe --sysconfdir=/var/ipcop/addons/nrpe --bindir=/var/ipcop/addons/nrpe --with-nagios-user=nagios --with-nagios-group=nagios --disable-nls --enable-command-args | ||
+ | # make nrpe | ||
+ | </code> | ||
+ | |||
+ | Anschließend muss der ``nagios`` Systembenutzer erstellt werden, bevor der Dienst installiert werden kann: | ||
+ | <code> | ||
+ | # useradd -d /dev/null -M -r -s /bin/false nagios | ||
+ | # make install-daemon | ||
+ | </code> | ||
+ | |||
+ | Darüber hinaus ist es ratsam eine Beispielkonfiguration in der Datei ``/var/ipcop/addons/nrpe/nrpe.cfg`` zu definieren. Diese sollte neben Benutzernamen/-gruppen auch einige andere wichtige Parameter und auch Standard-Plugins enthalten: | ||
+ | <code> | ||
+ | #IPCop NRPE example config | ||
+ | log_facility=daemon | ||
+ | pid_file=/var/run/nrpe.pid | ||
+ | nrpe_user=nagios | ||
+ | nrpe_group=nagios | ||
+ | |||
+ | #nrpe port - feel free to change port to enhance security | ||
+ | server_port=5666 | ||
+ | |||
+ | #specify server address to listen to | ||
+ | #server_address=192.168.1.1 | ||
+ | |||
+ | #specify hosts which are allowed to talk to us | ||
+ | allowed_hosts=127.0.0.1 | ||
+ | |||
+ | #set to 1 if you want to pass args (which IS a security risk!) | ||
+ | dont_blame_nrpe=0 | ||
+ | |||
+ | #debug and timeouts | ||
+ | debug=0 | ||
+ | command_timeout=60 | ||
+ | connection_timeout=300 | ||
+ | |||
+ | #some plugins | ||
+ | command[check_users]=/var/ipcop/addons/nrpe/plugins/check_users -w 5 -c 10 | ||
+ | command[check_load]=/var/ipcop/addons/nrpe/plugins/check_load -w 15,10,5 -c 30,25,20 | ||
+ | command[check_hda1]=/var/ipcop/addons/nrpe/plugins/check_disk -w 20% -c 10% -p /dev/hda1 | ||
+ | command[check_zombie_procs]=/var/ipcop/addons/nrpe/plugins/check_procs -w 5 -c 10 -s Z | ||
+ | command[check_total_procs]=/var/ipcop/addons/nrpe/plugins/check_procs -w 150 -c 200 | ||
+ | </code> | ||
+ | |||
+ | ======Tarball erstellen====== | ||
+ | Für das spätere Archiv wird ein Ordner angelegt, in welchem die später unterhalb **/var/ipcop/addons/nrpe** einzufügenden Addon-Dateien in einem Tarball komprimiert werden. | ||
+ | <code> | ||
+ | # mkdir nrpe-ipcop-VERSION | ||
+ | # cd nrpe-ipcop-VERSION | ||
+ | # mkdir -p build/nrpe/libs | ||
+ | # cp /PFAD-ZU-NRPE-VERSION/src/send_nsca build/nsca/ | ||
+ | # cp /PFAD-ZU-NRPE-VERSION/sample-config/nrpe.cfg build/nrpe/ | ||
+ | # cp --preserve=all -r /opt/lib/* build/nrpe/libs | ||
+ | # cd build/ | ||
+ | # tar cvfz ../nrpe.tar.gz nrpe/* | ||
+ | </code> | ||
+ | |||
+ | ======Installer====== | ||
+ | Herzstück des Addons ist ein Installationsskript, welches den **nrpe**-Tarball unterhalb von **/var/ipcop/addons** entpackt und den Nagios-Benutzer erstellt. | ||
+ | Mithilfe der Funktionen **addtofiletail** und **removefromfile** werden diese Eintragungen entsprechend maskiert, damit das Addons auch wieder sauber deinstalliert werden kann. | ||
+ | <code> | ||
+ | #!/bin/bash | ||
+ | # ipcop addon binary installer Ver 0.9b for IPCop 2.0 | ||
+ | |||
+ | CMD="$1" | ||
+ | |||
+ | # clear screen | ||
+ | /usr/bin/tput clear | ||
+ | |||
+ | # check | ||
+ | if [ ! -e /usr/lib/ipcop/library.sh ]; then | ||
+ | echo "Upgrade your IPCop, library.sh is missing" | ||
+ | exit 1 | ||
+ | fi | ||
+ | |||
+ | . /usr/lib/ipcop/library.sh | ||
+ | ismachine i486 | ||
+ | |||
+ | if [ ${?} -ne 0 ]; then | ||
+ | echo "This Addon is for i486 architecture only" | ||
+ | exit 1 | ||
+ | fi | ||
+ | |||
+ | # error handling | ||
+ | err() | ||
+ | { | ||
+ | echo " " | ||
+ | echo "Error : $1 " | ||
+ | echo " " | ||
+ | echo "Choose your option:" | ||
+ | echo " " | ||
+ | echo "./install -i ---> to install" | ||
+ | echo "./install -u ---> to uninstall" | ||
+ | echo " " | ||
+ | exit;exit; | ||
+ | } | ||
+ | |||
+ | # installation | ||
+ | ai() | ||
+ | { | ||
+ | #create user | ||
+ | /usr/sbin/useradd -d /dev/null -M -r -s /bin/false nagios | ||
+ | #extract tarball and copy configuration | ||
+ | tar xfz nrpe.tar.gz -C /var/ipcop/addons > /dev/null | ||
+ | #copy configuration and rc-stuff | ||
+ | cp nrpe.cfg /var/ipcop/addons/nrpe | ||
+ | cp rc.nrpe /etc/rc.d | ||
+ | addtofiletail nrpe local.add /etc/rc.d/rc.event.local | ||
+ | echo "nrpe 5666/tcp" >> /etc/services | ||
+ | } | ||
+ | |||
+ | # deinstallation | ||
+ | au() | ||
+ | { | ||
+ | #kill nrpe and delete user/files | ||
+ | /usr/bin/killall -KILL nrpe 2> /dev/null | ||
+ | rm -rf /var/ipcop/addons/nrpe | ||
+ | rm /etc/rc.d/rc.nrpe | ||
+ | /usr/sbin/userdel nagios | ||
+ | removefromfile nrpe /etc/rc.d/rc.event.local | ||
+ | grep -v "nrpe 5666/tcp" /etc/services > tmp | ||
+ | mv tmp /etc/services | ||
+ | } | ||
+ | |||
+ | |||
+ | case $CMD in | ||
+ | -i|i|install) | ||
+ | echo " " | ||
+ | echo "Installing now ..." | ||
+ | ai | ||
+ | echo "Successfully done!" | ||
+ | echo " " | ||
+ | echo "NOTE: dont forget to check /var/ipcop/addons/nrpe/nrpe.cfg" | ||
+ | echo " setup firewall rule to ensure connectivity from your nagios/icinga host to your ipcop" | ||
+ | echo " ";; | ||
+ | |||
+ | -u|u|uninstall) | ||
+ | echo " " | ||
+ | echo "Deinstalling now ..." | ||
+ | au | ||
+ | echo "Successfully done!" | ||
+ | echo " " | ||
+ | echo "NOTE: dont forget to delete nrpe firewall rule" | ||
+ | echo " ";; | ||
+ | *) | ||
+ | err "Invalid Option";; | ||
+ | esac | ||
+ | sync | ||
+ | #end of file | ||
+ | </code> | ||
+ | |||
+ | ======Packen und Aufräumen====== | ||
+ | Letztendlich kann der Addon-Ordner (//mit Ausnahme des **build**-Ordners//) in einen Tarball verwandelt werden, damit das Addon komfortabel installiert werden kann: | ||
+ | |||
+ | <code> | ||
+ | # tar cfz nrpe-ipcop-VERSION.tar.gz nrpe-ipcop-VERSION/{local.add,install,nrpe.tar.gz} | ||
+ | # md5sum nrpe-ipcop-VERSION.tar.gz > nrpe-ipcop-VERSION.tar.gz.md5sum | ||
+ | </code> | ||
+ | |||
+ | Auf dem Entwicklungssystem können die Daten unterhalb /opt entfernt werden: | ||
+ | <code> | ||
+ | # rm -rf /opt | ||
+ | </code> |