mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-12-07 18:05:09 +00:00
Optimized TELEGRAM_BOT implementation
This commit is contained in:
@@ -1,7 +1,15 @@
|
|||||||
system_service_id: sys-ctl-alm-compose@
|
system_service_id: sys-ctl-alm-compose@
|
||||||
|
|
||||||
SYSTEMCTL_ALARM_COMPOSER_SUBSERVICES:
|
SYSTEMCTL_ALARM_COMPOSER_SUBSERVICES: >-
|
||||||
- 'sys-ctl-alm-email'
|
{{
|
||||||
- 'sys-ctl-alm-telegram'
|
['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 }}."
|
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_BOT_TOKEN: '' # The token of your telegram bot
|
||||||
telegram_chat_id: '' # The id of your telegram chat
|
TELEGRAM_CHAT_ID: '' # The id of your telegram chat
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
- name: Fail if Telegram bot credentials are not set
|
- name: Fail if Telegram bot credentials are not set
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- telegram_bot_token != ""
|
- TELEGRAM_BOT_TOKEN != ""
|
||||||
- telegram_chat_id != ""
|
- TELEGRAM_CHAT_ID != ""
|
||||||
fail_msg: |
|
fail_msg: |
|
||||||
Telegram configuration is incomplete!
|
Telegram configuration is incomplete!
|
||||||
Please provide non‑empty values for:
|
Please provide non‑empty values for:
|
||||||
- telegram_bot_token # Your Telegram bot’s API token
|
- TELEGRAM_BOT_TOKEN # Your Telegram bot’s API token
|
||||||
- telegram_chat_id # The Telegram chat ID to send messages to
|
- TELEGRAM_CHAT_ID # The Telegram chat ID to send messages to
|
||||||
when: MODE_ASSERT | bool
|
when: MODE_ASSERT | bool
|
||||||
|
|
||||||
- include_role:
|
- include_role:
|
||||||
|
|||||||
@@ -13,6 +13,6 @@ fi
|
|||||||
|
|
||||||
# send the Telegram message
|
# send the Telegram message
|
||||||
/usr/bin/curl -s -X POST \
|
/usr/bin/curl -s -X POST \
|
||||||
"https://api.telegram.org/bot{{ telegram_bot_token }}/sendMessage" \
|
"https://api.telegram.org/bot{{ TELEGRAM_BOT_TOKEN }}/sendMessage" \
|
||||||
-d chat_id="{{ telegram_chat_id }}" \
|
-d chat_id="{{ TELEGRAM_CHAT_ID }}" \
|
||||||
--data-urlencode text="service ${friendly//\//-} on ${host} failed"
|
--data-urlencode text="service ${friendly//\//-} on ${host} failed"
|
||||||
|
|||||||
Reference in New Issue
Block a user