2023-05-26 18:04:49 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# https://github.com/cloudfoundry-community/slack-notification-resource/blob/master/out
|
|
|
|
# https://github.com/caronc/apprise-api#persistent-storage-solution
|
|
|
|
set -e
|
|
|
|
|
|
|
|
cd "${1}"
|
|
|
|
|
2023-05-26 21:14:00 +00:00
|
|
|
timestamp="$(jq -n "{version:{timestamp:\"$(date +%s)\"}}")"
|
|
|
|
|
2023-05-26 18:04:49 +00:00
|
|
|
exec 3>&1
|
|
|
|
exec 1>&2
|
|
|
|
|
|
|
|
payload=$(mktemp /tmp/resource-in.XXXXXX)
|
|
|
|
cat > "${payload}" <&0
|
|
|
|
|
|
|
|
apprise_host="$(jq -r '.source.host' < "${payload}")"
|
|
|
|
|
|
|
|
apprise_key="$(jq -r '.params.key' < "${payload}")"
|
|
|
|
alert_body="$(jq -r '.params.body' < "${payload}")"
|
|
|
|
alert_title="$(jq -r '.params.title // null' < "${payload}")"
|
|
|
|
alert_type="$(jq -r '.params.type // null' < "${payload}")"
|
|
|
|
alert_tag="$(jq -r '.params.tag // null' < "${payload}")"
|
|
|
|
alert_format="$(jq -r '.params.format // null' < "${payload}")"
|
|
|
|
|
|
|
|
echo "${alert_body}"
|
|
|
|
|
|
|
|
alert_body="$(eval "printf \"${alert_body}\"" | jq -R -s .)"
|
|
|
|
[ "${alert_title}" != "null" ] && alert_title="$(eval "printf \"${alert_title}\"" | jq -R -s .)"
|
|
|
|
[ "${alert_type}" != "null" ] && alert_type="$(eval "printf \"${alert_type}\"" | jq -R -s .)"
|
|
|
|
[ "${alert_tag}" != "null" ] && alert_tag="$(eval "printf \"${alert_tag}\"" | jq -R -s .)"
|
|
|
|
[ "${alert_format}" != "null" ] && alert_format="$(eval "printf \"${alert_format}\"" | jq -R -s .)"
|
|
|
|
|
|
|
|
body="$(cat <<EOF
|
|
|
|
{
|
|
|
|
"body": ${alert_body},
|
|
|
|
"title": ${alert_title},
|
|
|
|
"type": ${alert_type},
|
|
|
|
"tag": ${alert_tag},
|
|
|
|
"format": ${alert_format}
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
)"
|
|
|
|
|
|
|
|
compact_body="$(echo "${body}" | jq -c '.')"
|
|
|
|
echo "$compact_body" | jq 'del(..|nulls)' > /tmp/compact_body.json
|
|
|
|
|
|
|
|
curl -v -X POST -T /tmp/compact_body.json -H "Content-Type: application/json" "${apprise_host}/notify/${apprise_key}"
|
|
|
|
|
2023-05-26 21:14:00 +00:00
|
|
|
echo "${timestamp}" >&3
|