Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/network active transform #8

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<LIBVIRT_URI>"
#~ sudo systemctl restart zabbix-agent
Expand Down
1 change: 1 addition & 0 deletions deploy_zabbix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 16 additions & 2 deletions virbix/scripts/domain_check.sh
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
2 changes: 1 addition & 1 deletion virbix/scripts/domain_list.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 13 additions & 2 deletions virbix/scripts/net_check.sh
Original file line number Diff line number Diff line change
@@ -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'`
Expand All @@ -27,7 +27,18 @@ elif [[ ${ATTR} == 'mac_addr' ]]; then
refresh_cache
rval=`xmllint --xpath "string(//network/mac/@address)" ${CACHE_FILE}`
elif [[ ${ATTR} == 'active' ]]; then
rval="`${VIRSH} net-info ${UUID}|grep '^Active:'|awk -F: '{print $2}'|awk '{$1=$1};1'`"
activate="`${VIRSH} net-info ${UUID}|grep '^Active:'|awk -F: '{print $2}'|awk '{$1=$1};1'`"
case $activate in
"no")
rval="0"
;;
"yes")
rval="1"
;;
*)
rval="2"
;;
esac
fi

echo ${rval:-0}
4 changes: 2 additions & 2 deletions virbix/scripts/net_list.sh
Original file line number Diff line number Diff line change
@@ -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'`
Expand Down
18 changes: 16 additions & 2 deletions virbix/scripts/pool_check.sh
Original file line number Diff line number Diff line change
@@ -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'`
Expand All @@ -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}
2 changes: 1 addition & 1 deletion virbix/scripts/pool_list.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion virbix/scripts/report_domains.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ TIMESTAMP=`date '+%s'`

IFS_DEFAULT="${IFS}"

VIRSH="sudo `which virsh`"
VIRSH="`which virsh`"
UUID="${1:-all}"
TYPE="${2:-json}"

Expand Down
2 changes: 1 addition & 1 deletion virbix/scripts/report_nets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ TIMESTAMP=`date '+%s'`

IFS_DEFAULT="${IFS}"

VIRSH="sudo `which virsh`"
VIRSH="`which virsh`"
UUID="${1:-all}"
TYPE="${2:-json}"

Expand Down
2 changes: 1 addition & 1 deletion virbix/scripts/report_node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ TIMESTAMP=`date '+%s'`

IFS_DEFAULT="${IFS}"

VIRSH="sudo `which virsh`"
VIRSH="`which virsh`"
UUID="${1:-all}"
TYPE="${2:-json}"

Expand Down
2 changes: 1 addition & 1 deletion virbix/scripts/report_pools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ TIMESTAMP=`date '+%s'`

IFS_DEFAULT="${IFS}"

VIRSH="sudo `which virsh`"
VIRSH="`which virsh`"
UUID="${1:-all}"
TYPE="${2:-json}"

Expand Down
65 changes: 56 additions & 9 deletions zbx3.4_template_hv_kvm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<history>30d</history>
<trends>0</trends>
<status>0</status>
<value_type>1</value_type>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<snmpv3_contextname/>
Expand All @@ -87,14 +87,17 @@
<description>Is the domain running or not&#13;
0 - running&#13;
1 - paused&#13;
2 - shut off</description>
2 - shut off&#13;
3 - unknown</description>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>KVM</name>
</application>
</applications>
<valuemap/>
<valuemap>
<name>VIRSH Domain State</name>
</valuemap>
<logtimefmt/>
<preprocessing/>
<jmx_endpoint/>
Expand Down Expand Up @@ -166,7 +169,7 @@
<history>7d</history>
<trends>0</trends>
<status>0</status>
<value_type>1</value_type>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<snmpv3_contextname/>
Expand All @@ -186,15 +189,17 @@
<port/>
<description>Is the network up or not&#13;
0 - No&#13;
1 - Yes</description>
1 - Yes&#13;
2 - Unknown</description>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>KVM</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
<valuemap>
<name>Is Network Active</name>
</valuemap> <logtimefmt/>
<preprocessing/>
<jmx_endpoint/>
<application_prototypes/>
Expand Down Expand Up @@ -332,7 +337,7 @@
<history>7d</history>
<trends>0</trends>
<status>0</status>
<value_type>1</value_type>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<snmpv3_contextname/>
Expand All @@ -357,7 +362,9 @@
<name>KVM</name>
</application>
</applications>
<valuemap/>
<valuemap>
<name>VIRSH Domain State</name>
</valuemap>
<logtimefmt/>
<preprocessing/>
<jmx_endpoint/>
Expand Down Expand Up @@ -439,4 +446,44 @@
<screens/>
</template>
</templates>
<value_maps>
<value_map>
<name>VIRSH Domain State</name>
<mappings>
<mapping>
<value>0</value>
<newvalue>running</newvalue>
</mapping>
<mapping>
<value>1</value>
<newvalue>paused</newvalue>
</mapping>
<mapping>
<value>2</value>
<newvalue>shut off</newvalue>
</mapping>
<mapping>
<value>3</value>
<newvalue>unknown</newvalue>
</mapping>
</mappings>
</value_map>
<value_map>
<name>Is Network Active</name>
<mappings>
<mapping>
<value>0</value>
<newvalue>no</newvalue>
</mapping>
<mapping>
<value>1</value>
<newvalue>yes</newvalue>
</mapping>
<mapping>
<value>2</value>
<newvalue>unknown</newvalue>
</mapping>
</mappings>
</value_map>
</value_maps>
</zabbix_export>