已測試版本:0.88b
1.一樣編緝thold_functions.php,找到「function thold_mail」這個 Function,在最後的「return '';」上方加入以下程式碼:
2.把 your_line_token 改成自己使用的 token
/* LINE訊息告警 */
list($a,$b) = explode("Message:",$text['text']);
$ttime=date("Y/m/d h:i:sa");
if ($b != '') {
$content=trim("$b")."\n"."\n".$ttime;
}else{
$content=$subject;
}
if ($data != '') {
$ffile = fopen("/tmp/qq.jpg","w+");
fwrite($ffile,$data);
fclose($ffile);
$linefields = array('message' => $content,
'imageFile' => curl_file_create('/tmp/qq.jpg'));
}else{
$linefields = array('message' => $content);
}
$ch = curl_init();
$lineurl="https://notify-api.line.me/api/notify" ;
$linehead=array("Content-Type: multipart/form-data",
"Authorization: Bearer your_line_token");
curl_setopt($ch, CURLOPT_URL, $lineurl);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $linehead);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $linefields);
curl_exec($ch);
curl_close($ch);
if(file_exists('/tmp/qq.jpg')){
unlink('/tmp/qq.jpg');
}
上面程式放到 github 上,方便複製
https://github.com/zhuccc/cacti_thold_line
Ref:
新添LINE訊息告警 Cacti網管更即時
CACTI Alert 增加 LineNotify
0 意見:
張貼留言