溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

怎么用smokeping實現(xiàn)釘釘告警功能

發(fā)布時間:2021-09-10 07:37:15 來源:億速云 閱讀:155 作者:chen 欄目:網(wǎng)絡(luò)安全

這篇文章主要講解了“怎么用smokeping實現(xiàn)釘釘告警功能”,文中的講解內(nèi)容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“怎么用smokeping實現(xiàn)釘釘告警功能”吧!

第一:釘釘機器人API獲取方式

釘釘開放平臺

第二:配置smokeping調(diào)用外部 腳本進行郵件報警

vim /opt/smokeping/etc/config
*** Alerts ***
#to = 88@wsfnk.com
to = |/opt/smokeping/bin/mailx_alert.sh		# 使用|接腳本路徑,調(diào)用外部腳本
from = smokealert@company.xy
#注意:smokeping在告警的時候會發(fā)送5個參數(shù)到告警接收媒介(這里也就是我們自定義的alert腳本),參數(shù)按照順序分別為:name-of-alert, target, loss-pattern, rtt-pattern, hostname,對應下面報警腳本的$1-$5

第三:編寫報警腳本,并附報警效果圖

如下是報警效果
怎么用smokeping實現(xiàn)釘釘告警功能
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報警會創(chuàng)出的$1-$5值的類型
#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"
# 注意:為釘釘機器人告警,重新處理變量,因為釘釘機器人告警里(變量的內(nèi)容不能包含空格)
#A=`echo $1 | sed 's/ //g'`
	case "$Alertname" in
	hightloss)
		A=hightloss-高丟包;;
	hostdown)
		A=hostdown-DOWN;;
	rtt-1)
		A=rtt-1-高延時;;
	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'`
#  這里為了報警的內(nèi)容的美觀,順帶將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=未知類別
#定義"目標分類的函數(shù)"
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 `
}
#設(shè)置報警值的A端Z端,這里默認設(shè)置為	"AEND=深圳阿里云,ZEND=DNS"
#根據(jù)報警的target判斷那個機房出現(xiàn)報警
        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='有孚雙線'
		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
#根據(jù)報警的target判斷是否報警源位置(smokeping_salve的主機名)
        if [ `echo "$Target" |grep SH_youfu | wc -l`  -ne 0 ];then
                AEND='有孚雙線'
          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
####################釘釘機器人告警執(zhí)行部分#######################
# 注意:為釘釘機器人告警,重新處理變量,因為釘釘機器人告警里(變量的內(nèi)容不能包含空格)
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'
目標類別:'$G'
目標名稱:'$B'
丟包率:'$C'
延 遲:'$D'
目標地址:'$E'
故障時間:'$F'"
    },
     "at": {
         "atMobiles": [
             "182****8240"
         ], 
         "isAtAll": false
     }
}'
#>> /tmp/dingding-alert.log  2>&1
#####################郵件告警調(diào)用執(zhí)行部分,這里暫不使用,只記錄到日志文件#######################
#zhuti="打碼 ($AEND-$ZEND) 網(wǎng)絡(luò)質(zhì)量告警"
#messages=`echo -e " 報警策略名: \t $Alertname \n 報警目標: \t $Target \n 丟包率: \t $Losspattern  \n 延遲時間: \t $Rtt \n 主機地址: \t$Hostname \n 報警時間: \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

感謝各位的閱讀,以上就是“怎么用smokeping實現(xiàn)釘釘告警功能”的內(nèi)容了,經(jīng)過本文的學習后,相信大家對怎么用smokeping實現(xiàn)釘釘告警功能這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關(guān)知識點的文章,歡迎關(guān)注!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI