Skip to content

Commit

Permalink
Add privacy function, modified readme
Browse files Browse the repository at this point in the history
  • Loading branch information
filipnet committed Apr 29, 2021
1 parent b5bc825 commit 22b545a
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 5 deletions.
45 changes: 40 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ 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)
- [EXAMPLE](#example)
- [REQUIREMENTS](#requirements)
- [INSTALLATION](#installation)
- [CHECK_MK CONFIGURATION](#check_mk-configuration)
- [PRIVACY ANONYMIZATION / MASQUERADING](#privacy-anonymization--masquerading)
- [PAGER ADDRESS CHAT-ID INSTEAD OF TELEGRAM GROUP-ID](#pager-address-chat-id-instead-of-telegram-group-id)
- [TROUBLESHOOTING](#troubleshooting)
- [CONTRIBUTION](#contribution)
- [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.

## EXAMPLE
Notifications are usually sent via a Telegram group. Here is an example of how a Telegram notification is structured.

Expand Down Expand Up @@ -87,11 +87,46 @@ omd stop
omd start
```

## PRIVACY ANONYMIZATION / MASQUERADING
The current version of this script allows you to optionally enable IP anonymization. This gives you the option to comply with your own privacy policy or the recommendations of data protection authorities in certain countries if they prohibit the transmission of the full IP address. This masks IPv4 and IPv6 IP addresses before they are transmitted in a message to the Telegram service.

The activation of the privacy settings is realized directly in the Notification Rules in Check_MK by NOTIFY_PARAMETER_3, here the value "privacy" has to be entered:

<img src="images/notification_rule_modify_privacy.png" alt="Enable privacy settings" width="600"/>

There are certainly different requirements for privacy and masquerading of IP addresses. In the script, the IPv4 IP address is split into the 4 octets, the IPv6 address into the 8 columns. This allows to control __very individually__ which parts of the addresses are sent via Telegram and which are not. Both, placeholders and manipulations are basically possible here.

The adjustment is done exclusively in the following two lines of the script.
```
# Adjust the output to your privacy needs here (Details in the readme.md)
NOTIFY_HOST_ADDRESS_4="${sec1}.${sec2}.2.${sec4}"
NOTIFY_HOST_ADDRESS_6="${sec1}:${sec2}:${sec3}:${sec4}:ffff:ffff:ffff:${sec8}"
```

Explanation for the example configuration above:
* 192.168.__143__.104 --> 192.168.__2__.104
* 2001:db8:85a3:8d3:__1319__:__8a2e__:__370__:7348 --> 2001:db8:85a3:8d3:__ffff__:__ffff__:__ffff__:7348

## PAGER ADDRESS (CHAT-ID) INSTEAD OF TELEGRAM GROUP-ID
A different approach is to use the 'Pager address' field in Check_MK's user properties. This gets exported as $NOTIFY_CONTACTPAGER variable to the script and as such all that's needed is:
```
if [ -z ${NOTIFY_CONTACTPAGER} ]; then
echo "No pager address provided to be used as Chat-ID. Exiting" >&2
exit 2
else
CHAT_ID="${NOTIFY_CONTACTPAGER}"
fi
```

## TROUBLESHOOTING
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)

## CONTRIBUTION
Thank you for the excellent contributions and additional information @ThomasKaiser, which I have integrated into the README.

## LICENSE
checkmk-telegram-notify and all individual scripts are under the BSD 3-Clause license unless explicitly noted otherwise. Please refer to the LICENSE
checkmk-telegram-notify and all individual scripts are under the BSD 3-Clause license unless explicitly noted otherwise. Please refer to the LICENSE
33 changes: 33 additions & 0 deletions check_mk_telegram-notify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,39 @@ else
CHAT_ID="${NOTIFY_PARAMETER_2}"
fi

# Privacy settings to anonymize/masking IP addresses
if [ ${NOTIFY_PARAMETER_3} = "privacy" ]; then
# IPv4 IP addresses
if [ ${NOTIFY_HOST_ADDRESS_4} ]; then
slice="${NOTIFY_HOST_ADDRESS_4}"
count=1
while [ "$count" -le 4 ]
do
declare sec"$count"="${slice%%.*}"
slice="${slice#*.}"
count=$((count+1))
done
# Adjust the output to your privacy needs here (Details in the readme.md)
NOTIFY_HOST_ADDRESS_4="${sec1}.${sec2}.2.${sec4}"
fi

# IPv6 IP addresses
if [ ${NOTIFY_HOST_ADDRESS_6} ]; then
slice="${NOTIFY_HOST_ADDRESS_6}"
count=1
while [ "$count" -le 8 ]
do
declare sec"$count"="${slice%%:*}"
slice="${slice#*:}"
count=$((count+1))
done
# Adjust the output to your privacy needs here (Details in the readme.md)
NOTIFY_HOST_ADDRESS_6="${sec1}:${sec2}:${sec3}:${sec4}:ffff:ffff:ffff:${sec8}"
fi
else
echo "Invalid privacy parameter, check your Check_MK settings." >&2
fi

# Create a MESSAGE variable to send to your Telegram bot
MESSAGE="${NOTIFY_HOSTNAME} (${NOTIFY_HOSTALIAS})%0A"
MESSAGE+="${NOTIFY_WHAT} ${NOTIFY_NOTIFICATIONTYPE}%0A%0A"
Expand Down
Binary file added images/notification_rule_modify_privacy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 22b545a

Please sign in to comment.