#!/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}" timestamp="$(jq -n "{version:{timestamp:\"$(date +%s)\"}}")" 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 '.source.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 < /tmp/compact_body.json curl -v -X POST -T /tmp/compact_body.json -H "Content-Type: application/json" "${apprise_host}/notify/${apprise_key}" echo "${timestamp}" >&3