zabbix实现QQ消息告警:MojoWebQQ实现

  sre

依赖包安装:

yum install -y  chrony gcc gcc-c++ git openssl-devel perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker 

启用系统时间自动同步:

systemctl enable chronyd
systemctl start chronyd

安装cpanm工具:

curl -L https://cpanmin.us/ -o /usr/bin/cpanm && chmod +x /usr/bin/cpanm

安装相关依赖的perl插件:

cpanm --mirror http://mirrors.sohu.com/CPAN/ Digest::MD5 Encode::Locale IO::Socket::SSL Mojolicious Time::Piece Time::Seconds Compress::Raw::Zlib Digest::SHA --force

安装Mojo-Webqq:

cd /usr/src/
git clone https://github.com/sjdy521/Mojo-Webqq.git
cd Mojo-Webqq/
perl Makefile.PL
make -j 16 && make install

创建Mojo-Webqq启动脚本:

vim /usr/local/bin/MojoWebqq.pl
#!/usr/bin/env perl
use Mojo::Webqq;
my (host,port,post_api);host = "0.0.0.0"; #发送消息接口监听地址,没有特殊需要请不要修改
port = 5000;      #发送消息接口监听端口,修改为自己希望监听的端口
#post_api = ‘http://xxxx‘;  #接收到的消息上报接口,如果不需要接收消息上报,可以删除或注释此行

my client = Mojo::Webqq->new();client->load("ShowMsg");
client->load("Openqq",data=>{listen=>[{host=>host,port=>port}], post_api=>post_api});
$client->run();

添加执行权限并执行:

chmod +x /usr/local/bin/MojoWebqq.pl
nohup /usr/local/bin/MojoWebqq.pl &>>/var/log/Mojo-Webqq.log &
#默认二维码路径为/tmp/mojo_webqq_qrcode_default.png 下载后扫码登录

Shell客户端:

#!/bin/bash
#好友的QQ号码
qq=1

#Mojoqq服务器地址与端口号
server='127.0.0.1'
port='5000'

#消息内容处理下编码,用于合并告警内容的标题和内容,即2和3
message=`echo -e "2\n3"|od -t x1 -A n -v -w100000 | tr " " %`

#调用的api接口
api_url="http://server:port/openqq/send_friend_message"
parameter="uid=qq&content=message"

#post方式提交请求发送QQ好友消息
curl -dparameter $api_url

LEAVE A COMMENT

Captcha Code