Pense Bête : NSCA-NG
Si Debian/Wheezy
# echo ‘APT::Default-Release « wheezy »;’ > /etc/apt/apt.conf.d/99mixed
# echo ‘deb http://cdn.debian.net/debian jessie main’ > /etc/apt/sources.list.d/jessie.list
# apt-get update
Procédure
# apt-get install nagios-nrpe-server nagios-plugins nsca-ng-client
# mkdir /var/lib/nagios/bin
# vim /var/lib/nagios/bin/submit_host_result
1 2 3 4 5 6 7 | #!/bin/bash # Arguments # $1 = name of host in service definition # $2 = return code # $3 = output /usr/bin/printf "$1\t$2\t$3\n" | /usr/sbin/send_nsca |
# vim /var/lib/nagios/bin/submit_service_result
1 2 3 4 5 6 7 8 | #!/bin/bash # Arguments # $1 = name of host in service definition # $2 = name/description of service in service definition # $3 = return code # $4 = output /bin/echo -e "$1\t$2\t$3\t$4\n" | /usr/sbin/send_nsca |
# vim /var/lib/nagios/config
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #!/bin/bash HOSTNAME=the_hostname declare -A SERVICES SERVICES["APT"]="/usr/lib/nagios/plugins/check_apt" SERVICES["APT Distrib"]="/usr/lib/nagios/plugins/check_apt -d" # [...] SEPARATOR=";" # Groupement toutes les # minutes par Cron job CHECKS[1]="" CHECKS[15]="" CHECKS[30]="APT${SEPARATOR}APT Distrib" ## /!\ L'ajout d'un nouveau tempo, nécessite l'ajout de la cron job en tant que Nagios |
# vim /var/lib/nagios/bin/wrapper_host
1 2 3 4 5 | #!/bin/bash . /var/lib/nagios/config /var/lib/nagios/bin/submit_host_result "$HOSTNAME" 0 "PASSIVE UP" |
# vim /var/lib/nagios/bin/wrapper_service
1 2 3 4 5 6 7 8 | #!/bin/bash . /var/lib/nagios/config RESULT=$( ${SERVICES["$1"]} ) STATE=$? /var/lib/nagios/bin/submit_service_result "$HOSTNAME" "$1" $STATE "$RESULT" |
# vim /var/lib/nagios/bin/wrapper_services_cron
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #!/bin/bash . /var/lib/nagios/config IFS="${SEPARATOR}" read -a TAB <<< "${CHECKS[$1]}" for serviceName in "${TAB[@]}" do RESULT=$( ${SERVICES["$serviceName"]} ) STATE=$? /var/lib/nagios/bin/submit_service_result "$HOSTNAME" "$serviceName" $STATE "$RESULT" done |
# crontab -e
1 2 3 4 | */1 * * * * /var/lib/nagios/bin/wrapper_host */1 * * * * /var/lib/nagios/bin/wrapper_services_cron 1 */15 * * * * /var/lib/nagios/bin/wrapper_services_cron 15 */30 * * * * /var/lib/nagios/bin/wrapper_services_cron 30 |
# chmod +x /var/lib/nagios/bin/*
# chown nagios:nagios /var/lib/nagios -R
Après toute cette tambouille maison, ça roule un peu mieux, ne pas oublier de configurer :
– /etc/send_nsca.cfg
1 2 3 4 | identity = "some-textual-identity" password = "leave-me-alone" server = "Server IP" port = 5668 |
– Ouvrir le port 5668 sur le serveur
– Sur le serveur, /etc/nsca-ng/nsca-ng.local.cfg
1 2 3 4 5 6 7 8 9 10 11 12 13 | listen = "*:5668" user = "nagios" command_file= "/var/lib/icinga/rw/icinga.cmd" authorize "some-textual-identity" { password = "leave-me-alone" hosts = "hostnames in icinga" # services = ".*" commands = { "PROCESS_HOST_CHECK_RESULT;.+" , "PROCESS_SERVICE_CHECK_RESULT;.+" } } |
C’est un pense-bête grossier, pas vraiment prévu pour le World Wide Web, mais c’est tellement mal documenté, que certains pourrait bien tomber ici.