yum -y install lua-devel openssl-devel libconfig-devel readline-devel libevent-devel git uuid-devel libuuid libuuid-devel
cd /usr/local/src
git clone --recursive https://github.com/vysheng/tg.git
cd tg
./configure --disable-json
make
mkdir /usr/local/tg
cp tg-server.pub /usr/local/tg
cp bin/telegram-cli /usr/local/tg
https://my.telegram.org/auth?to=apps
访问该网站 输入你需要当做报警的telegram账号
填写这两个参数即可点击确定
获取keys:
在linux服务器上测试
查看组或用户的信息
/usr/local/tg/telegram-cli -k /usr/local/tg/tg-server.pub
第一次登陆需要收验证码
[root@zl-zabbix-xg04 tg]# /usr/local/tg/telegram-cli -k /usr/local/tg/tg-server.pub
change_user_group: can't find the user telegramd to switch to
Telegram-cli version 1.4.1, Copyright (C) 2013-2015 Vitaly Valtman
Telegram-cli comes with ABSOLUTELY NO WARRANTY; for details type `show_license'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show_license' for details.
Telegram-cli uses libtgl version 2.1.0
Telegram-cli includes software developed by the OpenSSL Project
for use in the OpenSSL Toolkit. (http://www.openssl.org/)
I: config dir=[/root/.telegram-cli]
phone number: +86 13185481234
code ('CALL' for phone code): 96212
发送组消息
> msg zabbix_zhulian can not pa
[10:27] zabbix_zhulian zabbix >>> can not pa
Chat zabbix_zhulian marked read 1 outbox and 0 inbox messages
开启端口8890
cd /usr/local/tg
./telegram-cli -k tg-server.pub -WDCRE -P 8890 -d &>/dev/null &
测试发送群组消息
echo -e "msg zabbix_zhulian test-xioaxi" | nc localhost 8890
配置zabbix脚本
vim /etc/zabbix/zabbix_server.conf
AlertScriptsPath=/etc/zabbix/scripts
vim tg.sh
#!/bin/sh
export to=$1;
export subject=$2;
export body=$3;
echo -e "msg $to ${subject}\n${body}" | nc localhost 8890
chmod +x tg.sh
{ALERT.SENDTO}
{ALERT.SUBJECT}
{ALERT.MESSAGE}
标题:
故障主机:{HOST.NAME} IP:{HOST.IP}时间:{EVENT.DATE}-{EVENT.TIME};等级:{TRIGGER.SEVERITY}发生故障:{TRIGGER.NAME};问题详情: {ITEM.NAME}:{ITEM.VALUE}
消息内容:
告警主机: {HOST.NAME}
告警 IP: {HOST.IP}
告警时间: {EVENT.DATE}-{EVENT.TIME}
告警等级: {TRIGGER.SEVERITY}
告警信息: {TRIGGER.NAME}
告警项目: {TRIGGER.KEY1}
问题详情: {ITEM.NAME}:{ITEM.VALUE}
当前状态: {TRIGGER.STATUS}:{ITEM.VALUE1}
事件 ID: {EVENT.ID}
标题:
恢复故障主机:{HOST.NAME} IP:{HOST.IP}时间:{EVENT.DATE}-{EVENT.TIME};等级:{TRIGGER.SEVERITY}故障:{TRIGGER.NAME}已恢复;恢复问题详情: {ITEM.NAME}:{ITEM.VALUE}
消息内容:
恢复告警主机: {HOST.NAME}
恢复 IP: {HOST.IP}
恢复 时间: {EVENT.DATE}-{EVENT.TIME}
恢复告警等级: {TRIGGER.SEVERITY}
恢复告警信息: {TRIGGER.NAME}
恢复告警项目: {TRIGGER.KEY1}
恢复问题详情: {ITEM.NAME}:{ITEM.VALUE}
恢复当前状态: {TRIGGER.STATUS}:{ITEM.VALUE1}
恢复事件 ID: {EVENT.ID}