mirror of
https://github.com/guezoloic/serverconfig.git
synced 2026-01-25 07:34:23 +00:00
fix: add few functions
- create send_notification function - auto scripts/*.sh scripts searcher
This commit is contained in:
@@ -56,11 +56,8 @@ install_file() {
|
||||
}
|
||||
echo
|
||||
datetime_print "------------- install files -------------"
|
||||
install_file "aws-backup.sh" "$SCRIPT_FILE" -Dm755
|
||||
install_file "disk-monitor.sh" "$SCRIPT_FILE" -Dm755
|
||||
install_file "sshd-login.sh" "$SCRIPT_FILE" -Dm755
|
||||
install_file "telegram.sh" "$SCRIPT_FILE" -Dm755
|
||||
install_file "docker-compose.yml" "$ETC_DIR" -Dm644
|
||||
for element in scripts/*.sh; do install_file "$(basename $element)" "$SCRIPT_FILE" -Dm755; done
|
||||
install_file "docker-compose.yml" "$ETC_DIR" -Dm644
|
||||
|
||||
create_env_variable() {
|
||||
local key="$1"
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
#!/bin/bash
|
||||
#!/bin/bash
|
||||
|
||||
source /etc/serverconfig/.env
|
||||
source /usr/local/bin/notifications.sh
|
||||
|
||||
disk_usage() {
|
||||
df -h / | grep / | awk -v max="$1" '{
|
||||
usage = $5;
|
||||
gsub("%", "", usage);
|
||||
if (usage > max) {
|
||||
printf "<b>🚨 WARNING:</b>\nDisk usage is at %d%%. which exceed the treshold of %d%%.\n\n", usage, max;
|
||||
}
|
||||
printf "<b>💾 Disk Usage Information:</b>\nTotal Size: %s, Used: %s, Available: %s\n\n", $2, $3, $4;
|
||||
}'
|
||||
}
|
||||
disk_usage() {
|
||||
df -h / | grep / | awk -v max="$1" '{
|
||||
usage = $5;
|
||||
gsub("%", "", usage);
|
||||
if (usage > max) {
|
||||
printf "<b>🚨 WARNING:</b>\nDisk usage is at %d%%. which exceed the treshold of %d%%.\n\n", usage, max;
|
||||
}
|
||||
printf "<b>💾 Disk Usage Information:</b>\nTotal Size: %s, Used: %s, Available: %s\n\n", $2, $3, $4;
|
||||
}'
|
||||
}
|
||||
|
||||
curl -X POST "https://api.telegram.org/bot$TOKEN/sendMessage" \
|
||||
-d "chat_id=$CHAT_ID" \
|
||||
-d "text=$(disk_usage 80)" \
|
||||
-d "parse_mode=HTML"
|
||||
send_notification "$(disk_usage 80)"
|
||||
|
||||
11
scripts/notifications.sh
Normal file
11
scripts/notifications.sh
Normal file
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
source /etc/serverconfig/.env
|
||||
|
||||
send_notification() {
|
||||
local message="$1"
|
||||
curl -X POST "https://api.telegram.org/bot$TELEGRAM_TOKEN/sendMessage" \
|
||||
-d "chat_id=$TELEGRAM_CHAT_ID" \
|
||||
-d "text=$message" \
|
||||
-d "parse_mode=HTML"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#!bin/bash
|
||||
|
||||
source /etc/serverconfig/.env
|
||||
source /usr/local/bin/notifications.sh
|
||||
|
||||
case "$PAM_TYPE" in
|
||||
open_session)
|
||||
@@ -12,8 +12,5 @@ case "$PAM_TYPE" in
|
||||
esac
|
||||
|
||||
if [ -n "$PAYLOAD" ] ; then
|
||||
curl -X POST "https://api.telegram.org/bot$TOKEN/sendMessage" \
|
||||
-d "chat_id=$CHAT_ID" \
|
||||
-d "text=$PLAYLOAD" \
|
||||
-d "parse_mode=HTML"
|
||||
send_notification "$PAYLOAD"
|
||||
fi
|
||||
Reference in New Issue
Block a user