Skip to content

Commit 2081c5c

Browse files
committed
fix bug with username
1 parent 5434984 commit 2081c5c

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

README.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,25 @@ For more information on the above parameters, please check out the Slack docs:
7979
* https://api.slack.com/docs/attachments
8080

8181

82-
### Examples
82+
# Send A Message
8383
The channel is "general" with username "hacky-slack". The icon is "apple" and the author is "apple". The author name is linked to "apple.com" and the text sent in the message is "Where are the new 2016 Macbook models?"
8484

8585
```
8686
slack -c "#general" -u "hacky-slack" -i "apple" -a "Macbook" -b "http://www.apple.com/ -t "Where are the new 2016 Macbook models?"
8787
```
8888

89-
These examples assumes you have set your token and webhook endpoint.
89+
Here is a sample message and a screenshot of the message with various flags set.
90+
91+
```
92+
slack -a -t "Hello World" -i ":slack:" -T "Titles are awesome" -p "Pretext is so helpful to include" -s "info"
93+
```
94+
95+
Here is an example error message from Monit:
96+
97+
![Generic Message Examples](icons/png/generic-message.png?raw=true "Generic INFO")
98+
99+
100+
Note: These examples assume you have set your token and webhook endpoint.
90101

91102
## Monit
92103
Monit is a system monitoring and recovery tool. More on Monit here: https://mmonit.com/monit/
@@ -143,9 +154,12 @@ check process crond with pidfile "/var/run/crond.pid"
143154
if 2 restarts within 3 cycles then exec /usr/bin/bash -c "sh /usr/local/bin/slack.sh -a -c #testing -s error -M monit" repeat every 3 cycles else if succeeded then exec /usr/bin/bash -c "sh /usr/local/bin/slack.sh -a -c #testing -s ok -M monit"
144155
if 5 restarts within 5 cycles then timeout
145156
```
146-
## Using Hacky Slack in with other apps.
157+
### Using Hacky Slack in with other apps.
158+
159+
Hacky Slack can be extended to support other applications besides Monit. For example, Nagios monitoring or Cron. Really, any application can send messages via Hacky Slack.
160+
147161

148-
Hacky Slack can be extended to support other applications. For example, Nagios monitoring or Cron. Really, any application can send messages via Hacky Slack.
162+
Since no user (<code>- u</code>) was specified it will default to using the host system IP address
149163

150164
# Icons
151165

icons/png/generic-message.png

55.6 KB
Loading

slack.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,13 @@ else
184184
if test "${PRIORITY}" = "INFO"; then echo "INFO: STATUS (-s) was set to INFO..."; ICON=${ICON:-':info:'} && COLOR=${COLOR:-'#439FE0'}; fi
185185
if test "${PRIORITY}" = "WARN"; then echo "INFO: STATUS (-s) was set to WARN..."; ICON=${ICON:-':warn:'} && COLOR=${COLOR:-'#ed7d21'}; fi
186186
if test "${PRIORITY}" = "ERROR"; then echo "INFO: STATUS (-s) was set to ERROR..."; ICON=${ICON:-':error:'} && COLOR=${COLOR:-'#E21B6C'}; fi
187+
if test -z "${USERNAME}"; then echo "INFO: A USERNAME (-u) was not specified for this POST to the Slack API. Setting a default username..."; USERNAME="${IP}"; fi
187188

188189
# Set defaults
189190
test -z "${TEXT}"; echo "WARNING: You do not have any TEXT (-t) specified in the message."; TEXT="${TEXT:-'This message is missing TEXT'}"
190191
test -z "${TITLE}"; echo "WARNING: You do not have a TITLE (-T) specified for the message."; TITLE=${TITLE:-'This message is missing a TITLE'}
191192
test -z "${PRETEXT}"; echo "WARNING: You do not have a PRETEXT (-p) specified for the message."; PRETEXT=${PRETEXT:-'This message is missing a PRETEXT'}
192193
test -z "${CHANNEL}"; echo "WARNING: A CHANNEL (-c) was not set. Using the default CHANNEL..."; CHANNEL=${CHANNEL:-'general'}
193-
test -z "${USERNAME}"; echo "INFO: A USERNAME (-u) was not specified for this POST to the Slack API. Setting a default username..."; USERNAME=${IP}
194194
test -z "${PRIORITY}"; echo "INFO: STATUS (-s) was not set. Setting a default STATUS to INFO..."; PRIORITY=${PRIORITY:-'INFO'} && ICON=${ICON:-':info:'} && COLOR=${COLOR:-'#439FE0'}
195195

196196
fi
@@ -224,7 +224,7 @@ PAYLOAD="payload={ \
224224
\"title_link\": \"${TITLELINK}\", \
225225
\"text\": \"${TEXT}\", \
226226
\"mrkdwn_in\": [\"text\",\"pretext\",\"fields\"], \
227-
\"fields\": [{\"title\": \"Status\",\"value\": \"${PRIORITY}\",\"short\": \"true\"}, {\"title\": \"Host\",\"value\": \"${IP}\",\"short\": \"true\"} ], \
227+
\"fields\": [{\"title\": \"Status\",\"value\": \"${PRIORITY}\",\"short\": \"true\"}, {\"title\": \"Host\",\"value\": \"${USERNAME}\",\"short\": \"true\"} ], \
228228
\"image_url\": \"${IMAGE}\", \
229229
\"thumb_url\": \"${THUMBNAIL}\" \
230230
}]}"

0 commit comments

Comments
 (0)