Cacti微信企业号图文报警

首先申请企业号获取对应应用中的CropID和Secret以及应用ID

这部分后面再进行添加

也可参考

http://wuhf2015.blog.51cto.com/8213008/1688614

中的内容进行设置

1、将cacti中thold的报警内容导出至文本文件进行保存

进入cacti主目录

vi plugins/thold/thold_functions.php

查找mailer。在如下位置插入后面的的语句

wKiom1Z-YYyggaCcAANQ1VRraWI313.jpg650) this.width=650;" src="https://images.winkp.com/imgs/winkp/_winkp/2023/08/2265707133309576632.jpg" title="php.jpg" class="aligncenter">

$msg_wx = strip_tags(str_replace(‘<br>‘, "\n", $message));//删除message中的html标签,并将<br>替换为换行符\n        $msg_wx = trim($msg_wx);//整理msg_wx字符串$file_title  = ‘/tmp/title.txt‘;//要写入文件的文件名(可以是任意文件名),如果文件不存在,将会创建一个$file_message  = ‘/tmp/message.txt‘;//要写入文件的文件名(可以是任意文件名),如果文件不存在,将会创建一个if($f  = file_put_contents($file_title, $subject)){//将subject参数的值保存到file_title中 }if($f  = file_put_contents($file_message,  $msg_wx)){//将msg_wx参数的值保存到file_message中 }shell_exec("/etc/wechat.sh");

然后创建微信发送脚本

vi /etc/wechat.shchmod 750 /etc/wechat.sh

输入如下内容

#微信企业号发送消息脚本#By:Fenei QQ:407603129#2015年12月26日#转载请注明出处#http://babyfenei.blog.51cto.com/443861/1728604#!/bin/bashCropID=‘企业号ID‘#此处为企业号IDSecret=‘企业号密钥‘#此处为企业号密钥GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CropID&corpsecret=$Secret"Gtoken=$(/usr/bin/curl -s -G $GURL | awk -F\" ‘{print $4}‘)PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Gtoken"function body() {local int AppID=11#此处为你所创建的消息型应用的ID号local UserID=fenei#此处为你所要发送的用户号local PartyID=1#此处为你所要发送的部门IDlocal TagID=2#此处为你所要发送的标签IDTit=$(cat /tmp/title.txt)#读取/tmp/title文件中内容到变量TitMsg=$(cat /tmp/message.txt)#读取/tmp/message文件中内容到变量MsgUrl=$(grep  "http" /tmp/message.txt|sed  ‘s/URL: //g‘)#获取message.txt中的url行内容到变量UrlPic=$(grep  "http" /tmp/message.txt|sed  ‘s/URL: //g‘|sed ‘s/graph.php/graph_image.php/g‘)#根据url行内容修改为添加Pic参数printf ‘{\n‘printf ‘\t"touser": "‘"$User"\"",\n"printf ‘\t"toparty": "‘"$PartyID"\"",\n"printf ‘\t"totag": "‘"$TagID"\"",\n"printf ‘\t"msgtype": "news",\n‘printf ‘\t"agentid": "‘" $AppID "\"",\n"printf ‘\t"news": {\n‘printf ‘\t"articles": [\n‘printf ‘{\n‘printf ‘\t\t"title": "‘"$Tit"\","\n"printf ‘\t\t"description": "‘"$Msg"\","\n"printf ‘\t\t"url": "‘"$Url"\","\n"printf ‘\t\t"picurl": "‘"$Pic"\","\n"printf ‘\t}\n‘printf ‘\t]\n‘printf ‘\t}\n‘printf ‘}\n‘}/usr/bin/curl --data-ascii "$(body )" $PURL

3 修改graph_img.php文件,取消graph_image.php的认证。

  否则微信无法正常显示图片

#include("./include/auth.php");include_once("./lib/rrd.php");include("./include/global.php");

wKioL1Z-ZaaCvnecAAaYqS5FnqE816.jpg650) this.width=650;" src="https://images.winkp.com/imgs/winkp/_winkp/2023/08/1625932149527020802.jpg" title="weixin.jpg" class="aligncenter">

本文出自 “www.fenei.com” 博客,请务必保留此出处http://babyfenei.blog.51cto.com/443861/1728604

相关文章