-
Notifications
You must be signed in to change notification settings - Fork 4
/
Telezabix.sh
37 lines (31 loc) · 1021 Bytes
/
Telezabix.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
#!/bin/bash
# This script implements telegram notification to zabbix
# By Aleksey Sviridkin [email protected]
# https://github.com/lexfrei/Telezabix
# Put this file to AlertScript path (you can find this path in zabbix_server.cfg)
JerardToken="123496961:AAEHXP8DYKkUu5Y2u7fXWySOhh7Gk157IJc" #You can change this token to your own or just use my bot
JerardURL="https://api.telegram.org/bot${JerardToken}"
JerardClient=${1} #You need to set this in "to" field in media settings in your user profile
JerardSubj=${2}
JerardText=${3}
rawurlencode() {
local string="${1}"
local strlen=${#string}
local encoded
unset encoded
for (( pos=0 ; pos<strlen ; pos++ ));
do
c=${string:$pos:1}
case "$c" in
[-_.~a-zA-Z0-9а-яА-Я] )
o="${c}"
;;
* )
printf -v o '%%%02x' "'$c"
;;
esac
encoded+="${o}"
done
echo "${encoded}"
}
curl "${JerardURL}/sendMessage?chat_id=${JerardClient}&text=$(rawurlencode "${JerardSubj}"):%20$(rawurlencode "${JerardText}")%0a%23zabbix%20%23work" 2>/dev/null 1>/dev/null