+# -----------------------------------------------------------------------------
+# pushbullet sender
+
+send_pushbullet() {
+ local userapikey="${1}" recipients="${2}" message="${3}" title="${4}" httpcode sent=0 user
+ if [ "${SEND_PUSHBULLET}" = "YES" -a ! -z "${userapikey}" -a ! -z "${recipients}" -a ! -z "${message}" -a ! -z "${title}" ]
+ then
+ #https://docs.pushbullet.com/#create-push
+ for user in ${recipients}
+ do
+ httpcode=$(${curl} --write-out %{http_code} --silent --output /dev/null \
+ --header 'Access-Token: '$userapikey'' \
+ --header 'Content-Type: application/json' \
+ --data-binary @<(cat <<EOF
+ {"title": "${title}",
+ "type": "note",
+ "email": "${user}",
+ "body": "$( echo -n ${message})"}
+EOF
+ ) "https://api.pushbullet.com/v2/pushes" -X POST)
+
+ if [ "${httpcode}" == "200" ]
+ then
+ echo >&2 "${me}: Sent pushbullet notification for: ${host} ${chart}.${name} is ${status} to '${user}'"
+ sent=$((sent + 1))
+ else
+ echo >&2 "${me}: Failed to send pushbullet notification for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
+ fi
+ done
+
+ [ ${sent} -gt 0 ] && return 0
+ fi
+
+ return 1
+}