Skip to content

Commit 22b545a

Browse files
committed
Add privacy function, modified readme
1 parent b5bc825 commit 22b545a

File tree

3 files changed

+73
-5
lines changed

3 files changed

+73
-5
lines changed

README.md

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ 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)
1110
- [EXAMPLE](#example)
1211
- [REQUIREMENTS](#requirements)
1312
- [INSTALLATION](#installation)
1413
- [CHECK_MK CONFIGURATION](#check_mk-configuration)
14+
- [PRIVACY ANONYMIZATION / MASQUERADING](#privacy-anonymization--masquerading)
15+
- [PAGER ADDRESS CHAT-ID INSTEAD OF TELEGRAM GROUP-ID](#pager-address-chat-id-instead-of-telegram-group-id)
16+
- [TROUBLESHOOTING](#troubleshooting)
17+
- [CONTRIBUTION](#contribution)
1518
- [LICENSE](#license)
1619

1720
<!-- /TOC -->
1821

19-
## LATEST UPDATE
20-
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.
21-
2222
## EXAMPLE
2323
Notifications are usually sent via a Telegram group. Here is an example of how a Telegram notification is structured.
2424

@@ -87,11 +87,46 @@ omd stop
8787
omd start
8888
```
8989

90+
## PRIVACY ANONYMIZATION / MASQUERADING
91+
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.
92+
93+
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:
94+
95+
<img src="images/notification_rule_modify_privacy.png" alt="Enable privacy settings" width="600"/>
96+
97+
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.
98+
99+
The adjustment is done exclusively in the following two lines of the script.
100+
```
101+
# Adjust the output to your privacy needs here (Details in the readme.md)
102+
NOTIFY_HOST_ADDRESS_4="${sec1}.${sec2}.2.${sec4}"
103+
NOTIFY_HOST_ADDRESS_6="${sec1}:${sec2}:${sec3}:${sec4}:ffff:ffff:ffff:${sec8}"
104+
```
105+
106+
Explanation for the example configuration above:
107+
* 192.168.__143__.104 --> 192.168.__2__.104
108+
* 2001:db8:85a3:8d3:__1319__:__8a2e__:__370__:7348 --> 2001:db8:85a3:8d3:__ffff__:__ffff__:__ffff__:7348
109+
110+
## PAGER ADDRESS (CHAT-ID) INSTEAD OF TELEGRAM GROUP-ID
111+
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:
112+
```
113+
if [ -z ${NOTIFY_CONTACTPAGER} ]; then
114+
echo "No pager address provided to be used as Chat-ID. Exiting" >&2
115+
exit 2
116+
else
117+
CHAT_ID="${NOTIFY_CONTACTPAGER}"
118+
fi
119+
```
120+
121+
## TROUBLESHOOTING
90122
For more details and troubleshooting with parameters please check:
91123

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

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

128+
## CONTRIBUTION
129+
Thank you for the excellent contributions and additional information @ThomasKaiser, which I have integrated into the README.
130+
96131
## LICENSE
97-
checkmk-telegram-notify and all individual scripts are under the BSD 3-Clause license unless explicitly noted otherwise. Please refer to the LICENSE
132+
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: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,39 @@ else
2525
CHAT_ID="${NOTIFY_PARAMETER_2}"
2626
fi
2727

28+
# Privacy settings to anonymize/masking IP addresses
29+
if [ ${NOTIFY_PARAMETER_3} = "privacy" ]; then
30+
# IPv4 IP addresses
31+
if [ ${NOTIFY_HOST_ADDRESS_4} ]; then
32+
slice="${NOTIFY_HOST_ADDRESS_4}"
33+
count=1
34+
while [ "$count" -le 4 ]
35+
do
36+
declare sec"$count"="${slice%%.*}"
37+
slice="${slice#*.}"
38+
count=$((count+1))
39+
done
40+
# Adjust the output to your privacy needs here (Details in the readme.md)
41+
NOTIFY_HOST_ADDRESS_4="${sec1}.${sec2}.2.${sec4}"
42+
fi
43+
44+
# IPv6 IP addresses
45+
if [ ${NOTIFY_HOST_ADDRESS_6} ]; then
46+
slice="${NOTIFY_HOST_ADDRESS_6}"
47+
count=1
48+
while [ "$count" -le 8 ]
49+
do
50+
declare sec"$count"="${slice%%:*}"
51+
slice="${slice#*:}"
52+
count=$((count+1))
53+
done
54+
# Adjust the output to your privacy needs here (Details in the readme.md)
55+
NOTIFY_HOST_ADDRESS_6="${sec1}:${sec2}:${sec3}:${sec4}:ffff:ffff:ffff:${sec8}"
56+
fi
57+
else
58+
echo "Invalid privacy parameter, check your Check_MK settings." >&2
59+
fi
60+
2861
# Create a MESSAGE variable to send to your Telegram bot
2962
MESSAGE="${NOTIFY_HOSTNAME} (${NOTIFY_HOSTALIAS})%0A"
3063
MESSAGE+="${NOTIFY_WHAT} ${NOTIFY_NOTIFICATIONTYPE}%0A%0A"
13 KB
Loading

0 commit comments

Comments
 (0)