Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| — | anwenderwiki:nagios:nagios-kvm [2013/05/28 22:56] (aktuell) – angelegt - Externe Bearbeitung 127.0.0.1 | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| + | {{tag> nagios kvm}} | ||
| + | ====== KVM-Hosts in Nagios anzeigen (über Nagios-nrpe) ====== | ||
| + | |||
| + | {{: | ||
| + | |||
| + | Neues plugin **'' | ||
| + | Muss zunächst auf deutsche Textausgabe angepasst werden. | ||
| + | |||
| + | <code text check_kvm> | ||
| + | #!/bin/sh | ||
| + | # check_kvm - Check that a virtual machine is running. | ||
| + | # Written by Karl Rink < | ||
| + | # | ||
| + | # | ||
| + | # COPYRIGHT | ||
| + | # | ||
| + | # AUTHOR | ||
| + | # | ||
| + | # BELONGS TO : Qemu/Kvm Nagios Integration | ||
| + | # | ||
| + | # DESCRIPTION | ||
| + | # | ||
| + | # $Revision: 1.0 $ | ||
| + | # | ||
| + | # Permission to use, copy, modify, distribute, and sell this software | ||
| + | # and its documentation for any purpose is hereby granted without fee, | ||
| + | # provided that the above copyright notice appear in all copies and that | ||
| + | # both that copyright notice and this permission notice appear in | ||
| + | # supporting documentation. | ||
| + | # | ||
| + | # The above copyright notice and this permission notice shall be | ||
| + | # included in all copies or substantial portions of the Software. | ||
| + | # | ||
| + | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
| + | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
| + | # MERCHANTABILITY, | ||
| + | # IN NO EVENT SHALL THE AUTHOR OR SUSE BE LIABLE FOR ANY CLAIM, DAMAGES | ||
| + | # OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
| + | # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR | ||
| + | # THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| + | # | ||
| + | |||
| + | # Install: | ||
| + | # As a nagios nrpe plugin, add the following line to your client nrpe.cfg | ||
| + | # command[virt_check_kvm]=/ | ||
| + | # No sudo is necessary if you simply add nagios user to the libvirt group | ||
| + | # libvirtd: | ||
| + | |||
| + | PATH=/ | ||
| + | export PATH | ||
| + | |||
| + | LIST=$(virsh list --all | sed ' | ||
| + | |||
| + | if [ ! " | ||
| + | EXITVAL=3 #Status 3 = UNKNOWN (orange) | ||
| + | echo " | ||
| + | exit $EXITVAL | ||
| + | fi | ||
| + | |||
| + | OK=0 | ||
| + | WARN=0 | ||
| + | CRIT=0 | ||
| + | NUM=0 | ||
| + | |||
| + | for host in $(echo $LIST) | ||
| + | do | ||
| + | name=$(echo $host | awk -F: ' | ||
| + | state=$(echo $host | awk -F: ' | ||
| + | NUM=$(expr $NUM + 1) | ||
| + | |||
| + | case " | ||
| + | laufend) OK=$(expr $OK + 1) ;; | ||
| + | Ausgeschaltet) WARN=$(expr $WARN + 1) ;; | ||
| + | shutdown|shut*|crashed) CRIT=$(expr $CRIT + 1) ;; | ||
| + | *) CRIT=$(expr $CRIT + 1) ;; | ||
| + | esac | ||
| + | done | ||
| + | |||
| + | EXITVAL=0 | ||
| + | |||
| + | #if [ " | ||
| + | # EXITVAL=0 #Status 0 = OK (green) | ||
| + | #fi | ||
| + | # | ||
| + | #if [ " | ||
| + | # EXITVAL=1 #Status 1 = WARNING (yellow) | ||
| + | #fi | ||
| + | |||
| + | if [ " | ||
| + | EXITVAL=2 #Status 2 = CRITICAL (red) | ||
| + | fi | ||
| + | |||
| + | echo Hosts:$NUM Laufend:$OK Aus:$WARN CRIT:$CRIT - $LIST | ||
| + | |||
| + | exit $EXITVAL | ||
| + | |||
| + | </ | ||
| + | |||
| + | Das Plugin in **''/ | ||
| + | |||
| + | command[check_kvm]=sudo / | ||
| + | |||
| + | Schließlich für sudo eine Datei anlegen: **''/ | ||
| + | <code text nagios-kvm-suid> | ||
| + | # / | ||
| + | # MR 27.05.2013 | ||
| + | # | ||
| + | |||
| + | Cmnd_Alias | ||
| + | nagios ALL=NOPASSWD: | ||
| + | |||
| + | </ | ||
| + | |||
| + | Ggf. noch mit " | ||