Skip to content

Commit

Permalink
fix bug with username
Browse files Browse the repository at this point in the history
  • Loading branch information
tspicer committed Apr 4, 2016
1 parent 5434984 commit 2081c5c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
22 changes: 18 additions & 4 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 @@ -143,9 +154,12 @@ check process crond with pidfile "/var/run/crond.pid"
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
```
## Using Hacky Slack in with other apps.
### 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.


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.
4 changes: 2 additions & 2 deletions slack.sh
Original file line number Diff line number Diff line change
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 2081c5c

Please sign in to comment.