Giter Club home page Giter Club logo

slacker's Introduction

Slacker

Slacker is simple email-to-slack gateway. It support basic rules for routing messages to different slack channels from different bots.

Main purpose of slacker is to redirect messages from old-school systems which doesn't support messaging other than email. For example cron and monit (https://mmonit.com/monit/) support only emails as the only system for notifications.

Installation

Slacker can be easily installed via docker:

docker pull ontrif/slacker

Then run container with custom slacker config.yml:

docker run \
    -d --restart=always \
    --name=slacker \
    -v /path/to/config.yml:/etc/slacker/config.yml \
    -p localhost:8025:8025 \
    ontrif/slacker

Last command will start SMTP server on localhost:8025

Config

Slacker supports simple list of rules for configuring target slack channel, bot name and its avatar depending on email content.

There are two sections:

  • default: this is default options for sending message to slack.
  • rules: list of rules for matching email message against 'from', 'to' and/or 'subject'.

Each rule in list tested in order. First matched rule is used to update options values from 'default' section of config.

Example config.yml for redirecting email to two channels: #monit and #cron:

# default values for channel, bot name, avatar url, slack token and debug mode
default:
    channel: "#general"
    username: "slacker"
    icon_url: ""
    slack_token: "xoxb-00000000000-aaaaaaaaaaaaaaaaaaaaaaaa"
    debug: false


# list of rules
rules:
    - name: "Monit rule"
      from: "monit@.*"     # all emails from monit@localhost will match this rule

      options:
          username: "monit"
          channel: "#monit"
          icon_url: "https://bitbucket.org/tildeslash/monit/avatar/128"
          debug: false


    - name: "Cron rule"
      from: "root@localhost"
      subject: "Cron.*"    # cron email subject starts with "Cron..."

      options:
          username: "cron"
          channel: "#cron"
          icon_url: ""
          debug: true    # will output full email with all X-headers

slacker's People

Contributors

dependabot[bot] avatar edhull avatar lastb0isct avatar ont 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

Watchers

 avatar  avatar

slacker's Issues

Message content not making it through

Specs

Running image id 7dbf7678e365 (0.0.4)

Config

docker-compose.yml

ont_slacker:
    container_name: ont_slacker
    image: ontrif/slacker:0.0.4
    restart: unless-stopped
    ports:
      - 127.0.0.1:8025:8025
    volumes:
      - ./ont_slacker/config/config.yml:/etc/slacker/config.yml

config.yml

default:
    channel: '#unifi-gateway'
    username: 'ont_slacker: SMTP'
    icon_url: ''
    slack_token: xoxp-
    debug: true

Docker logs

ont_slacker    | {'from': 'UniFi Controller <>', 'to': '', 'subject': '[UniFi] Alert: UniFi Switch Disconnected (2)', 'body': [<email.message.Message object at 0x7fd2db5d3b00>, <email.message.Message object at 0x7fd2db5d3e48>]}
ont_slacker    | matched {'channel': '#unifi-gateway', 'username': 'ont_slacker: SMTP', 'icon_url': '', 'slack_token': 'xoxp-', 'debug': False}
ont_slacker    | sending to slack [<email.message.Message object at 0x7fd2db5d3b00>, <email.message.Message object at 0x7fd2db5d3e48>] {'channel': '#unifi-gateway', 'username': 'ont_slacker: SMTP', 'icon_url': '', 'slack_token': 'xoxp-', 'debug': False}

Slack result

image

missing_scope error

Getting this error when attempting to run the default config with a general rule to catch all of them to go to one channel -- seems it's getting stuck on an empty icon_url? Should I just remove the options I'm not going to use from the .yml?:

