From 141b07aa0ef87d49439583a507a26094ee414c40 Mon Sep 17 00:00:00 2001 From: msavarit Date: Wed, 5 Feb 2020 11:22:01 +0100 Subject: [PATCH 1/2] Remove sudo for virsh, zabbix user should be in libvirt group --- README.md | 2 ++ virbix/scripts/domain_check.sh | 2 +- virbix/scripts/domain_list.sh | 2 +- virbix/scripts/net_check.sh | 2 +- virbix/scripts/net_list.sh | 2 +- virbix/scripts/pool_check.sh | 2 +- virbix/scripts/pool_list.sh | 2 +- virbix/scripts/report_domains.sh | 2 +- virbix/scripts/report_nets.sh | 2 +- virbix/scripts/report_node.sh | 2 +- virbix/scripts/report_pools.sh | 2 +- 11 files changed, 12 insertions(+), 10 deletions(-) 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/virbix/scripts/domain_check.sh b/virbix/scripts/domain_check.sh index b68bbfd..8c72552 100755 --- a/virbix/scripts/domain_check.sh +++ b/virbix/scripts/domain_check.sh @@ -1,6 +1,6 @@ #!/usr/bin/env ksh -VIRSH="sudo `which virsh`" +VIRSH="`which virsh`" UUID="${1}" ATTR="${2}" 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..bf4e5e4 100755 --- a/virbix/scripts/net_list.sh +++ b/virbix/scripts/net_list.sh @@ -1,6 +1,6 @@ #!/usr/bin/env ksh -VIRSH="sudo `which virsh`" +VIRSH="`which virsh`" for net in `${VIRSH} net-list --all --uuid | sort | uniq`; do output="" ${VIRSH} net-info ${net} | while read line; do diff --git a/virbix/scripts/pool_check.sh b/virbix/scripts/pool_check.sh index 8e6c851..505a97f 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'` 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}" From 7c82cbaa2874193d99628d3797605ede17b19455 Mon Sep 17 00:00:00 2001 From: msavarit Date: Wed, 5 Feb 2020 11:37:26 +0100 Subject: [PATCH 2/2] Change ownership of /etc/zabbix/scripts/agentd/virbix for allowing zabbix to write .xml --- deploy_zabbix.sh | 1 + 1 file changed, 1 insertion(+) 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