#!/bin/bash
# 使用方法:
# sh feishu_notify.sh "
" "" "" "" ""
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 并重启。"