mirror of
https://github.com/kejilion/sh.git
synced 2025-10-03 23:34:20 +08:00
Update CF-Under-Attack.sh
This commit is contained in:
parent
2d650e94e6
commit
f02b7b8d59
1 changed files with 13 additions and 0 deletions
|
@ -6,12 +6,23 @@ API_KEY="BBBB"
|
|||
ZONE_ID="CCCC"
|
||||
LOAD_THRESHOLD=5.0 # 设置高负载阈值
|
||||
|
||||
TELEGRAM_BOT_TOKEN="输入TG机器人API"
|
||||
CHAT_ID="输入TG用户ID"
|
||||
|
||||
|
||||
# 获取当前系统负载
|
||||
CURRENT_LOAD=$(uptime | awk -F'load average:' '{ print $2 }' | cut -d, -f1 | awk '{print $1}')
|
||||
|
||||
echo "当前系统负载: $CURRENT_LOAD"
|
||||
|
||||
|
||||
send_tg_notification() {
|
||||
local MESSAGE=$1
|
||||
curl -s -X POST "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage" -d "chat_id=$CHAT_ID" -d "text=$MESSAGE"
|
||||
}
|
||||
|
||||
|
||||
|
||||
# 获取当前的“Under Attack”模式状态
|
||||
STATUS=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/settings/security_level" \
|
||||
-H "X-Auth-Email: $EMAIL" \
|
||||
|
@ -24,6 +35,7 @@ echo "当前的Under Attack模式状态: $STATUS"
|
|||
if (( $(echo "$CURRENT_LOAD > $LOAD_THRESHOLD" | bc -l) )); then
|
||||
if [ "$STATUS" != "under_attack" ]; then
|
||||
echo "系统负载高于阈值,开启Under Attack模式"
|
||||
# send_tg_notification "系统负载高于阈值,开启Under Attack模式"
|
||||
NEW_STATUS="under_attack"
|
||||
else
|
||||
echo "系统负载高,但Under Attack模式已经开启"
|
||||
|
@ -32,6 +44,7 @@ if (( $(echo "$CURRENT_LOAD > $LOAD_THRESHOLD" | bc -l) )); then
|
|||
else
|
||||
if [ "$STATUS" == "under_attack" ]; then
|
||||
echo "系统负载低于阈值,关闭Under Attack模式"
|
||||
# send_tg_notification "系统负载低于阈值,关闭Under Attack模式"
|
||||
NEW_STATUS="high"
|
||||
else
|
||||
echo "系统负载低,Under Attack模式已经关闭"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue