# Simple script to send messages via mattermost. # You can e.g. use this with nix to get your zed reports like this # # zfs.zed.settings = { # ZED_DEBUG_LOG = "/tmp/zed.debug.log"; # ZED_EMAIL_ADDR = [ "root" ]; # ZED_EMAIL_PROG = "${pkgs.send-mmsg}/bin/send-mmsg"; # or use lib.getExe # ZED_EMAIL_OPTS = "-"; # # ZED_NOTIFY_INTERVAL_SECS = 3600; # ZED_NOTIFY_VERBOSE = true; # # ZED_SCRUB_AFTER_RESILVER = true; # }; # zfs.zed.enableMail = false; # # Default hook ID if none is provided DEFAULT_HOOK_ID="xxxxxxxxxxxxxxxxxxxxxxxxx" # Ensure message text is provided if [ -z "$1" ]; then echo "Usage: $0 [hook_id]" exit 1 fi HOSTNAME=''$(${pkgs.nettools}/bin/hostname) # Extract arguments MESSAGE=$1 HOOK_ID=''${2:-$DEFAULT_HOOK_ID} # Read message from stdin if not provided if [ "$1" == "-" ]; then MESSAGE=$(cat) fi # Escape special characters in the message text for JSON ESCAPED_MESSAGE=$(echo "$MESSAGE" | sed 's/\\/\\\\/g; s/\"/\\\"/g') # Send the message using curl curl -i -X POST -H 'Content-Type: application/json' \ -d "{\"username\": \"$HOSTNAME\", \"text\": \"$ESCAPED_MESSAGE\"}" \ "https://YOUR-SERVER-ADDR/hooks/$HOOK_ID"