一、环境
cat /etc/redhat-release
操作系统:CentOS Linux release 7.3.1611 (Core)
Zabbix软件版本:zabbix_server (Zabbix) 3.2.9
二、安装所需包
yum install lrzsz chrony gcc gcc-c++ git openssl-devel perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker -y
systemctl enable chronyd
systemctl start chronyd
三、安装Mojo-Webqq
curl -L https://cpanmin.us/ -o /usr/bin/cpanm && chmod +x /usr/bin/cpanm
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
cpanm Mojo::SMTP::Client MIME::Lite
cd /usr/src/ && git clone https://github.com/sjdy521/Mojo-Webqq.git
cd Mojo-Webqq/ && perl Makefile.PL
make && make install
vim /usr/local/bin/MojoWebqq.pl
#!/usr/bin/env perl
use Mojo::Webqq;
my ($host,$port,$post_api);
$host = "0.0.0.0";
$qq = "717639097";
$port = 5000;
my $client = Mojo::Webqq->new(qq=>$qq);
$client->load("PostQRcode",data=>{
smtp => 'smtp.qq.com',
port => '25',
from => '717639097@qq.com',
to => '717639097@qq.com',
user => '717639097@qq.com',
pass => '17050096438',
});
$client->login();
#$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
后台启动Mojo-Webqq进程
/usr/local/bin/MojoWebqq.pl >>/var/log/zabbix/zabbix-Mojo-Webqq.log 2>&1 &
tail -f /var/log/zabbix/zabbix-Mojo-Webqq.log
<span style="white-space:pre"> </span>(Missing semicolon on previous line?)
syntax error at /usr/local/bin/MojoWebqq.pl line 14, near "pass => '"
Execution of /usr/local/bin/MojoWebqq.pl aborted due to compilation errors.
[17/10/29 20:36:43] [info] 当前正在使用 Mojo-Webqq v2.1.4
[17/10/29 20:36:43] [info] 执行插件[ Mojo::Webqq::Plugin::PostQRcode ]
[17/10/29 20:36:43] [info] 初始化 smartqq 客户端参数...
[17/10/29 20:36:43] [info] 正在获取登录二维码...
[17/10/29 20:36:44] [info] 二维码已下载到本地[ /tmp/mojo_webqq_qrcode_default.png ]
[17/10/29 20:36:44] [info] 登录二维码已经发送到邮箱: 10880347@qq.com
[17/10/29 20:36:44] [info] 等待手机QQ扫描二维码...
这样会发一个邮件到邮箱,里面又二维码要扫描:
vim zabbix_qq.sh
qq=$1
server="172.16.8.111"
port="5000"
message=`echo -e "$2\n$3"|od -t x1 -A n -v -w1000000000 | tr " " %`
api_url="http://$server:$port/openqq/send_group_message"
parameter="uid=$qq&content=$message"
#CURL=`curl -d $parameter $api_url`
curl -d $parameter $api_url
测试结果
qq上会收到邮件告警
如果出现该问题:
root@localhost Mojo-Webqq]# tail -f /var/log/zabbix/zabbix-Mojo-Webqq.log
[17/12/24 05:33:24] [info] 当前正在使用 Mojo-Webqq v2.1.4
[17/12/24 05:33:24] [info] 执行插件[ Mojo::Webqq::Plugin::PostQRcode ]
[17/12/24 05:33:24] [info] 初始化 smartqq 客户端参数...
[17/12/24 05:33:24] [info] 正在获取登录二维码...
[17/12/24 05:33:25] [info] 二维码已下载到本地[ /tmp/mojo_webqq_qrcode_default.png ]
[17/12/24 05:33:25] [error] 插件[Mojo::Webqq::Plugin::PostQRcode]邮件发送失败: Error: A secure connection is requiered(such as ssl). More information at http://service.mail.qq.com/cgi-bin/help?id=28
[17/12/24 05:33:25] [info] 等待手机QQ扫描二维码...
[17/11/21 17:20:32] [error] 发送邮件,请先安装模块 Mojo::SMTP::Client
[17/11/21 17:20:32] [error] 插件[Mojo::Webqq::Plugin::PostQRcode]邮件发送失败:
解决办法
cpanm Mojo::SMTP::Client MIME::Lite --force