#!/bin/sh if echo "$MONIT_EVENT" | grep -q "succeeded$"; then DISCORD_TITLE="[M/Monit] OK Alert" DISCORD_COLOR="5763719" elif echo "$MONIT_EVENT" | grep -q "failed$"; then DISCORD_TITLE="[M/Monit] Critical Alert" DISCORD_COLOR="15548997" elif echo "$MONIT_EVENT" | grep -Eq "changed$|matched$"; then DISCORD_TITLE="[M/Monit] Warning Alert" DISCORD_COLOR="16776960" else DISCORD_TITLE="[M/Monit] Generic Alert" DISCORD_COLOR="5793266" fi # Generate the Discord message payload generate_payload() { printf '{ "embeds": [{ "title": "%s", "color": "%s", "fields": [ { "name": "Date", "value": "%s", "inline": true }, { "name": "Host", "value": "%s", "inline": true }, { "name": "Service", "value": "%s", "inline": true }, { "name": "Action", "value": "%s", "inline": true }, { "name": "Event", "value": "%s", "inline": false }, { "name": "Description", "value": "%s", "inline": false } ] }] }' "$DISCORD_TITLE" "$DISCORD_COLOR" "$MONIT_DATE" "$MONIT_HOST" "$MONIT_SERVICE" "$MONIT_ACTION" "$MONIT_EVENT" "$MONIT_DESCRIPTION" } # Generate and send the payload payload=$(generate_payload) curl -H "Content-Type: application/json" -d "$payload" "$ENDPOINT"