Traceback (most recent call last):
  File "/usr/src/app/src/aiosmtpd/aiosmtpd/smtp.py", line 315, in _handle_client
    await method(arg)
  File "/usr/src/app/src/aiosmtpd/aiosmtpd/smtp.py", line 688, in smtp_DATA
    status = await self._call_handler_hook('DATA')
  File "/usr/src/app/src/aiosmtpd/aiosmtpd/smtp.py", line 122, in _call_handler_hook
    status = await hook(self, self.session, self.envelope, *args)
  File "/usr/src/app/src/aiosmtpd/aiosmtpd/handlers.py", line 156, in handle_DATA
    self.handle_message(envelope)
  File "/usr/src/app/handler.py", line 28, in handle_message
    self.send_to_slack(self.extract_text(message), **options)
  File "/usr/src/app/handler.py", line 75, in send_to_slack
    icon_url=options['icon_url']
  File "/usr/local/lib/python3.6/site-packages/slack/chat.py", line 49, in post_message
    return slack.http_client.post('chat.postMessage', data)
  File "/usr/local/lib/python3.6/site-packages/slack/http_client.py", line 42, in post
    return _parse_response(response)
  File "/usr/local/lib/python3.6/site-packages/slack/http_client.py", line 49, in _parse_response
    _raise_error_if_not_ok(response)
  File "/usr/local/lib/python3.6/site-packages/slack/http_client.py", line 72, in _raise_error_if_not_ok
    raise SlackError(response['error'])
slack.exception.SlackError: missing_scope

This is my config.yml:

default:
    channel: '#mychannel'
    username: slacker
    icon_url: ''
    slack_token: xoxb
    debug: false
    format: "subject: %(subject)s; body: %(body)s"  ## default slack message format


rules:
    - name: "Catch them all"
      from: ".*"

      options:
          username: slacker
          channel: '#mychannel'
          icon_url: ''
          debug: false

Porting this over to webhooks instead of API due to my internal company policy -- guidance?

I have left everything pretty much the same, but if you can give some input on what I'm missing here? Essentially I've removed the rules processing and all of the other config.yml options other than url, which is the webhook url.

I'm able to get to the end of the handler.py but it doesn't seem to be calling the def, as it's not printing the "sending to slack" text. I know that the requests.post is correct, but not sure what I'm missing in the def. Any help is appreciated!

Thanks!

https://github.com/lastb0isct/slacker/blob/master/handler.py

How to use?

I've got the image up and running on docker, but do you have instructions on how to use it? What's the best program to install to take advantage of this smtp server? Thanks!

[HELP] can't make it work on docker-compose ..

Hi @ont

I think i have an issue in bind the directories... (below, docker-compose file)

version: '3.3'
services:
slacker:
container_name: slacker
volumes:
- ./config.yml:/etc/slacker/config.yml
ports:
- '8025:8025'
restart: unless-stopped
image: ontrif/slacker:latest

below: real syntax:

slacker

error appears in logs:

[+] Running 1/1
โœ” Container slacker Recreated 1.3s
Attaching to slacker
slacker | /etc/slacker/config.yml
slacker | Traceback (most recent call last):
slacker | File "/usr/local/bin/aiosmtpd", line 11, in
slacker | load_entry_point('aiosmtpd', 'console_scripts', 'aiosmtpd')()
slacker | File "/usr/src/app/src/aiosmtpd/aiosmtpd/main.py", line 107, in main
slacker | parser, args = parseargs(args=args)
slacker | File "/usr/src/app/src/aiosmtpd/aiosmtpd/main.py", line 86, in parseargs
slacker | args.handler = handler_class()
slacker | File "/usr/src/app/handler.py", line 19, in init
slacker | self.config = yaml.load(open(config))
slacker | IsADirectoryError: [Errno 21] Is a directory: '/etc/slacker/config.yml'
slacker exited with code 0

any clue?

Doesn't support ending emails with <cf>.<cf>

Attempted to send email via telnet as a test

telnet localhost:8025
Type: EHLO <mail server internet name>
Type: mail from: <[email protected]> and press Enter.
Type: rcpt to: <[email protected]> and press Enter.
Type: data and press Enter.
Type: Subject: <a subject here> and press Enter.
Type: This is a test message sent from telnet. and press Enter.
Type: . and press Enter

Server responded as expected up until attempting to confirm the contents of the email. It seemed to take <cr/lf>.<cr/lf> as part of the email body and never continued.

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.