-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patharris_stats.sh
executable file
·78 lines (65 loc) · 2.53 KB
/
arris_stats.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
#---------------------------------------------------------------------------------------
# Parse Arris TG862A status page using XPath and store results on rrd.
#---------------------------------------------------------------------------------------
host_name=$(hostname)
script_name="$(basename $0)[$$]"
ds="$HOME/bin/arris-downstream.rrd"
status_url="http://192.168.100.1/cgi-bin/status_cgi"
#---------------------------------------------------------------------------------------
# Print Help message
#---------------------------------------------------------------------------------------
function print_usage(){
cat << EOFU
SUMMARY:
Parse Arris TG862A status page using XPath and store results on rrd.
OPTIONS:
-d Data source file path. Optional, $ds by default.
-u status page URL, default: http://192.168.100.1/cgi-bin/status_cgi
-h This help.
EOFU
}
#---------------------------------------------------------------------------------------
# log messages with same format as /var/log/auth.log
# Format: <Timestamp> <hostname> <app name [PID]:> <message>
# Example: Jul 23 06:53:59 linux.local arris_stats.sh[2820]: Cable modem is down.
#---------------------------------------------------------------------------------------
function log_msg(){
echo -e "$(date '+%b %d %H:%M:%S') $host_name $script_name $1"
}
#---------------------------------------------------------------------------------------
# Get cable modem status page
#---------------------------------------------------------------------------------------
function get_status(){
wget --quiet "$status_url" -O -
}
#---------------------------------------------------------------------------------------
# Parse status page html using XPath and update data source.
#---------------------------------------------------------------------------------------
function record_down_streams(){
stream_xpath="//table/tbody[tr[td[.='DCID']]]/tr[%d]/td[7]/text()"
declare -a octets
for i in {2..9};do
sx=$(printf "$stream_xpath" $i)
octets[$i]=$(echo "$1" | xmllint --html --recover --xpath "$sx" - 2>/dev/null)
done
t=$(date '+%s')
update_val="$(printf '%d:%d:%d:%d:%d:%d:%d:%d:%d' $t ${octets[*]})"
log_msg "Updating rrd: '$update_val'"
rrdtool update "$ds" "$update_val"
}
# parse options
while getopts d:h arg
do
case $arg in
d) ds=$OPTARG;;
u) status_url="$OPTARG";;
h) print_usage; exit;;
*)
echo "Invalid option $arg"
print_usage
exit 1;;
esac
done
stats=$(get_status)
record_down_streams "$stats"