-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path60_esxi_if_in.sh
executable file
·83 lines (72 loc) · 2.74 KB
/
60_esxi_if_in.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
78
79
80
81
82
#!/bin/bash
community=$1
host=$2
version="2c"
date=$(date +%s)
count=0
list=$(snmpbulkwalk -v $version -c $community $host ifName)
listOctet=$(snmpbulkwalk -v $version -c $community $host ifHCInOctets)
listUcast=$(snmpbulkwalk -v $version -c $community $host ifHCInUcastPkts)
listMulticast=$(snmpbulkwalk -v $version -c $community $host ifHCInMulticastPkts)
listBroadcast=$(snmpbulkwalk -v $version -c $community $host ifHCInBroadcastPkts)
echo "["
while read -r line; do
if (($count != 0)); then
echo -n ","
fi
num=$((count+1))
inner=$(echo "$listOctet" | sed "${num}q;d")
index=$(echo $line | awk -F= '{print $2}' | awk -F: '{print $2}')
index=$(echo $index | xargs) #trim the white space
value=$(echo $inner | awk -F= '{print $2}' | awk -F: '{print $2}' )
value=$(echo $value | xargs) #trim the white space
echo "{\
\"endpoint\" : \"$host\",\
\"tags\" : \"iface=$index\",\
\"timestamp\" : $date,\
\"metric\" : \"esxi.net.in.octets\",\
\"value\" : $value,\
\"counterType\": \"COUNTER\",\
\"step\" : 60}"
inner=$(echo "$listUcast" | sed "${num}q;d")
index=$(echo $line | awk -F= '{print $2}' | awk -F: '{print $2}')
index=$(echo $index | xargs) #trim the white space
value=$(echo $inner | awk -F= '{print $2}' | awk -F: '{print $2}' )
value=$(echo $value | xargs) #trim the white space
echo ",{\
\"endpoint\" : \"$host\",\
\"tags\" : \"iface=$index\",\
\"timestamp\" : $date,\
\"metric\" : \"esxi.net.in.ucast.pkts\",\
\"value\" : $value,\
\"counterType\": \"COUNTER\",\
\"step\" : 60}"
inner=$(echo "$listMulticast"| sed "${num}q;d")
index=$(echo $line | awk -F= '{print $2}' | awk -F: '{print $2}')
index=$(echo $index | xargs) #trim the white space
value=$(echo $inner | awk -F= '{print $2}' | awk -F: '{print $2}')
value=$(echo $value | xargs) #trim the white space
echo ",{\
\"endpoint\" : \"$host\",\
\"tags\" : \"iface=$index\",\
\"timestamp\" : $date,\
\"metric\" : \"esxi.net.in.multicast.pkts\",\
\"value\" : $value,\
\"counterType\": \"COUNTER\",\
\"step\" : 60}"
inner=$(echo "$listBroadcast" | sed "${num}q;d")
index=$(echo $line | awk -F= '{print $2}' | awk -F: '{print $2}')
index=$(echo $index | xargs) #trim the white space
value=$(echo $inner | awk -F= '{print $2}' | awk -F: '{print $2}')
value=$(echo $value | xargs) #trim the white space
echo ",{\
\"endpoint\" : \"$host\",\
\"tags\" : \"iface=$index\",\
\"timestamp\" : $date,\
\"metric\" : \"esxi.net.in.broadcast.pkts\",\
\"value\" : $value,\
\"counterType\": \"COUNTER\",\
\"step\" : 60}"
count=$((count+1))
done <<< "$list"
echo "]"