mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-12-07 09:56:41 +00:00
Optimized TELEGRAM_BOT implementation
This commit is contained in:
@@ -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 }}."
|
||||
@@ -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
|
||||
@@ -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 non‑empty values for:
|
||||
- telegram_bot_token # Your Telegram bot’s API token
|
||||
- telegram_chat_id # The Telegram chat ID to send messages to
|
||||
- TELEGRAM_BOT_TOKEN # Your Telegram bot’s API token
|
||||
- TELEGRAM_CHAT_ID # The Telegram chat ID to send messages to
|
||||
when: MODE_ASSERT | bool
|
||||
|
||||
- include_role:
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user