You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+29-7Lines changed: 29 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -79,14 +79,25 @@ For more information on the above parameters, please check out the Slack docs:
79
79
*https://api.slack.com/docs/attachments
80
80
81
81
82
-
### Examples
82
+
#Send A Message
83
83
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?"
84
84
85
85
```
86
86
slack -c "#general" -u "hacky-slack" -i "apple" -a "Macbook" -b "http://www.apple.com/ -t "Where are the new 2016 Macbook models?"
87
87
```
88
88
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"
Note: These examples assume you have set your token and webhook endpoint.
90
101
91
102
## Monit
92
103
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
130
141
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.
131
142
132
143
```
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
134
156
```
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.
137
160
138
-
## Using Hacky Slack in with other apps.
139
161
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
Copy file name to clipboardExpand all lines: slack.sh
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -83,7 +83,7 @@ source ${IPCONFIG}
83
83
84
84
functionGET_HELP()
85
85
{
86
-
echo"Usage: [options]"
86
+
echo"Usage: [options]"
87
87
echo" options:"
88
88
echo"-a, Attachment Sends a messages as an attachment."
89
89
echo"-A, Author Small text used to display the author's name."
@@ -184,13 +184,13 @@ else
184
184
iftest"${PRIORITY}" = "INFO";thenecho"INFO: STATUS (-s) was set to INFO..."; ICON=${ICON:-':info:'}&& COLOR=${COLOR:-'#439FE0'};fi
185
185
iftest"${PRIORITY}" = "WARN";thenecho"INFO: STATUS (-s) was set to WARN..."; ICON=${ICON:-':warn:'}&& COLOR=${COLOR:-'#ed7d21'};fi
186
186
iftest"${PRIORITY}" = "ERROR";thenecho"INFO: STATUS (-s) was set to ERROR..."; ICON=${ICON:-':error:'}&& COLOR=${COLOR:-'#E21B6C'};fi
187
+
iftest -z "${USERNAME}";thenecho"INFO: A USERNAME (-u) was not specified for this POST to the Slack API. Setting a default username..."; USERNAME="${IP}";fi
187
188
188
189
# Set defaults
189
190
test -z "${TEXT}";echo"WARNING: You do not have any TEXT (-t) specified in the message."; TEXT="${TEXT:-'This message is missing TEXT'}"
190
191
test -z "${TITLE}";echo"WARNING: You do not have a TITLE (-T) specified for the message."; TITLE=${TITLE:-'This message is missing a TITLE'}
191
192
test -z "${PRETEXT}";echo"WARNING: You do not have a PRETEXT (-p) specified for the message."; PRETEXT=${PRETEXT:-'This message is missing a PRETEXT'}
192
193
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}
194
194
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'}
0 commit comments