-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDMSE_status.sh
More file actions
executable file
·200 lines (180 loc) · 14.1 KB
/
DMSE_status.sh
File metadata and controls
executable file
·200 lines (180 loc) · 14.1 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/bin/bash
# ============================================================================================================
# Script Name: DMSE_status.sh
# Author: CtrlAltJon
# Descrizione: Sends a status message about the console Unifi Dream Machine to a Telegram channel
#
# Copyright (c) 2025 CtrlAltJon
# Rilasciato sotto licenza MIT (https://opensource.org/licenses/MIT)
# ============================================================================================================
#
# Usage: DMSE_status.sh
#
# ============================================================================================================
# --- FUNCTION ---------------------------------------------------------- Escape Markdown --------------------
# ------------------------------------------------------------------------------------------------------------
# Function to escape MarkdownV2 special characters for Telegram.
escape_markdown() {
local text="$1"
text="${text//\\/\\\\}" # <<<<<< Escape backslash first
text="${text//\./\\\.}"
text="${text//\!/\\\!}"
#text="${text//\(/\\\(}"
#text="${text//\)/\\\)}"
#text="${text//\[/\\\[}"
#text="${text//\]/\\\]}"
text="${text//\-/\\\-}"
#text="${text//\%/\\\%}"
#text="${text//\_/\\\_}"
#text="${text//\*/\\\*}"
#text="${text//\~/\\\~}"
#text="${text//\`/\\\`}"
text="${text//\>/\\\>}"
text="${text//\#/\\\#}"
text="${text//\+/\\\+}"
text="${text//\=/\\\=}"
#text="${text//\|/\\\|}"
text="${text//\{/\\\{}"
text="${text//\}/\\\}}"
printf '%s' "$text"
}
# ----------------------------------------------------------------------- Variables initialization -----------
# ------------------------------------------------------------------------------------------------------------
SILENT_NOTIFICATION=false # Set to true to send telegram silent notifications
BOT_TOKEN="0000000000:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # Telegram bot token
CHAT_ID="-000000000000" # Telegram chat ID
VAR_DOTS=".................................................." # Dots for line padding
VAR_WIDTH=30 # Width of the output text lines
IPfile="/path/to/file/IP.txt" # File on the console containing the Public IP address.
# You may have an external script that updates this file.
if [[ -f "$IPfile" ]]; then # If the file exists
read -r VAR_IP < "$IPfile" # Read the Public IP address from the file
else
VAR_IP="Unknown"
fi
# System
VAR_FIRM=$(ubnt-device-info firmware) # Get the firmware version of the device
VAR_UPTIME=$(uptime -p) # Get the system uptime in a human-readable format
VAR_MAC=$(ubnt-device-info mac) # Get the MAC address of the device
# CPU
VAR_LOADAVG1=$(uptime | awk '{ print $10 }') # Get the 1-minute load average
VAR_LOADAVG5=$(uptime | awk '{ print $11 }') # Get the 5-minute load average
VAR_LOADAVG15=$(uptime | awk '{ print $12 }') # Get the 15-minute load average
VAR_CPULOAD=$(ubnt-systool cpuload) # Get the CPU load percentage
VAR_CPUTEMP=$(ubnt-systool cputemp) # Get the CPU temperature
# Disks (For other installed drives, complete with your own code)
VAR_SDA_BRAND=$(hddtemp /dev/sda | awk '{ print $2 }') # Get the brand of the hard drive
VAR_SDA_MODEL=$(hddtemp /dev/sda | awk '{ print $3 }') # Get the model of the hard drive
VAR_SDA_TEMP=$(hddtemp /dev/sda | awk '{ print $4 }') # Get the temperature of the hard drive
# Hardware
VAR_MBTEMP=$(sensors | grep "Board Temp" | awk '{ print $3 }') # Get the motherboard temperature
VAR_FANSPEED=$(sensors | grep "fan2" | awk '{ print $2 }') # Get the fan speed
# Memory
VAR_MEMTOT=$(free -h | grep "Mem" | awk '{ print $2 }') # Get the total memory
VAR_MEMUSED=$(free -h | grep "Mem" | awk '{ print $3 }') # Get the used memory
# Disks Usage
VAR_DISK1_TOT=$(df -h | grep "overlayfs-root" | awk '{ print $2 }') # Get the total space on the OS partition
VAR_DISK1_USED=$(df -h | grep "overlayfs-root" | awk '{ print $3 }') # Get the used space on the OS partition
VAR_DISK1_PERC=$(df -h | grep "overlayfs-root" | awk '{ print $5 }') # Get the percentage used on the OS partition
VAR_DISK2_TOT=$(df -h | grep "ssd1" | awk '{ print $2 }') # Get the total space on the data partition
VAR_DISK2_USED=$(df -h | grep "ssd1" | awk '{ print $3 }') # Get the used space on the data partition
VAR_DISK2_PERC=$(df -h | grep "ssd1" | awk '{ print $5 }') # Get the percentage used on the data partition
# ----------------------------------------------------------------------- Main -------------------------------
# ------------------------------------------------------------------------------------------------------------
TEXT="*DMSE - System Status* %E2%84%B9%0A" # Start the message with the title
TEXT+="\`\`\`" # Start a code block for formatting
TEXT+="%0A${VAR_UPTIME}" # Add the system uptime
TEXT+="%0A%0A %F0%9F%92%BB HARDWARE" # Add a section header for hardware
TEXT+="%0A" # New line
TEXT+="MB Temp" # Add the motherboard temperature
Tmp=$(( VAR_WIDTH - 5 - ${#VAR_MBTEMP} )) # Calculate the padding needed
TEXT+="${VAR_DOTS:0:$Tmp}" # Add dots for padding
TEXT+=" ${VAR_MBTEMP:1}°C" # Add the temperature value (removing the first character)
TEXT+="%0A" # New line
TEXT+="CPU Temp" # Add the CPU temperature
Tmp=$(( VAR_WIDTH - 7 - ${#VAR_CPUTEMP} )) # Calculate the padding needed
TEXT+="${VAR_DOTS:0:$Tmp}" # Add dots for padding
TEXT+=" ${VAR_CPUTEMP}°C" # Add the temperature value
TEXT+="%0A" # New line
TEXT+="FAN Speed" # Add the fan speed
Tmp=$(( VAR_WIDTH - 10 - ${#VAR_FANSPEED} )) # Calculate the padding needed
TEXT+="${VAR_DOTS:0:$Tmp}" # Add dots for padding
TEXT+=" ${VAR_FANSPEED} RPM" # Add the fan speed value
TEXT+="%0A%0A %F0%9F%93%84 SOFTWARE" # Add a section header for software
TEXT+="%0A" # New line
TEXT+="Firmware" # Add the firmware version
Tmp=$(( VAR_WIDTH - 5 - ${#VAR_FIRM} )) # Calculate the padding needed
TEXT+="${VAR_DOTS:0:$Tmp}" # Add dots for padding
TEXT+=" ${VAR_FIRM}" # Add the firmware version value
TEXT+="%0A" # New line
TEXT+="MAC" # Add the MAC address
Tmp=$(( VAR_WIDTH - ${#VAR_MAC} )) # Calculate the padding needed
TEXT+="${VAR_DOTS:0:$Tmp}" # Add dots for padding
TEXT+=" ${VAR_MAC}" # Add the MAC address value
TEXT+="%0A" # New line
TEXT+="IP" # Add the Public IP address
Tmp=$(( VAR_WIDTH + 1 - ${#VAR_IP} )) # Calculate the padding needed
TEXT+="${VAR_DOTS:0:$Tmp}" # Add dots for padding
TEXT+=" ${VAR_IP}" # Add the Public IP address value
TEXT+="%0A" # New line
TEXT+="RAM" # Add the RAM usage
Tmp=$(( VAR_WIDTH - 1 - ${#VAR_MEMUSED} - ${#VAR_MEMTOT} )) # Calculate the padding needed
TEXT+="${VAR_DOTS:0:$Tmp}" # Add dots for padding
TEXT+=" ${VAR_MEMUSED}/${VAR_MEMTOT}" # Add the RAM usage value
TEXT+="%0A" # New line
TEXT+="CPU Load" # Add the CPU load percentage
Tmp=$(( VAR_WIDTH - 6 - ${#VAR_CPULOAD} )) # Calculate the padding needed
TEXT+="${VAR_DOTS:0:$Tmp}" # Add dots for padding
TEXT+=" ${VAR_CPULOAD}%" # Add the CPU load percentage value
TEXT+="%0A" # New line
TEXT+="Load Avg1" # Add the 1-minute load average
Tmp=$(( VAR_WIDTH - 5 - ${#VAR_LOADAVG1} )) # Calculate the padding needed
TEXT+="${VAR_DOTS:0:$Tmp}" # Add dots for padding
TEXT+=" ${VAR_LOADAVG1%?}" # Add the 1-minute load average value (removing the last character)
TEXT+="%0A" # New line
TEXT+="Load Avg5" # Add the 5-minute load average
Tmp=$(( VAR_WIDTH - 5 - ${#VAR_LOADAVG5} )) # Calculate the padding needed
TEXT+="${VAR_DOTS:0:$Tmp}" # Add dots for padding
TEXT+=" ${VAR_LOADAVG5%?}" # Add the 5-minute load average value (removing the last character)
TEXT+="%0A" # New line
TEXT+="Load Avg15" # Add the 15-minute load average
Tmp=$(( VAR_WIDTH - 7 - ${#VAR_LOADAVG15} )) # Calculate the padding needed
TEXT+="${VAR_DOTS:0:$Tmp}" # Add dots for padding
TEXT+=" ${VAR_LOADAVG15}" # Add the 15-minute load average value
TEXT+="%0A%0A %F0%9F%93%80 STORAGE - /dev/sda" # Add a section header for storage
TEXT+="%0A" # New line
TEXT+="Brand" # Add the brand of the hard drive
Tmp=$(( VAR_WIDTH - 2 - ${#VAR_SDA_BRAND} )) # Calculate the padding needed
TEXT+="${VAR_DOTS:0:$Tmp}" # Add dots for padding
TEXT+=" ${VAR_SDA_BRAND}" # Add the brand value
TEXT+="%0A" # New line
TEXT+="Model" # Add the model of the hard drive
Tmp=$(( VAR_WIDTH - 3 - ${#VAR_SDA_MODEL} )) # Calculate the padding needed
TEXT+="${VAR_DOTS:0:$Tmp}" # Add dots for padding
TEXT+=" ${VAR_SDA_MODEL%?}" # Add the model value (removing the last character)
TEXT+="%0A" # New line
TEXT+="Temperature" # Add the temperature of the hard drive
Tmp=$(( VAR_WIDTH - 10 - ${#VAR_SDA_TEMP} )) # Calculate the padding needed
TEXT+="${VAR_DOTS:0:$Tmp}" # Add dots for padding
TEXT+=" ${VAR_SDA_TEMP}°C" # Add the temperature value
TEXT+="%0A" # New line
TEXT+="OS Partition" # Add the OS partition usage
Tmp=$(( VAR_WIDTH - 11 - ${#VAR_DISK1_USED} - ${#VAR_DISK1_TOT} - ${#VAR_DISK1_PERC} - 3 )) # Calculate the padding needed
TEXT+="${VAR_DOTS:0:$Tmp}" # Add dots for padding
TEXT+=" ${VAR_DISK1_USED}/${VAR_DISK1_TOT} - ${VAR_DISK1_PERC}" # Add the OS partition usage value
TEXT+="%0A" # New line
TEXT+="Data Partition" # Add the data partition usage
Tmp=$(( VAR_WIDTH - 13 - ${#VAR_DISK2_USED} - ${#VAR_DISK2_TOT} - ${#VAR_DISK2_PERC} - 3 )) # Calculate the padding needed
TEXT+="${VAR_DOTS:0:$Tmp}" # Add dots for padding
TEXT+=" ${VAR_DISK2_USED}/${VAR_DISK2_TOT} - ${VAR_DISK2_PERC}" # Add the data partition usage value
TEXT+="\`\`\`" # End the code block for formatting
ESCAPED_TEXT=$(escape_markdown "$TEXT") # Escape the text for MarkdownV2
# ----------------------------------------------------------------------- Send to Telegram -------------------
# ------------------------------------------------------------------------------------------------------------
# Replace YOUR_BOT_TOKEN and YOUR_CHAT_ID at the top of this script in the Variables initialization section
curl -s -X POST "https://api.telegram.org/bot${BOT_TOKEN}/sendMessage" \
-d chat_id="${CHAT_ID}" \
-d text="${ESCAPED_TEXT}" \
-d disable_notification="${SILENT_NOTIFICATION}" \
-d parse_mode=MarkdownV2 > /dev/null
exit 0