Created
June 28, 2014 18:31
-
-
Save kaz-tk/d647714da643b2281290 to your computer and use it in GitHub Desktop.
use to get interface statistics by zabbix_agent
This file contains hidden or 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
UserParameter=intstat[*],/etc/zabbix/scripts/intstat.sh $1 $2 |
This file contains hidden or 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
#!/bin/bash | |
USERNAME=`whoami` | |
INTERFACE=$1 | |
PARAM=$2 | |
interfaces="bond0 eth0 eth1 eth2" | |
statuses='collisions rx_errors rx_packets tx_errors | |
multicast rx_fifo_errors tx_aborted_errors tx_fifo_errors | |
rx_bytes rx_frame_errors tx_bytes tx_heartbeat_errors | |
rx_compressed rx_length_errors tx_carrier_errors tx_packets | |
rx_crc_errors rx_missed_errors tx_compressed tx_window_errors | |
rx_dropped rx_over_errors tx_dropped ' | |
function isCorrectInterface (){ | |
for interface in ${interfaces} | |
do | |
[ $1 = ${interface} ] && return 0; | |
done | |
exit 1; | |
} | |
function isCorrectStatus (){ | |
for status in ${statuses} | |
do | |
[ $1 = ${status} ] && return 0; | |
done | |
# echo "Parameter is not Match statuses." | |
exit 1 ; | |
} | |
$(isCorrectInterface "${INTERFACE}") | |
if [ $? -eq 1 ]; then | |
exit -1 | |
fi | |
$(isCorrectStatus "${PARAM}") | |
if [ $? -eq 1 ]; then | |
exit -1 | |
fi | |
cat /sys/class/net/${INTERFACE}/statistics/${PARAM} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment