Cacti auth.php,Cacti微信企业号图文报警
首先申請(qǐng)企業(yè)號(hào)獲取對(duì)應(yīng)應(yīng)用中的CropID和Secret以及應(yīng)用ID
這部分后面再進(jìn)行添加
也可參考
http://wuhf2015.blog.51cto.com/8213008/1688614
中的內(nèi)容進(jìn)行設(shè)置
1、將cacti中thold的報(bào)警內(nèi)容導(dǎo)出至文本文件進(jìn)行保存
進(jìn)入cacti主目錄
vi?plugins/thold/thold_functions.php
查找mailer。在如下位置插入后面的的語句
$msg_wx?=?strip_tags(str_replace('
',?"\n",?$message));//刪除message中的html標(biāo)簽,并將
替換為換行符\n
$msg_wx?=?trim($msg_wx);//整理msg_wx字符串
$file_title??=?'/tmp/title.txt';//要寫入文件的文件名(可以是任意文件名),如果文件不存在,將會(huì)創(chuàng)建一個(gè)
$file_message??=?'/tmp/message.txt';//要寫入文件的文件名(可以是任意文件名),如果文件不存在,將會(huì)創(chuàng)建一個(gè)
if($f??=?file_put_contents($file_title,?$subject)){//將subject參數(shù)的值保存到file_title中
}
if($f??=?file_put_contents($file_message,??$msg_wx)){//將msg_wx參數(shù)的值保存到file_message中
}
shell_exec("/etc/wechat.sh");
然后創(chuàng)建微信發(fā)送腳本
vi?/etc/wechat.sh
chmod?750?/etc/wechat.sh
輸入如下內(nèi)容
#微信企業(yè)號(hào)發(fā)送消息腳本
#By:Fenei?QQ:407603129
#2015年12月26日
#轉(zhuǎn)載請(qǐng)注明出處
#http://babyfenei.blog.51cto.com/443861/1728604
#!/bin/bash
CropID='企業(yè)號(hào)ID'
#此處為企業(yè)號(hào)ID
Secret='企業(yè)號(hào)密鑰'
#此處為企業(yè)號(hào)密鑰
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
#此處為你所創(chuàng)建的消息型應(yīng)用的ID號(hào)
local?UserID=fenei
#此處為你所要發(fā)送的用戶號(hào)
local?PartyID=1
#此處為你所要發(fā)送的部門ID
local?TagID=2
#此處為你所要發(fā)送的標(biāo)簽ID
Date=$(date?'+%Y年%m月%d日?%H:%M:%S\n')
#應(yīng)cactifans群內(nèi)要求,添加Cacti微信報(bào)警日期參數(shù)
Tit=$(cat?/tmp/title.txt)
#讀取/tmp/title文件中內(nèi)容到變量Tit
Msg=$Date$(cat?/tmp/message.txt)
#讀取/tmp/message文件中內(nèi)容到變量Msg
Url=$(grep??"http"?/tmp/message.txt|sed??'s/URL:?//g')
#獲取message.txt中的url行內(nèi)容到變量Url
Pic=$(grep??"http"?/tmp/message.txt|sed??'s/URL:?//g'|sed?'s/graph.php/graph_image.php/g')
#根據(jù)url行內(nèi)容修改為添加Pic參數(shù)
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的認(rèn)證。
否則微信無法正常顯示圖片
#include("./include/auth.php");
include_once("./lib/rrd.php");
include("./include/global.php");
總結(jié)
以上是生活随笔為你收集整理的Cacti auth.php,Cacti微信企业号图文报警的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: oracle的脚本语言,Oracle 无
- 下一篇: 127.0.0.1/dokuwiki/i