-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathfunction.sh
executable file
·63 lines (52 loc) · 1.13 KB
/
function.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
#!/bin/bash
# Author: Guanghongwei
# Date: 2014/12/25
# Public function/variable for zabbix agent check
#
. /etc/profile
. /etc/bashrc
cwdir=`dirname $0`
check_list=$cwdir/check_list.txt
json_null() {
printf '{\n'
printf '\t"data":[\n'
printf "\t\t{ \n"
printf "\t\t\t\"{#VALUE}\":\"NULL\"}]}\n"
}
str_md5() {
echo $1 | md5sum | awk '{ print $1 }'
}
tmpfile_md5() {
/usr/bin/md5sum $tmpfile 2> /dev/null | awk '{ print $1 }' || echo "NULL"
}
low_case() {
echo $1 | tr [A-Z] [a-z]
}
if [ -d "/dev/shm" ];then
tmp_dir="/dev/shm"
else
tmp_dir="/tmp"
fi
discovery() {
values=($@)
if [ ! -f "$check_list" ];then
json_null
exit 2
fi
if [ ${#values[@]} -eq 0 ];then
json_null
exit 1
fi
printf '{\n'
printf '\t"data":[\n'
for((i=0;i<${#values[@]};++i)) {
num=$(echo $((${#values[@]}-1)))
if [ "$i" != "${num}" ]; then
printf "\t\t{ \n"
printf "\t\t\t\"{#VALUE}\":\"${values[$i]}\"},\n"
else
printf "\t\t{ \n"
printf "\t\t\t\"{#VALUE}\":\"${values[$num]}\"}]}\n"
fi
}
}