GithubHelp home page GithubHelp logo

coursehero / slacktee Goto Github PK

View Code? Open in Web Editor NEW
829.0 829.0 95.0 278 KB

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

Shell 100.00%
bash slack

slacktee's People

Contributors

atomicturtle avatar bruno-amelco avatar ch-ckato avatar chasebolt avatar chikashi-kato avatar danielgavrilov avatar dannyben avatar dawsbot avatar dgengtek avatar funkjedi avatar gilesw avatar jovandeginste avatar rbotzer avatar samskiter avatar shanley2015 avatar siosphere avatar vipulgagrani avatar wayneworkman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

slacktee's Issues

streaming but without editing

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

Tag people/channels

Would it be possible to slack a message that uses e.g @channel or @<username> to notify people of things?

Allow send messages to user, not only to channel

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
 }

stream output

Would be super great to have slacktee stream output to Slack. It could update the comment as output comes in.

Breaking rich format when sending +4000 characters

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

`parseMode` causes invalid json error

parseMode=', "parse": "none"'

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.

Cannot override user/icon/channel

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.

Different output by same bot?

Hello,

I have a weird question. I have 2 vps and they print the output differently.

imagen

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?

Issues on Debian 8

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

slacktee should continue to output the input to STDOUT even if it fails to be executed

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.

Allow slacktee to do /commands

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

Error: here-document delimited by end-of-file (wanted `EOF')

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:

slacktee/slacktee.sh

Lines 406 to 415 in 86522a9

cat <<- EOF | sed 's/^[[:space:]]*//' > "$local_conf"
webhook_url="$input_webhook_url"
token="$input_token"
tmp_dir="$input_tmp_dir"
channel="$input_channel"
username="$input_username"
icon="$input_icon"
attachment="$input_attachment"
EOF
}

Post to thread

I needed some stuff to be posted into thread for my logging purposes on production, so I came up with the following:

  1. add a new function for parsing response:
function get_thread_ts() {
    local response=$1
    echo "$(echo "$response" | jq -r .message.ts)"
}
  1. in function send_message() add to json
    "thread_ts": "$thread_ts",
    (var $thread_ts can be empty, slack will ignore it)

  2. 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
  1. in main() add thread_ts for uploading files:
    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)"
  2. add reading $thread_ts with -r key in parse_args()

And now I can do stuff like this:

thread_ts=$(echo anything|slacktee -q)
echo something|slacktee -r $thread_ts

Bug with tail -f

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 !

Add negative color/prefix pattern condition

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

Using Webhook to run slacktee

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.

invalid json when sending non-json text

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?

deb/rpm/whatever package?

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.

#35
#37

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.

No way to add new line to string passed?

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?

Fails silently if curl is not installed

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 πŸ‘

Send without message

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

any kind of logs?

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

Backslack was not processed correctly

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

Color in ouput gives json error

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

Globbing

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

Messages are not dispatched from rsyslog

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

"not in channel" error

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

ReadMe could use a bit more clarification

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 :-(

slacktee.sh doesn't work with crontab because of $PATH issue...

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.

Unable to create slacktee as a service

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.

Slack files.upload deprecated

The files.upload API is being deprecated. slacktee makes usage of it here

upload_result="$(curl -F file=@"$filename" -F token="$token" $channels_param https://slack.com/api/files.upload 2> /dev/null)"

We want to inform you of two important dates related to upcoming changes to support for the files.upload web API method

image

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.

color doesn't stay

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?

Error happens when input is empty with -f option

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.

Copyright/Applying License

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

slacktee install as root

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?

Unable to close with CTRL+C, when running directly

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.