coursehero / slacktee Goto Github PK
View Code? Open in Web Editor NEWslacktee is a bash script that works like tee command. Instead of writing the standard input to files, slacktee posts it to Slack.
License: Apache License 2.0
slacktee is a bash script that works like tee command. Instead of writing the standard input to files, slacktee posts it to Slack.
License: Apache License 2.0
I was wondering if it would be possible to do something like:
./script | slacktee.sh -flag to directly send input as it comes, but without editing it
the problem with editing with further text is that it might fail and sometimes that is not wanted.
So --streaming
flag but without editing when more input comes
Would it be possible to slack a message that uses e.g @channel
or @<username>
to notify people of things?
Hi!
It's possible to send message to user by using "@username" as channel parameter.
For now, it's hardcoded to add # sign to channel name.
Below my patch that will add # sign only if channel name doesn't start with it nor with @ sign. So it's possible to send messages with "-c @username" option.
--- a/slacktee.sh
+++ b/slacktee.sh
@@ -98,7 +98,10 @@ function send_message(){
message_attr="\"text\": \"$escaped_message\","
fi
- json="{\"channel\": \"#$channel\", \"username\": \"$username\", $message_attr \"icon_emoji\": \":$icon:\" $parseMode}"
+ if [[ ( "$channel" != "#"* ) && ( "$channel" != "@"* ) ]]; then
+ channel="#$channel"
+ fi
+ json="{\"channel\": \"$channel\", \"username\": \"$username\", $message_attr \"icon_emoji\": \":$icon:\" $parseMode}"
curl -X POST --data-urlencode "payload=$json" "$webhook_url" &> /dev/null
fi
}
Would be super great to have slacktee stream output to Slack. It could update the comment as output comes in.
I'm not sure if this is a bug or not, but when sending over 4k characters, the rich formats breaks and the message it's sent like this:
message1:
`(3)
message
message2:
abcabc
`(3)
so the rich format doesn't work and looks a bit ugly
Line 594 in 22e0189
In lines 594, 598, and 602, the leading comma in the parseMode
string, when combined with the json builder (e.g., lines 318-320), creates json like ... "icon_emoji": ":wrench:", , "link_names": "1"}
. The double comma causes an invalid_json
error to be returned.
The simplest fix seems to be just dropping that comma in each of those three lines, instead making them parseMode='"parse":"none"
and so on.
How do you get images to expand in the slack channel? It's not as fun when you just see a url.
Hello,
I think Slack has changed the way Incoming Webhooks work and they no longer allow customization of the message
https://api.slack.com/incoming-webhooks#advanced_message_formatting
You *cannot* override the default channel (chosen by the user who installed your app), username, or icon when you're using Incoming Webhooks to post messages. Instead, these values will always inherit from the associated Slack app configuration.
This makes some of the slacktee
flags inoperative. Being able to control the channel is especially useful.
Hello,
I have a weird question. I have 2 vps and they print the output differently.
As you can see, the first one has that line, and when reaching half the line, it goes to the second line, which is annoying as fuck.
my other bot prints it perfectly (last line of output).
In both of them I just tried echo abc | slacktee -c channel
.
Any way to control this? or know why this is happening?
Please, add ability to skip interactive setup at the end of the installation.
Hello,
I used to use slacktee on CentOS 7, worked great. I'm having issues getting it to work on Debian. I'm fairly certain I've copy/pasted the webhook url and token into the prompts correctly as before, I've typed in the correct channel as before, but something like echo "testing 123" | slacktee.sh
isn't working for me, and there are no errors displayed.
the slacktee.sh command is available, and it's in my path:
root@FOGTESTING:~# command -v slacktee.sh
/usr/local/bin/slacktee.sh
root@FOGTESTING:~# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Where are the logs? What should I check?
Thanks,
Wayne
Currently, slacktee
exits immediately with the error code if it fails to send a message to Slack or some other errors happen (e.g. webhook URL is not configured).
However, this was not ideal behavior as a tee-like-command because it blocks piped subsequent commands.
Here is the example:
cat test.txt | slacktee -n | mail [email protected]
If webhook URL is not configured, slacktee
fails immediately and following mail
command cannot read the output of cat
command.
cat test.txt | tee inaccessible_file.txt | mail [email protected]
Even if tee
cannot open inaccessible_file.txt
, tee
outputs an error message to STDERR and then continues to pass the input to mail
command.
In order to minimize the chance to interfere the operation of the piped subsequent commands, slacktee
should try to follow the error handling behavior of tee
command.
Hi
Currently using slacktee to send notifications to administrators via various scripts but I would also like the ability to use /remind to setup reminders as well. Currently trying the following:
echo "/remind @user to do something in 10 minutes" | slacktee.sh -u @otheruser -p -m link_names
but it just prints that and /remind isn't invoked. Am I missing something? Is this even possible?
Thanks
Ben
When running in a plain alpine container (with bash and curl installed), I was getting this error:
bash-4.4# slacktee
/usr/local/bin/slacktee: line 792: warning: here-document at line 406 delimited
by end-of-file (wanted `EOF')
/usr/local/bin/slacktee: line 793: syntax error: unexpected end of file
Removing the indentation of the closing EOF
in this block fixes the problem:
Lines 406 to 415 in 86522a9
I needed some stuff to be posted into thread for my logging purposes on production, so I came up with the following:
function get_thread_ts() {
local response=$1
echo "$(echo "$response" | jq -r .message.ts)"
}
in function send_message() add to json
"thread_ts": "$thread_ts",
(var $thread_ts can be empty, slack will ignore it)
in function send_message() execute get_thread_ts in else part:
if [[ $(get_ok_in_response "$post_result") != "true" ]]; then
write_to_stderr "$post_result"
exit_code=1
else
get_thread_ts "$post_result"
fi
upload_result="$(curl -F file=@"$filename" -F token="$token" $channels_param -F thread_ts="$thread_ts" https://slack.com/api/files.upload 2> /dev/null)"
And now I can do stuff like this:
thread_ts=$(echo anything|slacktee -q)
echo something|slacktee -r $thread_ts
Hello,
If i use slacktee.sh to send an "ls" or "echo" command to my slack channel it's working.
Nevertheless, when i try to send a "tail" like this :
tail -f app/logs/prod.log | grep "INSERT INTO" | slacktee.sh -n
I received this error, the grep is write into my prompt :
invalid_payload
Why ? do you have an idea ?
Thanks a lot for your help !
It would be useful to have negative conditions. E.g. to consider all lines that do not start with "Success" as failure:
tail -f app.log | slacktee.sh -n -a "good" -no "danger" "^Success:" -nd "@channel" "^Success:" -m link_names
Hi Team
I don't have access to a token but was only provided a webhook.
Whenever I run slacktee.sh after installation, I get
slacktee.sh: Please setup the authentication token or the incoming webhook url (deprecated).
Can you please help me on how to configure the webhook url.
Thanks in advance.
I am trying to send some text of a file like:
cat file | slacktee
But I am getting this error:
slacktee.sh: {"ok":false,"error":"invalid_json"}
The file is pure text and I can't show it because it has sensitive information, but even if it was json (which it isn't) why it is failing with this error?
Would it be possible to slack a message that uses e.g @all
or @<username>
to notify people of things?
edit: nevermind, just found this: https://api.slack.com/docs/formatting
Add the -v flag so we can quickly check for last version!
A more standard way of distributing software in Linux OS is by using package manager - this allows to specify dependencies. There's at least two existing issues caused by the missing curl.
There is a workaround for this problem: https://github.com/course-hero/slacktee/pull/38/files but it will only check for curl when you try to use it for the first time, not when trying to install it.
I am probably just doing something wrong. But my string im sending to slack is one big string not multiple variables. So I'm trying to make new lines. \n does not work. How can make sure the new lines are parsed and not stripped?
Hello everybody,
I testet this script on a new server install where no curl was installed. The script failed silently which made it hard to find the cause of no message appearing in slack. (I know: rtfm, you stated it uses curl on README)
Expected behaviour: check if curl command fails and output some kind of error message.
Otherwise it's a great project, with curl installed it works like a charm π
How can I send a slack message with only attachments? When I tried like the below, slacktee just ignored my command.
Is there any way?
echo "" | ./slacktee.sh -c "test-channel" -a good -e abc 123 -s abc 123
I wanted to ask if slacktee does any kind of logs of the alerts it sends? trying to identify the origin from some alerts and I can't do it
dgengtek found this issue in PR #32
since read doesn't read any backslashes without option -r anyway.
and tabs gets eaten
$ echo 'a\\ttest' | bash slacktee.sh
slacktee receives, a\ttest
, outputs on slack is, atest
$ echo 'a\\\\ttest' | bash slacktee.sh
slacktee receives, a\\ttest
, outputs on slack is, a\ttest
even though on line 180 line="$(echo "$1" | sed $'s/\t/ /g')"
should replace a tab char with space
Great script, thanks for this!
Removing the :: from line 105 (icon=":$1:") fixes this.
https://github.com/course-hero/slacktee/blob/master/slacktee.sh#L105
When providing output from color to send to slack, slacktee gives a json error. I got this error when using a public tool called nuclei which gave a one line output of color, and when piping it to slacktee it gave this error:
slacktee.sh: {"ok":false,"error":"invalid_json"}
I guess this happens because of the color, since when removing it slacktee had no problems. Maybe add a condition to remove colorful output so it doesn't give this error? not sure
I've made a custom version of slacktee for myself and found this problem happening with me with function get_ok_in_response()
you call it in test:
if [[ $(get_ok_in_response $post_result) != "true" ]]; then
I'd pass "$post_result" like this cause if slack api changes order of returning json you'll be in trouble
root@mpro-ns-1:~# echo $ok
{"ok":true,text":"a b c"}
root@mpro-ns-1:~# get_ok_in_response $ok
true
root@mpro-ns-1:~# echo $not_ok
{text":"a b c","ok":true}
root@mpro-ns-1:~# get_ok_in_response $not_ok
root@mpro-ns-1:~# get_ok_in_response "$not_ok"
true
in rsyslog.conf I have the following
:msg, contains, "NODFLT001" ^/root/slacktee-master/slacktee.sh
when the event with NODFLT appears nothing is sent to slack
What do you think?
I'm used to change it as a difference between custom/local scripts to installed tools.
In any case that's a really useful script, π»
Hello,
I have a bot with channel-join, chat:write, and file:write.
I am already sending messages throw webhook, but when using slacktee I get this message:
slacktee.sh: {"ok":false,"error":"not_in_channel"}
The bot is already in the channel I want to post messages, and in the configuration I put that exact channel
Hey there,
I'm definitely a CLI novice, but have been using slack for a while, and I can't figure out how to integrate this into our team's site.
For "token", should this be an OAuth Slack API App? Or a webhook integration? It asks for integration token, so I assume a web hook integration? But I can't find tokens for web hooks. So I created an API app, but I don't see a token there either. Looks like I would have to do something with OAuth and get my user token that way? Is this a required step? I can't tell in the readme.
Looks really cool, but I'm stuck setting this up. And I presume others will be too :-(
Makes the script very unhappy.
slacktee.sh by default doesn't work with crontab because /usr/local/bin is not included in crontab path, so manually i have to move into /bin directory, it would be great if you move in /bin or /usr/bin directory by default.
I took quite long to figure out these thing.
Hi
This application is really useful and helps so much with a simple thing of posting a message to Slack.
I have an issue though. I am trying to run this bash script as a service.
/tmp/temp.sh
#!/bin/bash
tail -f /tmp/metrics.out | slacktee.sh -u 'snmptrap' -n
The service file is
cat /etc/systemd/system/slack-snmp.service
[Unit]
Description= Send SNMP traps received on telegraf to slack service.
[Service]
Type=simple
ExecStart=/tmp/temp.sh
[Install]
WantedBy=multi-user.target
However on starting the service, it is not able to read the .slacktee file
systemctl status slack-snmp
β slack-snmp.service - Send SNMP traps received on telegraf to slack service.
Loaded: loaded (/etc/systemd/system/slack-snmp.service; disabled; vendor preset: enabled)
Active: active (running) since Fri 2020-03-13 01:15:39 UTC; 6s ago
Main PID: 10650 (temp.sh)
Tasks: 2 (limit: 4915)
CGroup: /system.slice/slack-snmp.service
ββ10650 /bin/bash /tmp/temp.sh
ββ10651 tail -f /tmp/metrics.out
Mar 13 01:15:39 snmp-trap-1 systemd[1]: Started Send SNMP traps received on telegraf to slack service..
Mar 13 01:15:39 snmp-trap-1 temp.sh[10650]: slacktee.sh: Please setup the authentication token or the incoming webhook url (deprecated).
Can you please help me how I can run this shell script as a service and show the file .slacktee
Thanks you in advance.
Great program indeed.
The files.upload API is being deprecated. slacktee makes usage of it here
Line 884 in c439618
We want to inform you of two important dates related to upcoming changes to support for the files.upload web API method
To prepare for this change, we recommend migrating away from files.upload and instead using the combination of files.getUploadURLExternal and files.completeUploadExternal. More information on how to use these two APIs together can be found on our Uploading files documentation. You can also leverage Slackβs SDKs to help you transition to this new way of uploading files by visiting our api.slack page.
I expected this
(echo "bliblablu test 123"; sleep 5; echo "blibla error kfgjk"; sleep 5)|../tools/build/gae/slacktee.sh --streaming -o "danger" ".*error.*" -s head das -s env das -s branch das -s commit/tag abcder -e log "https://console.cloud.google.com/cloud-build/builds/$BUILD_ID" -c "@jonas.strassel"
to be a message marked red. instead it changes its color back to grey. I my expectation wrong?
If nothing is passed to slacktee with -f option, an error happens in the cleanup process of the temp file.
Example)
rm: /tmp/2381-01042016-131201.log: No such file or directory
Also, a meaning less message is posted to Slack as following:
Input file has been uploaded.
You can download it from the link below.
If input is empty, slacktee shouldn't do anything like buffering/non-buffering mode.
Hi,
I really like slacktee and would like to use parts of it for a project. Therefore I have to change something.
As the Apache Licenses states, I have to mark my changes in the copyright notice.
Unfortunately there is none.
There is a paragraph about applying the Apache license in its appendix, which states:
" APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format[...]"
It would be great if you could add a copyright notice, so i can use your code, or do you prefer it in a different way?
Best regards
Ive spent several days trying to get slacktee to work with the root crontab. I installed it as per the instructions in the readme. I also included all the path variables i could think of in the crontab, however it did not work. When i looked in slacktee.sh i noticed there was no webhook url set. So i set it in there and it worked. So it seems that sudo cron jobs cant read the config in my home directory. Not sure if there is a better way to fix this?
While testing out the script (amazing work, btw), I typed slacktee.sh
in my terminal.
It gave me a warning about "using the URL is deprecated, please use token" and then it hung, with CTRL+C not aborting. I was forced to restart my terminal session.
Thoughts?
Running
echo "hey" | slacktee.sh
worked
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.