发送消息到飞书:

#!/bin/bash


function sendmsgtofeishu {
    CONTENT=$1
    #飞书机器人webhook 地址
    API=https://open.feishu.cn/open-apis/bot/v2/hook/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx
    curl -X POST $API -H 'Content-Type: application/json' \
    -d '{"msg_type": "post","content": {"post": {"zh_cn": {"title": "“请问什么是红三兵”的告警","content": [[{"tag": "text","text": "'$CONTENT'"}],[]]}}}}'
}



# 每次轮询间隔
export SLEEP_TIME=60


while true
do

#USER_ID="12345"
#PACKAGE_ID="123450001111"

USER_ID=$(printf "%05d" $((RANDOM % 100000)))
PACKAGE_ID=$(printf "%012d" $((RANDOM % 1000000000000)))

START_TIME=$(date +%s%3N)
curl --location --request POST 'https://b-openapi.xxxxxx.com/scp/v1/risk/rich_text' \
--header 'Authorization: Bearerscp-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' \
--header 'User-Agent: Apifox/1.0.0(https://apifox.com)' \
--header 'Content-Type: application/json' \
--data "{
	'user_info':{'user_id':${USER_ID}},
	'package_id':${PACKAGE_ID},
	'biz_type':'guojun',
	'resources':[
		{
			'id':'123450001111',
			'name':'用户描述',
			'context':'你好',
			'type':'TEXT',
			'scene':'guojun:prompt'
		}
	]
}"

END_TIME=$(date +%s%3N)
ELAPSED_TIME=$((END_TIME - START_TIME))

if [ "$ELAPSED_TIME" -gt 20 ]; then
    sendmsgtofeishu "执行时间:\t${ELAPSED_TIME}毫秒\nuser_id:\t${USER_ID}\npackage_id:${PACKAGE_ID}"
    echo "执行时间: $ELAPSED_TIME 毫秒"
else
    echo "执行时间: $ELAPSED_TIME 毫秒"
fi

sleep $SLEEP_TIME
done