Skip to content

Commit

Permalink
Merge pull request #1 from openbridge/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
tspicer committed Apr 4, 2016
2 parents 28542b4 + 2081c5c commit 6ee5467
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
36 changes: 29 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,25 @@ For more information on the above parameters, please check out the Slack docs:
* https://api.slack.com/docs/attachments


### Examples
# Send A Message
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?"

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

These examples assumes you have set your token and webhook endpoint.
Here is a sample message and a screenshot of the message with various flags set.

```
slack -a -t "Hello World" -i ":slack:" -T "Titles are awesome" -p "Pretext is so helpful to include" -s "info"
```

Here is an example error message from Monit:

![Generic Message Examples](icons/png/generic-message.png?raw=true "Generic INFO")


Note: These examples assume you have set your token and webhook endpoint.

## Monit
Monit is a system monitoring and recovery tool. More on Monit here: https://mmonit.com/monit/
Expand Down Expand Up @@ -130,14 +141,25 @@ In a future release, the look and feel can be tailored to the specific Monit eve
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.

```
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"
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"
```
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
ok". Lastly, the <code>-M</code> flag is set to "monit". This tells Hacky Slack to use the Monit config.

Here is an example for monitoring crond:
```
check process crond with pidfile "/var/run/crond.pid"
start program = "/etc/init.d/crond start" with timeout 60 seconds
stop program = "/etc/init.d/crond stop"
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"
if 5 restarts within 5 cycles then timeout
```
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
ok". Lastly, the -M flag is set to "monit". This tells Hacky Slack to use the Monit config.
### Using Hacky Slack in with other apps.

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.

## Using Hacky Slack in with other apps.

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

# Icons

Expand Down
Binary file added icons/png/generic-message.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions slack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ source ${IPCONFIG}

function GET_HELP()
{
echo "Usage: [options]"
echo "Usage: [options]"
echo " options:"
echo "-a, Attachment Sends a messages as an attachment."
echo "-A, Author Small text used to display the author's name."
Expand Down Expand Up @@ -184,13 +184,13 @@ else
if test "${PRIORITY}" = "INFO"; then echo "INFO: STATUS (-s) was set to INFO..."; ICON=${ICON:-':info:'} && COLOR=${COLOR:-'#439FE0'}; fi
if test "${PRIORITY}" = "WARN"; then echo "INFO: STATUS (-s) was set to WARN..."; ICON=${ICON:-':warn:'} && COLOR=${COLOR:-'#ed7d21'}; fi
if test "${PRIORITY}" = "ERROR"; then echo "INFO: STATUS (-s) was set to ERROR..."; ICON=${ICON:-':error:'} && COLOR=${COLOR:-'#E21B6C'}; fi
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

# Set defaults
test -z "${TEXT}"; echo "WARNING: You do not have any TEXT (-t) specified in the message."; TEXT="${TEXT:-'This message is missing TEXT'}"
test -z "${TITLE}"; echo "WARNING: You do not have a TITLE (-T) specified for the message."; TITLE=${TITLE:-'This message is missing a TITLE'}
test -z "${PRETEXT}"; echo "WARNING: You do not have a PRETEXT (-p) specified for the message."; PRETEXT=${PRETEXT:-'This message is missing a PRETEXT'}
test -z "${CHANNEL}"; echo "WARNING: A CHANNEL (-c) was not set. Using the default CHANNEL..."; CHANNEL=${CHANNEL:-'general'}
test -z "${USERNAME}"; echo "INFO: A USERNAME (-u) was not specified for this POST to the Slack API. Setting a default username..."; USERNAME=${IP}
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'}

fi
Expand Down Expand Up @@ -224,7 +224,7 @@ PAYLOAD="payload={ \
\"title_link\": \"${TITLELINK}\", \
\"text\": \"${TEXT}\", \
\"mrkdwn_in\": [\"text\",\"pretext\",\"fields\"], \
\"fields\": [{\"title\": \"Status\",\"value\": \"${PRIORITY}\",\"short\": \"true\"}, {\"title\": \"Host\",\"value\": \"${IP}\",\"short\": \"true\"} ], \
\"fields\": [{\"title\": \"Status\",\"value\": \"${PRIORITY}\",\"short\": \"true\"}, {\"title\": \"Host\",\"value\": \"${USERNAME}\",\"short\": \"true\"} ], \
\"image_url\": \"${IMAGE}\", \
\"thumb_url\": \"${THUMBNAIL}\" \
}]}"
Expand Down

0 comments on commit 6ee5467

Please sign in to comment.