#!/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
#add for chinese status
export LANG=C

#LIST=$(sudo virsh list --all | sed '1,2d' | sed '/^$/d'| awk '{print $2":"$3}')

#O="SUDO VIRSH LIST"
#echo LIST:$LIST
#echo $O
count=`ps -aux |grep qemu-kvm |wc -l`
count=`expr $count - 1`
EXITVAL=0

echo "OK vm is $count|vms=$count"
exit 0
