From d7aba3c27ede762cec9eb2aebb1ac6eec7685364 Mon Sep 17 00:00:00 2001 From: Jakub Turski Date: Fri, 29 Nov 2024 18:40:34 +0000 Subject: [PATCH] feat: add tgsend, use it for the failure-reporting systemd unit --- files/scripts/eget.sh | 1 + files/system/etc/.gitkeep | 1 - .../etc/systemd/system/unit-status-telegram@.service | 8 -------- files/system/usr/.gitkeep | 0 files/system/usr/bin/telegram-msg-send | 6 ------ files/system/usr/bin/unit-status-telegram | 10 ---------- .../lib/systemd/system/unit-status-telegram@.service | 9 +++++++++ 7 files changed, 10 insertions(+), 25 deletions(-) delete mode 100644 files/system/etc/.gitkeep delete mode 100644 files/system/etc/systemd/system/unit-status-telegram@.service delete mode 100644 files/system/usr/.gitkeep delete mode 100755 files/system/usr/bin/telegram-msg-send delete mode 100755 files/system/usr/bin/unit-status-telegram create mode 100644 files/system/usr/lib/systemd/system/unit-status-telegram@.service diff --git a/files/scripts/eget.sh b/files/scripts/eget.sh index 0339a52..b38daa4 100644 --- a/files/scripts/eget.sh +++ b/files/scripts/eget.sh @@ -9,4 +9,5 @@ eget atanunq/viu --to=/usr/bin eget atuinsh/atuin -a gnu -a '^update' --to=/usr/bin eget containers/podlet --to=/usr/bin -a gnu eget creativeprojects/resticprofile -a no_self_update --to=/usr/bin +eget stunnel/tgsend -f 'tgsend-*' --to=/usr/bin/tgsend eget watchexec/watchexec -a musl.tar.xz _ -a '^b3' -a '^sha512' --to=/usr/bin diff --git a/files/system/etc/.gitkeep b/files/system/etc/.gitkeep deleted file mode 100644 index 8b13789..0000000 --- a/files/system/etc/.gitkeep +++ /dev/null @@ -1 +0,0 @@ - diff --git a/files/system/etc/systemd/system/unit-status-telegram@.service b/files/system/etc/systemd/system/unit-status-telegram@.service deleted file mode 100644 index 194134a..0000000 --- a/files/system/etc/systemd/system/unit-status-telegram@.service +++ /dev/null @@ -1,8 +0,0 @@ -# via from https://github.com/CurrySoftware/Telegram-Notifier -[Unit] -Description=Unit Status Telegram Service -After=network.target - -[Service] -Type=simple -ExecStart=/usr/bin/unit-status-telegram %I diff --git a/files/system/usr/.gitkeep b/files/system/usr/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/files/system/usr/bin/telegram-msg-send b/files/system/usr/bin/telegram-msg-send deleted file mode 100755 index dab6632..0000000 --- a/files/system/usr/bin/telegram-msg-send +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -# via from https://github.com/CurrySoftware/Telegram-Notifier -. /etc/telegram/key - -URL="https://api.telegram.org/bot$TELEGRAM_KEY/sendMessage" -curl -s -d "chat_id=$CHAT_ID&disable_web_page_preview=1&text=$1" "$URL" >/dev/null diff --git a/files/system/usr/bin/unit-status-telegram b/files/system/usr/bin/unit-status-telegram deleted file mode 100755 index 84829e5..0000000 --- a/files/system/usr/bin/unit-status-telegram +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh - -UNIT=$1 - -UNITSTATUS=$(systemctl status "$UNIT") -ALERT=$(echo -e "\u26A0") - -/usr/bin/telegram-msg-send "$ALERT Unit failed $UNIT $ALERT -Status: -$UNITSTATUS" diff --git a/files/system/usr/lib/systemd/system/unit-status-telegram@.service b/files/system/usr/lib/systemd/system/unit-status-telegram@.service new file mode 100644 index 0000000..e4ea98f --- /dev/null +++ b/files/system/usr/lib/systemd/system/unit-status-telegram@.service @@ -0,0 +1,9 @@ +[Unit] +Description=Unit Status Telegram Service +After=network.target +ConditionPathExists=/etc/tgsend-env + +[Service] +Type=simple +EnvironmentFile=/etc/tgsend-env +ExecStart=/bin/sh -c '/usr/bin/tgsend -token ${TG_TOKEN} -chatid ${TG_CHAT_ID} -format markdown -message "‼️ %H unit status: \`\`\`$(systemctl status %i)\`\`\`"'