1.注册微信公众号
首先到微信公众平台https://mp.weixin.qq.com申请
然后登录,手机客户端扫描二维码,并加关注就可以了
然后就可以看到用户数

点击用户数,并点击用户,可以看到用户的tofakeid,这个ID就是zabbix将发送报警信息到这个账号。

可以在URL里看到这个ID
2.下载微信公众平台私有接口
2.1 进入zabbix报警目录,下载文件
[root@monitor ~]# cd /usr/local/share/zabbix/alertscripts [root@monitor alertscripts]# git clone https://github.com/lealife/WeiXin-Private-API Initialized empty Git repository in /usr/local/share/zabbix/alertscripts/WeiXin-Private-API/.git/ remote: Counting objects: 172, done. remote: Total 172 (delta 0), reused 0 (delta 0), pack-reused 172 Receiving objects: 100% (172/172), 36.94 KiB, done. Resolving deltas: 100% (72/72), done.
2.2 修改配置文件
[root@monitor alertscripts]# vim WeiXin-Private-API/config.php
<?php
// 全局配置
$G_ROOT = dirname(__FILE__);
$G_CONFIG["weiXin"] = array(
'account' => '微信公众登录账号',
'password' => '微信公众登录密码',
'cookiePath' => $G_ROOT. '/cache/cookie', // cookie缓存文件路径
'webTokenPath' => $G_ROOT. '/cache/webToken', // webToken缓存文件路径
);
[root@monitor alertscripts]# vim WeiXin-Private-API/test.php
<?php
require "config.php";
require "include/WeiXin.php";
$weiXin = new WeiXin($G_CONFIG['weiXin']);
$testFakeId = "$argv[1]";
$msg = "$argv[3]";
print_r($weiXin->send($testFakeId, "$msg"));
注意:这里$msg="$argv[3]"表示zabbix传入的第三个参数,因为在zabbix报警时会传入三个参数:一是微信好友ID,二是报警信息的主题,三是报警信息的具体内容,这里跳过了报警信息主题,直接发送报警信息内容
#### 2.3 创建报警脚本
[root@monitor alertscripts]# vim weixin /usr/local/php/bin/php /usr/local/share/zabbix/alertscripts/WeiXin-Private-API/test.php "$1" "$2" "$3"
2.4 修改权限
[root@monitor alertscripts]# chown www. weixin WeiXin-Private-API -R [root@monitor alertscripts]# chmod +x weixin
2.5 测试脚本
[root@monitor alertscripts]# ./weixin 353131080 "" "hello weixin"
PHP Notice: curl_setopt(): CURLOPT_SSL_VERIFYHOST with value 1 is deprecated and will be removed as of libcurl 7.28.1\. It is recommended to use value 2 instead in /usr/local/share/zabbix/alertscripts/WeiXin-Private-API/include/LeaWeiXinClient.php on line 32
Notice: curl_setopt(): CURLOPT_SSL_VERIFYHOST with value 1 is deprecated and will be removed as of libcurl 7.28.1\. It is recommended to use value 2 instead in /usr/local/share/zabbix/alertscripts/WeiXin-Private-API/include/LeaWeiXinClient.php on line 32
PHP Notice: Undefined index: HTTP_USER_AGENT in /usr/local/share/zabbix/alertscripts/WeiXin-Private-API/include/LeaWeiXinClient.php on line 33
Notice: Undefined index: HTTP_USER_AGENT in /usr/local/share/zabbix/alertscripts/WeiXin-Private-API/include/LeaWeiXinClient.php on line 33
PHP Notice: curl_setopt(): CURLOPT_SSL_VERIFYHOST with value 1 is deprecated and will be removed as of libcurl 7.28.1\. It is recommended to use value 2 instead in /usr/local/share/zabbix/alertscripts/WeiXin-Private-API/include/LeaWeiXinClient.php on line 32
Notice: curl_setopt(): CURLOPT_SSL_VERIFYHOST with value 1 is deprecated and will be removed as of libcurl 7.28.1\. It is recommended to use value 2 instead in /usr/local/share/zabbix/alertscripts/WeiXin-Private-API/include/LeaWeiXinClient.php on line 32
PHP Notice: Undefined index: HTTP_USER_AGENT in /usr/local/share/zabbix/alertscripts/WeiXin-Private-API/include/LeaWeiXinClient.php on line 33
Notice: Undefined index: HTTP_USER_AGENT in /usr/local/share/zabbix/alertscripts/WeiXin-Private-API/include/LeaWeiXinClient.php on line 33
stdClass Object
(
[base_resp] => stdClass Object
(
[ret] => 0
[err_msg] => ok
)
)
2.6 查看结果

4.测试报警
停掉mongoldb服务







