Skip to content

Commit

Permalink
Token and Chat-ID as parameters not inside xml-file
Browse files Browse the repository at this point in the history
  • Loading branch information
filipnet committed Mar 16, 2021
1 parent def5097 commit cc3ac67
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 29 deletions.
45 changes: 24 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,27 @@ The following Script is for Check_MK, I have used it exclusively with the RAW ve
<!-- TOC -->

- [Check_MK Telegram notification](#check_mk-telegram-notification)
- [LATEST UPDATE](#latest-update)
- [REQUIREMENTS](#requirements)
- [INSTALLATION](#installation)
- [CHECK_MK CONFIGURATION](#check_mk-configuration)
- [LICENSE](#license)

<!-- /TOC -->

## LATEST UPDATE
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.

## REQUIREMENTS
In order for Check_MK to send alerts (notifications) to the Telegram Messenger, we need

* a bot
* a Telegram bot
* a username for the bot
* an API token
* a chat ID
* a Telegram Chat- or Group-ID

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

Additionally for the XML-based configuration the command line tool ```xmllint``` is used, which requires the following packages on the Linux system:
```
apt install libxml2-utils # Debian/Raspbian-based distributions
yum install libxml2-utils # Redhat/CentOS-based distributions
```

## INSTALLATION
Change to your Check_MK site user
```
Expand All @@ -46,18 +44,6 @@ Download the Telegram notify script from Git repository
git clone https://github.com/filipnet/checkmk-telegram-notify.git .
```

Adjusting the config.xml
```
cd /opt/omd/sites/mysite/local/share/check_mk/notifications/
mv config.xml.sample config.xml
```

Inside your API Token and Chat/Group-ID
```
<telegram_api_token>TELEGRAM_API_TOKEN_WITHOUT_BOT_PREFIX</telegram_api_token>
<telegram_chat_id>TELEGRAM_GROUP_OR_CHAT-ID</telegram_chat_id>
```

Give the script execution permissions
```
chmod +x check_mk_telegram-notify.sh
Expand All @@ -72,7 +58,11 @@ First create a clone of your existing mail notification rule

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

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

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

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

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

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.
```
su - mysite
omd stop
omd start
```

For more details and troubleshooting with parameters please check:

[Check_MK Manual > Notifications > Chapter: 11.3. A simple example](https://docs.checkmk.com/latest/en/notifications.html#H1:Real)

[[Feature-Request] Multiple Alert Profiles](https://github.com/filipnet/checkmk-telegram-notify/issues/3)

## LICENSE
checkmk-telegram-notify and all individual scripts are under the BSD 3-Clause license unless explicitly noted otherwise. Please refer to the LICENSE
6 changes: 3 additions & 3 deletions check_mk_telegram-notify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
# License : BSD 3-Clause "New" or "Revised" License
# ======================================================================================

CONFIGFILE="${BASH_SOURCE%/*}/config.xml"
# Telegram API Token
# Find telegram bot named "@botfarther", type /mybots, select your bot and select "API Token" to see your current token
TOKEN=$(xmllint --xpath 'string(/config/telegram_api_token)' $CONFIGFILE)
TOKEN=$NOTIFY_PARAMETER_1

# Telegram Chat-ID or Group-ID
# Open "https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates" inside your Browser and send a HELLO to your bot, refresh side
CHAT_ID=$(xmllint --xpath 'string(/config/telegram_chat_id)' $CONFIGFILE)
CHAT_ID=$NOTIFY_PARAMETER_2

# Write Check_MK output to a temporary file, delete depricated macros and create variable OUTPUT
env | grep NOTIFY_ | grep -v "This macro is deprecated" | sort > $OMD_ROOT/tmp/telegram.out
Expand Down
5 changes: 0 additions & 5 deletions config.xml.sample

This file was deleted.

0 comments on commit cc3ac67

Please sign in to comment.