월간 인기 게시물

게시물 1,372건
   
nagios check_libvirt
글쓴이 : 최고관리자 날짜 : 2022-12-06 (화) 17:55 조회 : 624
글주소 :
                                
https://github.com/sadsfae/nagios-plugins


/etc/sudoers
nagios  ALL=NOPASSWD:/usr/bin/virsh


/usr/lib/nagios/plugins/check_libvirt
#!/bin/sh
# check_kvm - Check that a virtual machine is running.
# Written by Karl Rink <krink@csun.edu>
#
#----------------------------------------------------------------------
# COPYRIGHT    : 12.2010 California State University, Northridge
#
# AUTHOR       : Karl Rink 
#
# BELONGS TO   : Qemu/Kvm Nagios Integration
#
# DEscRIPTION  : Runs "virsh list" and returns the available vms
#
# $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, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# 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:  Put this script in nagios client directory libexec/check_kvm
# As a nagios nrpe plugin, add the following line to your client nrpe.cfg
# command[virt_check_kvm]=/opt/nagios/libexec/check_kvm
# No sudo is necessary if you simply add nagios user to the libvirt group
# libvirtd:x:118:nagios 

PATH=/bin:/usr/bin:/sbin:/usr/sbin
export PATH

#LIST=$(sudo virsh list --all | sed '1,2d' | sed '/^$/d'| awk '{print $2":"$3}')
LIST=$(sudo virsh list --all | sed '/^$/d'| awk '{print $2":"$3}')
if [ ! "$LIST" ]; then
  EXITVAL=3 #Status 3 = UNKNOWN (orange) 
  echo "Unknown guests"
  exit $EXITVAL
fi

OK=0
WARN=0
CRIT=0
NON=0
NUM=-2

for host in $(echo $LIST)
do
  name=$(echo $host | awk -F: '{print $1}')
  state=$(echo $host | awk -F: '{print $2}')
  NUM=$(expr $NUM + 1)

  case "$state" in
    running|blocked) OK=$(expr $OK + 1) ;;
    paused|shutdown|shut*) WARN=$(expr $WARN + 1) ;;
    crashed) CRIT=$(expr $CRIT + 1) ;;
    *) NON=$(expr $NON + 1) ;;
  esac
done

if [ "$NUM" -eq "$OK" ]; then
  EXITVAL=0 #Status 0 = OK (green)
fi

if [ "$WARN" -gt 0 ]; then
  EXITVAL=1 #Status 1 = WARNING (yellow)
fi

if [ "$CRIT" -gt 0 ]; then
  EXITVAL=2 #Status 2 = CRITICAL (red)
fi

echo hosts:$NUM OK:$OK WARN:$WARN CRIT:$CRIT - $LIST

exit $EXITVAL



XXXXXXX/Check libvirt: Unknown guests

XXXXXXX/Check libvirt: hosts:4 OK:2 WARN:0 CRIT:2 - instance-0000033a:running instance-00002619:running instance-00000d8b:shut instance-00000f4d:shut

XXXXXXX/Check libvirt: hosts:3 OK:3 WARN:0 CRIT:0 - instance-00000e05:running instance-000019e7:running instance-000021cf:running


이름 패스워드
비밀글 (체크하면 글쓴이만 내용을 확인할 수 있습니다.)
왼쪽의 글자를 입력하세요.
   

 



 
사이트명 : 모지리네 | 대표 : 이경현 | 개인커뮤니티 : 랭키닷컴 운영체제(OS) | 경기도 성남시 분당구 | 전자우편 : mojily골뱅이chonnom.com Copyright ⓒ www.chonnom.com www.kyunghyun.net www.mojily.net. All rights reserved.