Files
Work-configuration-file/sh/weblessie-server-01/feishu_notify.sh
2025-11-26 14:11:03 +08:00

50 lines
1.4 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 使用方法:
# sh feishu_notify.sh "<title>" "<host>" "<program>" "<level>" "<detail>"
WEBHOOK="https://open.feishu.cn/open-apis/bot/v2/hook/c14d9964-3b5e-402a-866e-42768aa45e5e"
TITLE="$1" # 标题
HOST="$2" # 主机
PROGRAM="$3" # 程序
LEVEL="$4" # 级别,飞书卡片 header 颜色info / warning / danger
DETAIL="$5" # 详情内容Markdown
TIME=$(date +"%Y-%m-%d %H:%M:%S")
curl -s -X POST \
-H "Content-Type: application/json" \
-d "{
\"msg_type\": \"interactive\",
\"card\": {
\"header\": {
\"template\": \"${LEVEL}\",
\"title\": {
\"content\": \"${TITLE}\",
\"tag\": \"plain_text\"
}
},
\"elements\": [
{
\"tag\": \"div\",
\"text\": {
\"tag\": \"lark_md\",
\"content\": \"**主机:** ${HOST}\n**程序:** ${PROGRAM}\n**级别:** ${LEVEL}\n**时间:** ${TIME}\n\n${DETAIL}\"
}
}
]
}
}" \
"$WEBHOOK" >/dev/null 2>&1
# 调用示例
# sh /data/sh/feishu_notify.sh \
# "⚠️ Python 内存告警" \
# "$(hostname)" \
# "lessie_sourcing_agents_s5(8000)" \
# "danger" \
# "**内存占用**: ${usage}MB\n已自动 kill 并重启。"