From 8ff9ca1294d9994f73a688edde7555af4709b0b2 Mon Sep 17 00:00:00 2001 From: Pim Kunis Date: Fri, 26 May 2023 20:04:49 +0200 Subject: [PATCH] init --- Dockerfile | 7 +++++++ check | 1 + example.json | 12 ++++++++++++ in | 1 + out | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 68 insertions(+) create mode 100644 Dockerfile create mode 100755 check create mode 100644 example.json create mode 100755 in create mode 100755 out diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1bff368 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM badouralix/curl-jq:latest + +COPY ./check /opt/resource/check +COPY ./in /opt/resource/in +COPY ./out /opt/resource/out + +RUN chmod +x /opt/resource/out /opt/resource/in /opt/resource/check diff --git a/check b/check new file mode 100755 index 0000000..1a24852 --- /dev/null +++ b/check @@ -0,0 +1 @@ +#!/bin/sh diff --git a/example.json b/example.json new file mode 100644 index 0000000..2639fe0 --- /dev/null +++ b/example.json @@ -0,0 +1,12 @@ +{ + "params": { + "key": "concourse", + "body": "hoi", + "title": "Titeltje!", + "type": "warning", + "format": "text" + }, + "source": { + "host": "https://apprise.pim.kunis.nl:444" + } +} diff --git a/in b/in new file mode 100755 index 0000000..1a24852 --- /dev/null +++ b/in @@ -0,0 +1 @@ +#!/bin/sh diff --git a/out b/out new file mode 100755 index 0000000..457dab6 --- /dev/null +++ b/out @@ -0,0 +1,47 @@ +#!/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}" + +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 < /tmp/compact_body.json + +curl -v -X POST -T /tmp/compact_body.json -H "Content-Type: application/json" "${apprise_host}/notify/${apprise_key}" + +echo "{}" >&3