- 資訊首頁(yè) > 網(wǎng)絡(luò )安全 >
- 怎么用smokeping實(shí)現釘釘告警功能
這篇文章主要講解了“怎么用smokeping實(shí)現釘釘告警功能”,文中的講解內容簡(jiǎn)單清晰,易于學(xué)習與理解,下面請大家跟著(zhù)小編的思路慢慢深入,一起來(lái)研究和學(xué)習“怎么用smokeping實(shí)現釘釘告警功能”吧!
第一:釘釘機器人API獲取方式
釘釘開(kāi)放平臺
第二:配置smokeping調用外部 腳本進(jìn)行郵件報警
vim /opt/smokeping/etc/config *** Alerts *** #to = 88@wsfnk.com to = |/opt/smokeping/bin/mailx_alert.sh # 使用|接腳本路徑,調用外部腳本 from = smokealert@company.xy #注意:smokeping在告警的時(shí)候會(huì )發(fā)送5個(gè)參數到告警接收媒介(這里也就是我們自定義的alert腳本),參數按照順序分別為:name-of-alert, target, loss-pattern, rtt-pattern, hostname,對應下面報警腳本的$1-$5
第三:編寫(xiě)報警腳本,并附報警效果圖
如下是報警效果
cat /opt/smokeping/bin/mailx_alert.sh
#!/bin/bash ######################################################### # Script to email a ping report on alert from Smokeping # ######################################################### # 解析變量 Alertname=$1 Target=$2 Losspattern=$3 Rtt=$4 Hostname=$5 Date=$( date '+%Y-%m-%d %H:%M:%S' ) #這是smokeping報警會(huì )創(chuàng )出的$1-$5值的類(lèi)型 #A1=hightloss #B2="HK.HK-9S.9s-3 [from template]" #C3="loss: 0%, 0%, 0%, 0%, 15%, 45%, 40%" #D4="rtt: 29ms, 29ms, 29ms, 29ms, 33ms, 33ms, 33ms" #E5="1.1.1.1" # 注意:為釘釘機器人告警,重新處理變量,因為釘釘機器人告警里(變量的內容不能包含空格) #A=`echo $1 | sed 's/ //g'` case "$Alertname" in hightloss) A=hightloss-高丟包;; hostdown) A=hostdown-DOWN;; rtt-1) A=rtt-1-高延時(shí);; esac #處理變量B B=`echo $2 | sed 's/ //g'` B=`echo $B | sed 's/\[fromSH_youfu_CT_Proxy\]//g'` B=`echo $B | sed 's/\[fromtemplate\]//g'` # 這里為了報警的內容的美觀(guān),順帶將rtt:和loss:抹去了 C=`echo $3 | sed 's/ //g'` C=`echo $C | sed 's/loss://g'` D=`echo $4 | sed 's/ //g'` D=`echo $D | sed 's/rtt://g'` E=`echo $5 | sed 's/ //g'` F=`echo $Date |sed 's/ /_/g'` G=未知類(lèi)別 #定義"目標分類(lèi)的函數" Mubiao() { H=/opt/smokeping/etc/targets P=`cat -n "$H"-"$X" |grep "host = $E$" | cut -f 1 ` PP=`expr $P - 2` G=`sed -n "s/menu = //g;$PP p" $H-$X ` } #設置報警值的A端Z端,這里默認設置為 "AEND=深圳阿里云,ZEND=" #根據報警的target判斷那個(gè)機房出現報警 if [ `echo "$Target" |grep SGP | wc -l` -ne 0 ];then ZEND='新加坡' X=SGP Mubiao elif [ `echo "$Target" |grep PHI | wc -l` -ne 0 ];then ZEND='菲律賓' X=PHI Mubiao elif [ `echo "$Target" |grep HK | wc -l` -ne 0 ];then ZEND='香港' X=HK Mubiao elif [ `echo "$Target" |grep LA | wc -l` -ne 0 ];then ZEND='洛杉磯' X=LA Mubiao elif [ `echo "$Target" |grep JP | wc -l` -ne 0 ];then ZEND='日本' X=JP Mubiao elif [ `echo "$Target" |grep KOR | wc -l` -ne 0 ];then ZEND='韓國' X=KOR Mubiao elif [ `echo "$Target" |grep CD-PBS | wc -l` -ne 0 ];then ZEND='成都鵬博士' X=TG Mubiao elif [ `echo "$Target" |grep BJ-SJQ | wc -l` -ne 0 ];then ZEND='北京四季青' X=TG Mubiao elif [ `echo "$Target" |grep SH-YF | wc -l` -ne 0 ];then ZEND='有孚雙線(xiàn)' X=TG Mubiao elif [ `echo "$Target" |grep SZ-YX | wc -l` -ne 0 ];then ZEND='深圳易信' X=TG Mubiao elif [ `echo "$Target" |grep SZ-PBS | wc -l` -ne 0 ];then ZEND='深圳鵬博士' X=TG Mubiao elif [ `echo "$Target" |grep TG-YN | wc -l` -ne 0 ];then ZEND='越南' X=TG Mubiao else [ `echo "$Target" |grep DNS | wc -l` -ne 0 ] ZEND='DNS' X=DNS Mubiao fi #根據報警的target判斷是否報警源位置(smokeping_salve的主機名) if [ `echo "$Target" |grep SH_youfu | wc -l` -ne 0 ];then AEND='有孚雙線(xiàn)' elif [ `echo "$Target" |grep template | wc -l` -ne 0 ];then AEND='陜西聯(lián)通' else AEND='深圳阿里云' # mtr -r -n $Hostname >> /tmp/mtr.txt # echo '++++++++++++' >> /tmp/mtr.txt fi #釘釘二號機器人API #https://oapi.dingtalk.com/robot/send?access_token=6c1712241129c425e5385d7d164ffe1ed4d4663b0651c4e #釘釘三號機器人API #https://oapi.dingtalk.com/robot/send?access_token=98ce2cf2925eb0b960745b449ee63a9917571a650f6e7ca4b323f73c7 ####################釘釘機器人告警執行部分####################### # 注意:為釘釘機器人告警,重新處理變量,因為釘釘機器人告警里(變量的內容不能包含空格) curl 'https://oapi.dingtalk.com/robot/send?access_token=6c1712241129c425e5385d7d164ffe1ed4d4663b065b50bf' \ -H 'Content-Type: application/json' \ -d ' { "msgtype": "text", "text": { "content":"('$AEND'-'$ZEND')網(wǎng)絡(luò )告警 告警策略:'$A' 目標類(lèi)別:'$G' 目標名稱(chēng):'$B' 丟包率:'$C' 延 遲:'$D' 目標地址:'$E' 故障時(shí)間:'$F'" }, "at": { "atMobiles": [ "182****8240" ], "isAtAll": false } }' #>> /tmp/dingding-alert.log 2>&1 #####################郵件告警調用執行部分,這里暫不使用,只記錄到日志文件####################### #zhuti="打碼 ($AEND-$ZEND) 網(wǎng)絡(luò )質(zhì)量告警" #messages=`echo -e " 報警策略名: \t $Alertname \n 報警目標: \t $Target \n 丟包率: \t $Losspattern \n 延遲時(shí)間: \t $Rtt \n 主機地址: \t$Hostname \n 報警時(shí)間: \t$Date "` #email="zhsd@www.com" echo "$Date -- $Alertname -- $Target -- $Losspattern -- $Rtt -- $Hostname" >> /tmp/smokeping-baojin #echo "$messages" | mail -s "$zhuti" $email >>/tmp/mailx.log 2>&1
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自互聯(lián)網(wǎng)轉載和分享為主,文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權請聯(lián)系QQ:712375056 進(jìn)行舉報,并提供相關(guān)證據,一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容。
Copyright ? 2009-2021 56dr.com. All Rights Reserved. 特網(wǎng)科技 特網(wǎng)云 版權所有 珠海市特網(wǎng)科技有限公司 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2
建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站