Skip to content

Commit cc3ac67

Browse files
committed
Token and Chat-ID as parameters not inside xml-file
1 parent def5097 commit cc3ac67

File tree

3 files changed

+27
-29
lines changed

3 files changed

+27
-29
lines changed

README.md

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,27 @@ The following Script is for Check_MK, I have used it exclusively with the RAW ve
77
<!-- TOC -->
88

99
- [Check_MK Telegram notification](#check_mk-telegram-notification)
10+
- [LATEST UPDATE](#latest-update)
1011
- [REQUIREMENTS](#requirements)
1112
- [INSTALLATION](#installation)
1213
- [CHECK_MK CONFIGURATION](#check_mk-configuration)
1314
- [LICENSE](#license)
1415

1516
<!-- /TOC -->
1617

18+
## LATEST UPDATE
19+
The Telegram token (API key) and the chat/group ID are no longer stored in a separate XML file and instead are passed directly by Check_MK as parameters. This offers the possibility to create several notification groups and to use the script universally.
20+
1721
## REQUIREMENTS
1822
In order for Check_MK to send alerts (notifications) to the Telegram Messenger, we need
1923

20-
* a bot
24+
* a Telegram bot
2125
* a username for the bot
2226
* an API token
23-
* a chat ID
27+
* a Telegram Chat- or Group-ID
2428

2529
There are a lot of good instructions for this on the Internet, so this is not part of this documentation.
2630

27-
Additionally for the XML-based configuration the command line tool ```xmllint``` is used, which requires the following packages on the Linux system:
28-
```
29-
apt install libxml2-utils # Debian/Raspbian-based distributions
30-
yum install libxml2-utils # Redhat/CentOS-based distributions
31-
```
32-
3331
## INSTALLATION
3432
Change to your Check_MK site user
3533
```
@@ -46,18 +44,6 @@ Download the Telegram notify script from Git repository
4644
git clone https://github.com/filipnet/checkmk-telegram-notify.git .
4745
```
4846

49-
Adjusting the config.xml
50-
```
51-
cd /opt/omd/sites/mysite/local/share/check_mk/notifications/
52-
mv config.xml.sample config.xml
53-
```
54-
55-
Inside your API Token and Chat/Group-ID
56-
```
57-
<telegram_api_token>TELEGRAM_API_TOKEN_WITHOUT_BOT_PREFIX</telegram_api_token>
58-
<telegram_chat_id>TELEGRAM_GROUP_OR_CHAT-ID</telegram_chat_id>
59-
```
60-
6147
Give the script execution permissions
6248
```
6349
chmod +x check_mk_telegram-notify.sh
@@ -72,7 +58,11 @@ First create a clone of your existing mail notification rule
7258

7359
<img src="images/global_notification_rules_create_clone.png" alt="Create clone" width="600"/>
7460

75-
Change the description and select "Push Notification (by Telegram)", no further settings are required for this.
61+
* Change the description (e.g. Notify all contacts of a host/service via Telegram)
62+
* The notification method is "Push Notification (by Telegram)"
63+
* Select option "Call with the following parameters:"
64+
* As the first parameter we set the Telegram token ID (without bot-prefix)
65+
* The second parameter is the Telegram Chat-ID or Telegram Group-ID
7666

7767
<img src="images/create_new_notification_rule_for_telegram.png" alt="Adjust settings" width="600"/>
7868

@@ -84,5 +74,18 @@ To activate it you have to press "1 Change" and "Activate affected"
8474

8575
<img src="images/activate_affected.png" alt="Activate changes and commit" width="100"/>
8676

77+
To ensure that the parameters are also transferred in the event of an alert, it is strongly recommended that the Check_MK instance is restarted.
78+
```
79+
su - mysite
80+
omd stop
81+
omd start
82+
```
83+
84+
For more details and troubleshooting with parameters please check:
85+
86+
[Check_MK Manual > Notifications > Chapter: 11.3. A simple example](https://docs.checkmk.com/latest/en/notifications.html#H1:Real)
87+
88+
[[Feature-Request] Multiple Alert Profiles](https://github.com/filipnet/checkmk-telegram-notify/issues/3)
89+
8790
## LICENSE
8891
checkmk-telegram-notify and all individual scripts are under the BSD 3-Clause license unless explicitly noted otherwise. Please refer to the LICENSE

check_mk_telegram-notify.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
# License : BSD 3-Clause "New" or "Revised" License
88
# ======================================================================================
99

10-
CONFIGFILE="${BASH_SOURCE%/*}/config.xml"
1110
# Telegram API Token
1211
# Find telegram bot named "@botfarther", type /mybots, select your bot and select "API Token" to see your current token
13-
TOKEN=$(xmllint --xpath 'string(/config/telegram_api_token)' $CONFIGFILE)
12+
TOKEN=$NOTIFY_PARAMETER_1
13+
1414
# Telegram Chat-ID or Group-ID
1515
# Open "https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates" inside your Browser and send a HELLO to your bot, refresh side
16-
CHAT_ID=$(xmllint --xpath 'string(/config/telegram_chat_id)' $CONFIGFILE)
16+
CHAT_ID=$NOTIFY_PARAMETER_2
1717

1818
# Write Check_MK output to a temporary file, delete depricated macros and create variable OUTPUT
1919
env | grep NOTIFY_ | grep -v "This macro is deprecated" | sort > $OMD_ROOT/tmp/telegram.out

config.xml.sample

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)