diff --git a/README.md b/README.md index e946f38..4687896 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,8 @@ LIBVIRT_URI|qemu:///system ## Zabbix +Add zabbix user in libvirt group (mandatory for running virsh command without sudo). + #~ git clone https://github.com/sergiotocalini/virbix.git #~ sudo ./virbix/deploy_zabbix.sh "" #~ sudo systemctl restart zabbix-agent diff --git a/deploy_zabbix.sh b/deploy_zabbix.sh index 0084be4..d4177da 100755 --- a/deploy_zabbix.sh +++ b/deploy_zabbix.sh @@ -9,4 +9,5 @@ cp -r ${SOURCE_DIR}/virbix/scripts ${ZABBIX_DIR}/scripts/agentd/virbix/ cp ${SOURCE_DIR}/virbix/virbix.conf.example ${ZABBIX_DIR}/scripts/agentd/virbix/virbix.conf cp ${SOURCE_DIR}/virbix/virbix.sh ${ZABBIX_DIR}/scripts/agentd/virbix/ cp ${SOURCE_DIR}/virbix/zabbix_agentd.conf ${ZABBIX_DIR}/zabbix_agentd.d/virbix.conf +chown -R zabbix:zabbix ${ZABBIX_DIR}/scripts/agentd/virbix sed -i "s|LIBVIRT_DEFAULT_URI=.*|LIBVIRT_DEFAULT_URI=\"${LIBVIRT_URI}\"|g" ${ZABBIX_DIR}/scripts/agentd/virbix/virbix.conf diff --git a/virbix/scripts/domain_check.sh b/virbix/scripts/domain_check.sh index b68bbfd..cd25d00 100755 --- a/virbix/scripts/domain_check.sh +++ b/virbix/scripts/domain_check.sh @@ -1,11 +1,25 @@ #!/usr/bin/env ksh -VIRSH="sudo `which virsh`" +VIRSH="`which virsh`" UUID="${1}" ATTR="${2}" if [[ ${ATTR} == 'state' ]]; then - ${VIRSH} domstate ${UUID}|sed '/^\s*$/d' + state=`${VIRSH} domstate ${UUID}|sed '/^\s*$/d'` + case $state in + "running") + echo "0" + ;; + "paused") + echo "1" + ;; + "shut off") + echo "2" + ;; + *) + echo "3" + ;; + esac elif [[ ${ATTR} == 'json' ]]; then dump=`${VIRSH} dumpxml ${UUID}` memory=`echo "${xml}" | xmlstarlet sel -q -T -t -m "domain/memory" -v . -n` diff --git a/virbix/scripts/domain_list.sh b/virbix/scripts/domain_list.sh index e291e5c..b82f0ac 100755 --- a/virbix/scripts/domain_list.sh +++ b/virbix/scripts/domain_list.sh @@ -1,6 +1,6 @@ #!/usr/bin/env ksh -VIRSH="sudo `which virsh`" +VIRSH="`which virsh`" for vm in `${VIRSH} list --all --uuid | sort | uniq`; do output="" ${VIRSH} dominfo ${vm} | while read line; do diff --git a/virbix/scripts/net_check.sh b/virbix/scripts/net_check.sh index bb8dd39..ed10ed1 100755 --- a/virbix/scripts/net_check.sh +++ b/virbix/scripts/net_check.sh @@ -1,7 +1,7 @@ #!/usr/bin/env ksh APP_DIR=$(dirname $0) -VIRSH="sudo `which virsh`" +VIRSH="`which virsh`" UUID="${1}" ATTR="${2}" TIMESTAMP=`date '+%s'` diff --git a/virbix/scripts/net_list.sh b/virbix/scripts/net_list.sh index 06dad6b..e4c8259 100755 --- a/virbix/scripts/net_list.sh +++ b/virbix/scripts/net_list.sh @@ -1,7 +1,7 @@ #!/usr/bin/env ksh -VIRSH="sudo `which virsh`" -for net in `${VIRSH} net-list --all --uuid | sort | uniq`; do +VIRSH="`which virsh`" +for net in `${VIRSH} net-list --all | sed 1,2d | sed '/^$/d' | cut -d' ' -f 2 | uniq`; do output="" ${VIRSH} net-info ${net} | while read line; do key=`echo ${line}|awk -F: '{print $1}'|awk '{$1=$1};1'` diff --git a/virbix/scripts/pool_check.sh b/virbix/scripts/pool_check.sh index 8e6c851..32a6ab8 100755 --- a/virbix/scripts/pool_check.sh +++ b/virbix/scripts/pool_check.sh @@ -1,7 +1,7 @@ #!/usr/bin/env ksh APP_DIR=$(dirname $0) -VIRSH="sudo `which virsh`" +VIRSH="`which virsh`" UUID="${1}" ATTR="${2}" TIMESTAMP=`date '+%s'` @@ -28,7 +28,21 @@ elif [[ ${ATTR} == 'size_free' ]]; then elif [[ ${ATTR} == 'size_total' ]]; then rval=`xmllint --xpath "string(//pool/capacity)" ${CACHE_FILE}` elif [[ ${ATTR} == 'state' ]]; then - rval="`${VIRSH} pool-info ${UUID}|grep '^State:'|awk -F: '{print $2}'|awk '{$1=$1};1'`" + state="`${VIRSH} pool-info ${UUID}|grep '^State:'|awk -F: '{print $2}'|awk '{$1=$1};1'`" + case $state in + "running") + rval="0" + ;; + "paused") + rval="1" + ;; + "shut off") + rval="2" + ;; + *) + rval="3" + ;; + esac fi echo ${rval:-0} diff --git a/virbix/scripts/pool_list.sh b/virbix/scripts/pool_list.sh index d25ebde..c6862be 100755 --- a/virbix/scripts/pool_list.sh +++ b/virbix/scripts/pool_list.sh @@ -1,6 +1,6 @@ #!/usr/bin/env ksh -VIRSH="sudo `which virsh`" +VIRSH="`which virsh`" for vm in `${VIRSH} pool-list --all | egrep -v "(^-.*|^ Name.*|^$)" | awk '{print $1}' | sort | uniq`; do output="" ${VIRSH} pool-info ${vm} | while read line; do diff --git a/virbix/scripts/report_domains.sh b/virbix/scripts/report_domains.sh index 73d9053..ce7a2d0 100755 --- a/virbix/scripts/report_domains.sh +++ b/virbix/scripts/report_domains.sh @@ -10,7 +10,7 @@ TIMESTAMP=`date '+%s'` IFS_DEFAULT="${IFS}" -VIRSH="sudo `which virsh`" +VIRSH="`which virsh`" UUID="${1:-all}" TYPE="${2:-json}" diff --git a/virbix/scripts/report_nets.sh b/virbix/scripts/report_nets.sh index 73d9053..ce7a2d0 100755 --- a/virbix/scripts/report_nets.sh +++ b/virbix/scripts/report_nets.sh @@ -10,7 +10,7 @@ TIMESTAMP=`date '+%s'` IFS_DEFAULT="${IFS}" -VIRSH="sudo `which virsh`" +VIRSH="`which virsh`" UUID="${1:-all}" TYPE="${2:-json}" diff --git a/virbix/scripts/report_node.sh b/virbix/scripts/report_node.sh index 2caed1e..f715d7e 100755 --- a/virbix/scripts/report_node.sh +++ b/virbix/scripts/report_node.sh @@ -10,7 +10,7 @@ TIMESTAMP=`date '+%s'` IFS_DEFAULT="${IFS}" -VIRSH="sudo `which virsh`" +VIRSH="`which virsh`" UUID="${1:-all}" TYPE="${2:-json}" diff --git a/virbix/scripts/report_pools.sh b/virbix/scripts/report_pools.sh index 4e11d7e..561a674 100755 --- a/virbix/scripts/report_pools.sh +++ b/virbix/scripts/report_pools.sh @@ -10,7 +10,7 @@ TIMESTAMP=`date '+%s'` IFS_DEFAULT="${IFS}" -VIRSH="sudo `which virsh`" +VIRSH="`which virsh`" UUID="${1:-all}" TYPE="${2:-json}" diff --git a/zbx3.4_template_hv_kvm.xml b/zbx3.4_template_hv_kvm.xml index c9556e9..f3beea9 100644 --- a/zbx3.4_template_hv_kvm.xml +++ b/zbx3.4_template_hv_kvm.xml @@ -66,7 +66,7 @@ 30d 0 0 - 1 + 3 @@ -87,14 +87,17 @@ Is the domain running or not 0 - running 1 - paused -2 - shut off +2 - shut off +3 - unknown 0 KVM - + + VIRSH Domain State + @@ -332,7 +335,7 @@ 7d 0 0 - 1 + 3 @@ -357,7 +360,9 @@ KVM - + + VIRSH Domain State + @@ -439,4 +444,27 @@ + + + VIRSH Domain State + + + 0 + running + + + 1 + paused + + + 2 + shut off + + + 3 + unknown + + + +