From 16b041fdd8ab4560e952cbe7f1ed1d77315ccb95 Mon Sep 17 00:00:00 2001 From: Jef Bucas Date: Fri, 20 Nov 2009 16:47:01 +0100 Subject: [PATCH] Initial version --- plugins/other/esxi | 254 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 254 insertions(+) create mode 100755 plugins/other/esxi diff --git a/plugins/other/esxi b/plugins/other/esxi new file mode 100755 index 00000000..34506db1 --- /dev/null +++ b/plugins/other/esxi @@ -0,0 +1,254 @@ +#!/bin/bash + +GREP="/usr/bin/grep" +SED="/usr/bin/sed" +TAIL="/usr/bin/tail" +SSH="/usr/bin/ssh" +BASENAME="/usr/bin/basename" + +# script name must be like esx_cpu_machine.domain or esx_mem_machine.domain +temp="$(basename $0 | $SED 's/^esx_//g')" +which_info="${temp%%_*}" +HOST="${temp##*_}" + +case "$which_info" in + "cpu" | "mem" | "hmem" | "gmem" ) ;; + * ) echo "Script name incorrect, should be esx_xxx_hostname where xxx in {cpu,mem,hmem,gmem}" + exit 1;; +esac + +# --------------- + +function get_infos () { + summary="$($SSH "$HOST" \ + vim-cmd hostsvc/hostsummary \; \ + vim-cmd vmsvc/getallvms)" +} + +function get_vmlist () { + total_linenumber="$(echo "$summary" | wc -l)" + + vmlist_linenumber="$(echo "$summary" | $GREP -n "^Vmid")" + vmlist_linenumber="${vmlist_linenumber/:*/}" + + vmlist="$(echo "$summary" | $TAIL -n $(($total_linenumber - $vmlist_linenumber)) | tr -s " ")" +} + +function overallCpuUsage () { + cpu="$(echo "$1" | $GREP "overallCpuUsage")" + cpu="${cpu/*overallCpuUsage = /}" + cpu="${cpu/,*/}" +} + +function overallMemoryUsage () { + mem="$(echo "$1" | $GREP "overallMemoryUsage")" + mem="${mem/*overallMemoryUsage = /}" + mem="${mem/,*/}" +} + +# --------------- + +function get_vmsvcsummaries () { + n=0 + cmd="" +# echo "$vmlist" | \ + while read vmline ; do + id[$n]="${vmline%% *}" + temp="${vmline#${id[$n]} }" + name[$n]="${temp%% *}" + cmd="$cmd""vim-cmd vmsvc/get.summary ${id[$n]} \\\; " + (( n++ )) + done <