-
Notifications
You must be signed in to change notification settings - Fork 0
/
TEMPer_zabbix.sh
89 lines (73 loc) · 2.2 KB
/
TEMPer_zabbix.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
83
84
85
86
87
88
89
#!/usr/bin/env sh
##################### CONFIG ###########################
########################################################
# To configure the JSON PARSING, follow the guide of
# temper.py and change the jq query to match your output.
# == https://github.com/urwen/temper ==
TEMPERPY=/home/pi/temper/temper.py
ZABBIX_CONF=/etc/zabbix/zabbix_agentd.conf
ZABBIX_SENDER=/usr/bin/zabbix_sender
JQ=/usr/bin/jq
# Should be ok for TEMPer 0c45:7401
TEMPER_JSON_PARSING=".[0][\"internal temperature\"]"
##################### END CONFIG ###########################
exit_with_error(){
echo 1>&2 "TEMPer_zabbix.sh: ERROR: ${2}"
exit ${1}
}
zabbixsend() {
key=${1}
shift
message="${@}"
${ZABBIX_SENDER} -c "${ZABBIX_CONF}" -k $key -o "${message}"
}
datestamp() {
local formatting="+%F %T %z"
date "${formatting}"
}
check_config() {
failures=0
# checking zabbix
if [ ! -f "${ZABBIX_CONF}" ];then
echo 1>&2 "ZABBIX_CONF Not found, check config at top of script"
failures=$(( ${failures} + 1 ))
fi
if [ ! -x "${ZABBIX_SENDER}" ];then
echo 1>&2 "ZABBIX_SENDER Not a program, check config at top of script. Looking for zabbix_sender in PATH"
which zabbix_sender
failures=$(( ${failures} + 1 ))
fi
# check jq
if [ ! -x "${JQ}" ];then
echo 1>&2 "jq Not a program, check config at top of script. Looking for jq in PATH"
which jq
failures=$(( ${failures} + 1 ))
fi
# check temper.py
if [ ! -x ${TEMPERPY} ];then
echo 1>&2 "temper.py is not found. Check config at top of script"
failures=$(( ${failures} + 1 ))
fi
if [ $failures -gt 0 ];then
exit_with_error 2 "Script config is not set up correctly. please check config at top of script. see errors above "
else
return 0
fi
}
temper_error() {
echo 1>&2 "temper.py command failed. Check config at top of this script."
INFO="DATE : $(datestamp)
temper.py command failed.
"
zabbixsend temper.is_online 0
exit 1
}
main() {
check_config
# Get data from TEMPer
# looks like ./temper.py --json |jq '.[0]["internal temperature"]'
DATA="$( ${TEMPERPY} --json |jq "${TEMPER_JSON_PARSING}" )" || temper_error
zabbixsend temper.temperature ${DATA}
zabbixsend temper.is_online 1
}
main "${@}"