forked from bterp-web/elmsln
-
Notifications
You must be signed in to change notification settings - Fork 0
/
elmsln-grove-reporter
55 lines (53 loc) · 1.76 KB
/
elmsln-grove-reporter
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
#provide messaging colors for output to console
txtbld=$(tput bold) # Bold
bldgrn=${txtbld}$(tput setaf 2) # green
bldred=${txtbld}$(tput setaf 1) # red
txtreset=$(tput sgr0)
elmslnecho(){
echo "${bldgrn}$1${txtreset}"
}
elmslnwarn(){
echo "${bldred}$1${txtreset}"
}
#require input for the tweet in question
if [ -z "${1}" ]; then
elmslnwarn "[FAIL] No message recieved to broadcast"
exit 1
fi
#SLACK INTEGRATION
#Modify these variables for your environment
SLACK_HOSTNAME="" #FILL WITH YOUR HOSTNAME
SLACK_TOKEN="" #FILL WITH YOUR TOKEN
SLACK_CHANNEL="#qa" #CHANNEL TO WRITE TO
SLACK_CHANNEL2="#grove" #OPTIONAL SECOND CHANNEL TO WRITE TO
SLACK_USERNAME="ELMSLN-Grove" #NAME OF THE BOT
SLACK_ICON="http://elmsln.org/sites/default/files/elms_blackleaf_1.png" #ICON LOGO FOR BOT
SLACK_MESSAGE="${1}" #MESSAGE TO SEND, TAKES IN THE FIRST ARGUMENT TO DO THIS
#allow for attachments json to be passed in
if [ -z "${2}" ]; then
SLACK_ATTACHMENTS=''
else
SLACK_ATTACHMENTS="${2}"
fi
#Send message to Slack
payload="payload={
\"channel\": \"${SLACK_CHANNEL}\",
\"username\": \"${SLACK_USERNAME}\",
\"text\": \"${SLACK_MESSAGE}\",
\"icon_url\": \"${SLACK_ICON}\"
${SLACK_ATTACHMENTS}
}"
rep=$(curl -X POST --data-urlencode "${payload}" https://${SLACK_HOSTNAME}/services/hooks/incoming-webhook?token=${SLACK_TOKEN} 2>&1)
elmslnecho "${rep}"
#now against the second location specific to this command running
payload="payload={
\"channel\": \"${SLACK_CHANNEL2}\",
\"username\": \"${SLACK_USERNAME}\",
\"text\": \"${SLACK_MESSAGE}\",
\"icon_url\": \"${SLACK_ICON}\"
${SLACK_ATTACHMENTS}
}"
rep=$(curl -X POST --data-urlencode "${payload}" https://${SLACK_HOSTNAME}/services/hooks/incoming-webhook?token=${SLACK_TOKEN} 2>&1)
elmslnecho "${rep}"
exit 1