Cacti auth.php,Cacti微信企业号图文报警
首先申請企業號獲取對應應用中的CropID和Secret以及應用ID
這部分后面再進行添加
也可參考
http://wuhf2015.blog.51cto.com/8213008/1688614
中的內容進行設置
1、將cacti中thold的報警內容導出至文本文件進行保存
進入cacti主目錄
vi?plugins/thold/thold_functions.php
查找mailer。在如下位置插入后面的的語句
$msg_wx?=?strip_tags(str_replace('
',?"\n",?$message));//刪除message中的html標簽,并將
替換為換行符\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.sh
chmod?750?/etc/wechat.sh
輸入如下內容
#微信企業號發送消息腳本
#By:Fenei?QQ:407603129
#2015年12月26日
#轉載請注明出處
#http://babyfenei.blog.51cto.com/443861/1728604
#!/bin/bash
CropID='企業號ID'
#此處為企業號ID
Secret='企業號密鑰'
#此處為企業號密鑰
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
#此處為你所要發送的部門ID
local?TagID=2
#此處為你所要發送的標簽ID
Date=$(date?'+%Y年%m月%d日?%H:%M:%S\n')
#應cactifans群內要求,添加Cacti微信報警日期參數
Tit=$(cat?/tmp/title.txt)
#讀取/tmp/title文件中內容到變量Tit
Msg=$Date$(cat?/tmp/message.txt)
#讀取/tmp/message文件中內容到變量Msg
Url=$(grep??"http"?/tmp/message.txt|sed??'s/URL:?//g')
#獲取message.txt中的url行內容到變量Url
Pic=$(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");
總結
以上是生活随笔為你收集整理的Cacti auth.php,Cacti微信企业号图文报警的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: oracle的脚本语言,Oracle 无
- 下一篇: oracle驱动权限如何修改,详解如何实