发送消息到飞书告警脚本
来源:原创
时间:2024-09-07
作者:脚本小站
分类:SHELL
发送消息到飞书:
#!/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
- 使用curl在harbor创建镜像仓库
- shell编程,定期执行脚本cron,crontab,anacron,定时任务
- shell编程,正则表达式BRE模式,ERE模式
- shell编程,处理用户输入,选项和参数的处理getopts,shift,常见的linux命令选项
- shell编程,if-then、else,case,数值、字符串、文件类型比较检测,[ ],(()),[[ ]]
- shell编程,在/tmp中创建临时文件或目录,mktemp
- jar包自启动脚本
- docker部署elk mysql redis rabbitmq mongo nacos
- shell编程,命令替换$(),<输入重定向,<<内联输入重定向,>输出重定向,>>追加输出重定
- shell编程,以后台模式运行进程,bg、fg、jobs -l、nohup、&