-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path60_esxi_user.sh
executable file
·61 lines (57 loc) · 1.78 KB
/
60_esxi_user.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
#!/bin/bash
community=$1
host=$2
version="2c"
ret_trans() {
if [ "$1" == "0" ] ; then
echo "$2"
else
echo "$3"
fi
}
date=$(date +%s)
process=$(snmpbulkwalk -v $version -c $community $host 1.3.6.1.2.1.25.1.6.0)
alive=$(ret_trans $? "1" "-1")
echo "["
echo "{\
\"endpoint\" : \"$host\",\
\"tags\" : \"\",\
\"timestamp\" : $date,\
\"metric\" : \"agent.alive\",\
\"value\" : $alive,\
\"counterType\": \"GAUGE\",\
\"step\" : 60}"
if [ "$alive" == "1" ] ; then
value=$(echo $process | awk -F= '{print $2}' | awk -F: '{print $2}')
value=$(echo $value | xargs) #trim the white space
echo ",{\
\"endpoint\" : \"$host\",\
\"tags\" : \"\",\
\"timestamp\" : $date,\
\"metric\" : \"esxi.current.process\",\
\"value\" : $value,\
\"counterType\": \"GAUGE\",\
\"step\" : 60}"
user=$(snmpbulkwalk -v $version -c $community $host 1.3.6.1.2.1.25.1.5.0)
value=$(echo $user | awk -F= '{print $2}' | awk -F: '{print $2}')
value=$(echo $value | xargs) #trim the white space
echo ",{\
\"endpoint\" : \"$host\",\
\"tags\" : \"\",\
\"timestamp\" : $date,\
\"metric\" : \"esxi.current.user\",\
\"value\" : $value,\
\"counterType\": \"GAUGE\",\
\"step\" : 60}"
VmGuestState=$(snmpbulkwalk -v $version -c $community $host 1.3.6.1.4.1.6876.2.1.1.8)
numOfVhost=$(echo $VmGuestState|wc -l)
echo ",{\
\"endpoint\" : \"$host\",\
\"tags\" : \"\",\
\"timestamp\" : $date,\
\"metric\" : \"esxi.current.vhost\",\
\"value\" : $numOfVhost,\
\"counterType\": \"GAUGE\",\
\"step\" : 60}"
fi
echo "]"