Last active
August 29, 2015 14:02
-
-
Save alice-xu/b52335af1d847ba00a4a to your computer and use it in GitHub Desktop.
virsh VM discovery script for Zabbix Low Level Discovery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# virsh_vm_discovery.sh: | |
# Virtual Machine discovery script for Zabbix | |
# | |
export LANG=en_US.UTF-8 | |
HV_NAME=$( hostname --fqdn ) | |
VMLIST=$( virsh list --all|tail -n +3|awk '{ print $2 }' ) | |
{ | |
echo "{" | |
echo " \"data\":[" | |
for VM in ${VMLIST}; do | |
VMINFO=$( virsh dominfo ${VM} ) | |
DOM_UUID=$( echo "${VMINFO}"|grep -E '^UUID:'|awk '{ print $2 }' ) | |
DOM_NAME=$( echo "${VMINFO}"|grep -E '^Name:'|awk '{ print $2 }' ) | |
echo " {" | |
echo " \"{#HV_NAME}\":\"${HV_NAME}\"," | |
echo " \"{#DOM_UUID}\":\"${DOM_UUID}\"," | |
echo " \"{#DOM_NAME}\":\"${DOM_NAME}\"" | |
echo " }," | |
done | sed -e '$d' | |
echo " }" | |
echo " ]" | |
echo "}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment