指令碼如下:
#!/bin/bash
#釘釘告警函數
function SendMessageToDingding(){
url="https://oapi.dingtalk.com/robot/send?access_token=4901cd7eceeaf6d1977f0367d4d1ac29e56e9852b1564ee326a417995b3464564"
res=`curl -XPOST -s -L -H "Content-Type:application/json" -H "charset:utf-8" $url -d "
{
"msgtype": "text",
"text": {
"content": "$1\n$2"
}
}"`
echo $res
}
subject=$hostname
time=$(date "+%Y-%m-%d %H:%M:%S")
host=$hostname
ip=`ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d '/'`
body="DB告警\n報警時間:$time\n主機地址:$ip\n告警內容:ogg故障"
(echo info all;echo exit)|/data/ogg/ggsci|grep -E "EXTRACT|REPLICAT" |awk 'BEGIN {FS=" +"} {print $1,$3,$2,$4,$5}'>> /tmp/1.log
VALUE=`cat /tmp/1.log|grep "ABEND"|wc -l`
if [ "$VALUE" -gt 0 ]; then
body="DB告警\n報警時間:$time\n主機地址:$ip\n告警內容:ogg故障-ABEND"
SendMessageToDingding $subject $body
fi
VALUE=`cat /tmp/1.log|grep "STOPPED"|wc -l`
if [ "$VALUE" -gt 0 ]; then
body="DB告警\n報警時間:$time\n主機地址:$ip\n告警內容:ogg故障-STOPPED"
SendMessageToDingding $subject $body
fi
tail -20 /data/ogg/ggserr.log >/tmp/ogg_err.log
VALUE=`cat /tmp/ogg_err.log|grep "ERROR"|wc -l`
if [ "$VALUE" -gt 0 ]; then
body="DB告警\n報警時間:$time\n主機地址:$ip\n告警內容:ogg故障-errorlog"
SendMessageToDingding $subject $body
fi
釘釘告警如下:
企業微信告警如下: