Skip to content

Instantly share code, notes, and snippets.

@jhrcz
Created January 17, 2014 13:46
Show Gist options
  • Save jhrcz/8473576 to your computer and use it in GitHub Desktop.
Save jhrcz/8473576 to your computer and use it in GitHub Desktop.
without proper monitoring (nagios for example) this is the easy way to catch vms in incorrect states - other than running, suspend, stopped..
#!/bin/bash
[ "$DEBUG" = "YES" ] \
&& set -x
qverbose ()
{
[ "$VERBOSE" = "YES" ] \
&& return 0 || return 1
}
list_running_vmids ()
{ # none
onevm list --xml \
| xmlstarlet sel -t -m '/VM_POOL/VM' -v 'ID' -n
}
get_vmid_state ()
{ # 1: vmid
onevm show --xml $vmid | xmlstarlet sel -t -m '/VM' -v STATE -n | head -n 1
}
list_running_vmids | while read vmid
do
[ -n "$vmid" ] || continue
qverbose \
&& echo "# $vmid"
vm_state=""
vm_state=$( get_vmid_state "$vmid" )
case "$vm_state" in
"5") # suspend
echo "OK: vmid $vmid is ok, suspend"
;;
"4") # stopped
echo "OK: vmid $vmid is ok, stopped"
;;
"3") # running
echo "OK: vmid $vmid is ok, running"
;;
*)
echo "ERROR: vmid $vmid in nonstandard state \"$vm_state\"" >&2
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment