-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdisk_check.sh
36 lines (29 loc) · 1013 Bytes
/
disk_check.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
# Telegram Configuration
BOT_TOKEN="" # Telegram bot token
CHAT_ID="" # Group ID
THREAD_ID="" # Thread ID within the group
# Function to send Telegram notification
send_tg_message() {
local message=$1
curl -s -X POST "https://api.telegram.org/bot${BOT_TOKEN}/sendMessage" \
-d chat_id="${CHAT_ID}" \
-d message_thread_id="${THREAD_ID}" \
-d text="${message}" \
-d parse_mode="HTML"
}
# Disk check
# Get free space on root partition in gigabytes
FREE_SPACE=$(df -BG / | awk 'NR==2 {print $4}' | sed 's/G//')
# Check free disk space
if [ ${FREE_SPACE} -lt 100 ]; then
# Prepare Telegram notification
DISK_ALERT="⚠️ Critical low disk space on $(hostname)!
Free: ${FREE_SPACE}GB
Threshold: 100GB
❗️ Disk cleanup required!"
# Send Telegram notification
send_tg_message "$DISK_ALERT"
# Log critical event to system log
logger "Disk Monitor: Free space is below 100GB (Current: ${FREE_SPACE}GB)"
fi