ansible-roles/roles/zabbix_server/files/scripts/matrix_notify
2021-12-01 19:13:34 +01:00

27 lines
753 B
Bash

#!/bin/bash
TO=$1
MESSAGE=$2
if [[ $TO =~ ^@ ]]; then
# This is a matrix user. We need to create a room before we can send
# But first check if we haven't already one
if [ -e ~/.matrix_zabbix/$TO ]; then
# We already have a room for this user, just send it there
TO=$(cat ~/.matrix_zabbix/$TO)
else
# Create a new room, invite the user, and grant him admin privileges
USER=$TO
TO=$(patrix --create-room --name="Zabbix Alerter for $TO" --topic='Alerts' --invite=$TO)
patrix --modify-room --room=$TO --user-perm "$USER=100"
echo $TO > ~/.matrix_zabbix/$USER
fi
fi
# Check we now have a room ID or alias
if [[ $TO =~ ^[\!\#] ]]; then
echo "$MESSAGE" | patrix --room=$TO
else
echo "Can't send to $TO"
exit 1
fi