#!/bin/bash # Ryan Wilgoss 2010 (Ver 1.0 - 30/7/2010) # # Using the vmware-cmd (located on the target virtual server) the /path_to/target-server.vmx file # and getstate to check 1 of 4 available states which are on, off, suspended, stuck. # Any result other than on will return a CRITICAL state. # # vhost = Virtual Host (Server Running VMware) # vserver = Path To Virtual Server .vmx file (Running On The Virtual Host) # To avoid authentication requirements of SSH, use pre shared encrypted keys on the nagios # user both on the Nagios server and the target vserver. # # Command Line Usage - ./vmware_check vhost /path/to/.vmx # # # Nagios Service Example Usage ## Service to check VMware on a remote machine. ##define service{ # use local-service ; Name of service template to use # host_name vhost # service_description VMware # is_volatile 0 # check_period 24x7 # max_check_attempts 3 # normal_check_interval 5 # retry_check_interval 1 # notification_interval 120 # check_command vmware_check!vhost!/path/to/.vmx # } if [ "$1" == "" ]; then echo "Usage: vmware_check vhost vserver" echo " vhost -> The virtual host or FQDN (server@example.com)" echo " vserver -> The path to the VMWare .vmx file (/virtual/server/server.vmx)" exit -1; else vhost=$1 vserver=$2 fi STATUS=`ssh "$vhost" vmware-cmd -q "$vserver" getstate` echo $STATUS if [ "$STATUS" == 'on' ]; then message="OK - Virtual Server $vserver is running" echo $message extout=0 fi if [ "$STATUS" == 'off' ]; then message="Virtual Server $vserver is not running" echo $message extout=2 fi exit $exout;