Optimized TELEGRAM_BOT implementation

This commit is contained in:
2025-12-04 10:35:45 +01:00
parent 7847d5fddc
commit 651038a7c5
4 changed files with 19 additions and 11 deletions

View File

@@ -1,7 +1,15 @@
system_service_id: sys-ctl-alm-compose@
SYSTEMCTL_ALARM_COMPOSER_SUBSERVICES:
- 'sys-ctl-alm-email'
- 'sys-ctl-alm-telegram'
SYSTEMCTL_ALARM_COMPOSER_SUBSERVICES: >-
{{
['sys-ctl-alm-email']
+
(
['sys-ctl-alm-telegram']
if (TELEGRAM_BOT_TOKEN | default('') | trim != '')
and (TELEGRAM_CHAT_ID | default('') | trim != '')
else []
)
}}
SYSTEMCTL_ALARM_COMPOSER_DUMMY_MESSAGE: "[Info] Dummy Message: No Failure; Ansible is initializing {{ SOFTWARE_NAME }} on {{ inventory_hostname }}."

View File

@@ -1,2 +1,2 @@
telegram_bot_token: '' # The token of your telegram bot
telegram_chat_id: '' # The id of your telegram chat
TELEGRAM_BOT_TOKEN: '' # The token of your telegram bot
TELEGRAM_CHAT_ID: '' # The id of your telegram chat

View File

@@ -1,13 +1,13 @@
- name: Fail if Telegram bot credentials are not set
assert:
that:
- telegram_bot_token != ""
- telegram_chat_id != ""
- TELEGRAM_BOT_TOKEN != ""
- TELEGRAM_CHAT_ID != ""
fail_msg: |
Telegram configuration is incomplete!
Please provide nonempty values for:
- telegram_bot_token # Your Telegram bots API token
- telegram_chat_id # The Telegram chat ID to send messages to
- TELEGRAM_BOT_TOKEN # Your Telegram bots API token
- TELEGRAM_CHAT_ID # The Telegram chat ID to send messages to
when: MODE_ASSERT | bool
- include_role:

View File

@@ -13,6 +13,6 @@ fi
# send the Telegram message
/usr/bin/curl -s -X POST \
"https://api.telegram.org/bot{{ telegram_bot_token }}/sendMessage" \
-d chat_id="{{ telegram_chat_id }}" \
"https://api.telegram.org/bot{{ TELEGRAM_BOT_TOKEN }}/sendMessage" \
-d chat_id="{{ TELEGRAM_CHAT_ID }}" \
--data-urlencode text="service ${friendly//\//-} on ${host} failed"