66
77# Default WEBHOOK to post messages
88if [[ -n ${WEBHOOK} ]]; then
9+
910 echo " INFO: The Slack API WEBHOOK was passed via the command line (-w)"
11+
1012elif [[ -n ${SLACK_WEBHOOK} ]]; then
13+
1114 echo " INFO: The Slack API TOKEN was set as a system variable"
1215 TOKEN=${SLACK_WEBHOOK}
16+
1317else
18+
1419 echo " INFO: Using default Slack API endpoint to POST messages..."
1520 WEBHOOK=${WEBHOOK-' https://hooks.slack.com/services/' }
21+
1622fi
1723
1824echo " ${SLACK_TOKEN} "
1925# Default TOKEN to post messages
2026if [[ -n ${TOKEN} ]]; then
27+
2128 echo " INFO: The Slack API TOKEN was passed via the command line (-k)"
29+
2230elif [[ -n ${SLACK_TOKEN} ]]; then
31+
2332 echo " INFO: The Slack API TOKEN was set as a system variable"
2433 TOKEN=${SLACK_TOKEN}
34+
2535else
2636 echo " ERROR: No Slack API TOKEN was found. Can not proceed with posting messages to the API without one."
2737 exit 1
@@ -46,17 +56,23 @@ if test "${PRIORITY}" = "OK"; then echo "INFO: STATUS (-s) was set to OK..."; IC
4656
4757# Check for the IP address every 2 hours. Use cache for anything < 2 hours
4858if [[ ! -f " ${IPCONFIG} " ]]; then
59+
4960echo " ${IPCONFIG} does not exist"
5061IP=$( curl -s checkip.dyndns.org| sed -e ' s/.*Current IP Address: //' -e ' s/<.*$//' )
5162echo " IP=${IP} " > ${IPCONFIG}
52- else
5363
54- if test " find '${IPCONFIG} ' -mmin +120" ; then
55- echo " ${IPCONFIG} is less than 2 hours old."
5664else
57- IP=$( curl -s checkip.dyndns.org| sed -e ' s/.*Current IP Address: //' -e ' s/<.*$//' )
58- echo " IP=${IP} " > ${IPCONFIG}
59- fi
65+
66+ if test " find '${IPCONFIG} ' -mmin +120" ; then
67+
68+ echo " ${IPCONFIG} is less than 2 hours old."
69+
70+ else
71+
72+ IP=$( curl -s checkip.dyndns.org| sed -e ' s/.*Current IP Address: //' -e ' s/<.*$//' )
73+ echo " IP=${IP} " > ${IPCONFIG}
74+
75+ fi
6076fi
6177
6278source ${IPCONFIG}
@@ -101,6 +117,7 @@ exit 1
101117else
102118
103119while getopts " aA:b:B:c:Chi:I:m:N:p:s:t:T:L:k:u:w" opt; do
120+
104121 case ${opt} in
105122 a) ATTACHMENT=" true" ;;
106123 A) AUTHOR=" ${OPTARG} " ;;
@@ -224,6 +241,7 @@ PAYLOAD="payload={ \
224241 \" mrkdwn\" : \" true\" \
225242 }"
226243fi
244+
227245# Send the payload to the Slack API
228246POST=$( curl -s -S -X POST --data-urlencode " ${PAYLOAD} " " ${WEBHOOK}${TOKEN} " ) ;
229247
0 commit comments