Skip to content

Commit 6ee5467

Browse files
committed
Merge pull request #1 from openbridge/develop
Develop
2 parents 28542b4 + 2081c5c commit 6ee5467

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

README.md

Lines changed: 29 additions & 7 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/
@@ -130,14 +141,25 @@ In a future release, the look and feel can be tailored to the specific Monit eve
130141
Below is a Monit statement triggers an alert if the memory exceeds 15MB for 2 cycles. It will repeat the alert every 3 cycles. Once the condition that triggered the alert returns to normal, Monit will issue an all clear message to Slack.
131142

132143
```
133-
if memory > 15 MB for 2 cycles then exec /usr/bin/bash -c "sh /usr/local/bin/slack.sh -a -c #testing -s error -M monit >> /ebs/logs/foo.log 2<&1" 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 >> /ebs/logs/foo.log 2<&1"
144+
if memory > 15 MB for 2 cycles then exec /usr/bin/bash -c "sh /usr/local/bin/slack.sh -a -c #testing -s error -M monit >> /ebs/logs/foo.log 2<&1" 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 >> /ebs/logs/foo.log 2<&1"
145+
```
146+
The <code>-a</code> flag sets the attachment flag. This is the expanded message format seen above. The <code>-c</code> flag sets the channel to deliver the message to. In this case the channel is "#testing". The <code>-s</code> flag sets the status the message should inherit. The example above uses "error" and
147+
ok". Lastly, the <code>-M</code> flag is set to "monit". This tells Hacky Slack to use the Monit config.
148+
149+
Here is an example for monitoring crond:
150+
```
151+
check process crond with pidfile "/var/run/crond.pid"
152+
start program = "/etc/init.d/crond start" with timeout 60 seconds
153+
stop program = "/etc/init.d/crond stop"
154+
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"
155+
if 5 restarts within 5 cycles then timeout
134156
```
135-
The -a flag sets the attachment flag. This is the expanded message format seen above. The -c flag sets the channel to deliver the message to. In this case the channel is "testing". The -s flag sets the status the message should inherit. The example above uses "error" and
136-
ok". Lastly, the -M flag is set to "monit". This tells Hacky Slack to use the Monit config.
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.
137160

138-
## Using Hacky Slack in with other apps.
139161

140-
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
141163

142164
# Icons
143165

icons/png/generic-message.png

55.6 KB
Loading

slack.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ source ${IPCONFIG}
8383

8484
function GET_HELP()
8585
{
86-
echo "Usage: [options]"
86+
echo "Usage: [options]"
8787
echo " options:"
8888
echo "-a, Attachment Sends a messages as an attachment."
8989
echo "-A, Author Small text used to display the author's name."
@@ -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)