2021-12-24 16:47:21 -06:00
|
|
|
#! /bin/sh
|
|
|
|
#
|
|
|
|
# notify-by-matrix
|
|
|
|
# Copyright (C) 2021 Vintage Salt <rehashedsalt@cock.li>
|
|
|
|
#
|
|
|
|
# Distributed under terms of the MIT license.
|
|
|
|
#
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Set our Matrix-related vars here
|
|
|
|
MX_TOKEN="{{ nagios_matrix_token }}"
|
|
|
|
MX_SERVER="{{ nagios_matrix_server }}"
|
|
|
|
MX_ROOM="{{ nagios_matrix_room }}"
|
|
|
|
|
|
|
|
# Get a TXN to prefix this particular message with
|
|
|
|
MX_TXN="$(date "+%s")$(( RANDOM % 9999 ))"
|
|
|
|
|
2022-05-02 15:46:41 -05:00
|
|
|
# Read the first line from STDIN
|
|
|
|
# This is supposed to be the NOTIFICATIONTYPE
|
|
|
|
read notiftype
|
|
|
|
prefix=""
|
|
|
|
# https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/3/en/macrolist.html#notificationtype
|
|
|
|
case "$notiftype" in
|
|
|
|
PROBLEM)
|
|
|
|
# Large Red Circle (U+1F534)
|
|
|
|
prefix="🔴"
|
|
|
|
;;
|
|
|
|
RECOVERY)
|
|
|
|
# Large Green Circle (U+1F7E2)
|
|
|
|
prefix="🟢"
|
|
|
|
;;
|
|
|
|
ACKNOWLEDGEMENT)
|
|
|
|
# Symbol For Acknowledge (U+2406)
|
|
|
|
prefix="␆"
|
|
|
|
;;
|
|
|
|
FLAPPINGSTART)
|
|
|
|
# Large Orange Circle (U+1F7E0)
|
|
|
|
prefix="🟠"
|
|
|
|
;;
|
|
|
|
FLAPPINGSTOP)
|
|
|
|
# Large Green Circle (U+1F7E2)
|
|
|
|
prefix="🟢"
|
|
|
|
;;
|
|
|
|
FLAPPINGDISABLED)
|
|
|
|
# Bell with Cancellation Stroke (U+1F515)
|
|
|
|
prefix="🔕"
|
|
|
|
;;
|
|
|
|
DOWNTIMESTART)
|
|
|
|
# Bell with Cancellation Stroke (U+1F515)
|
|
|
|
prefix="🔕"
|
|
|
|
;;
|
|
|
|
DOWNTIMEEND)
|
|
|
|
# Bell (U+1F514)
|
|
|
|
prefix="🔔"
|
|
|
|
;;
|
|
|
|
DOWNTIMECANCELLED)
|
|
|
|
# Bell (U+1F514)
|
|
|
|
prefix="🔔"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
prefix="$notiftype - "
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2021-12-24 16:47:21 -06:00
|
|
|
# Read a message from STDIN
|
|
|
|
# NOTE: This is dangerous and stupid and unsanitized
|
|
|
|
read message
|
|
|
|
while read line; do
|
|
|
|
message="${message}\n${line}"
|
|
|
|
done
|
|
|
|
|
|
|
|
# Push it to the channel
|
|
|
|
curl -X PUT \
|
|
|
|
--header 'Content-Type: application/json' \
|
|
|
|
--header 'Accept: application/json' \
|
|
|
|
-d "{
|
|
|
|
\"msgtype\": \"m.text\",
|
2022-05-02 15:46:41 -05:00
|
|
|
\"body\": \"$prefix $message\"
|
2021-12-24 16:47:21 -06:00
|
|
|
}" \
|
|
|
|
"$MX_SERVER/_matrix/client/unstable/rooms/$MX_ROOM/send/m.room.message/$MX_TXN?access_token=$MX_TOKEN"
|