slacker icon indicating copy to clipboard operation
slacker copied to clipboard

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

Open walteroa2023 opened this issue 2 years ago • 12 comments

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?

walteroa2023 avatar Sep 01 '23 03:09 walteroa2023

Check that ./config.yml path exists during startup. It very likely that you mount inexistent path (or directory named config.yml) into docker container.

ont avatar Sep 01 '23 05:09 ont

Thxs for the quick response. awesome.

this is my directory structure before running the container:

[image: image.png]

There is only 1 directory created called config.yml, but as far as I understand, I should bind a directory locally to a container directory.

*is this case: * the directory /config.yml inside of slacker folder will bind to /etc/slacker/config.yml as stated on my docker-compose file:

[image: image.png]

Now, as I saw in the documentation, your app expects to have a config.yml file instead of a directory... So, what's wrong with it?

should I map without config.yml declaration? (As follow)

volumes: - ./:/etc/slacker

it means, in the host folder "slacker" bind the container folder "/etc/slacker"

please help me and tryout from your side...

El vie, 1 sept 2023 a las 2:48, ont @.***>) escribió:

Check that ./config.yml path exists during startup. It very likely that you mount inexistent path (or directory named config.yml) into docker container.

— Reply to this email directly, view it on GitHub https://github.com/ont/slacker/issues/14#issuecomment-1702199740, or unsubscribe https://github.com/notifications/unsubscribe-auth/BB7TLMRIBGUNTO6IW6LMH53XYFZJVANCNFSM6AAAAAA4G6BWKM . You are receiving this because you authored the thread.Message ID: @.***>

--

Walter Altimora@.***

walteroa2023 avatar Sep 01 '23 12:09 walteroa2023

Finally, i did it work as follows: (and of course, config.yml has to be copied to directory /config in host to make it works) - suggestion: update github and include a docker-compose.yml for avoid further questions -

[image: image.png]

but, when I use my test mail sent from D'Link NAS box with those settings, I've got tons of SSL errors... see attached log...

[image: image.png]

even if i didn catchup the rules, the smtp process seems to be a mess...

What are your recommendations for an email client "clean and without any SSL request", to verify at least messages are coming to the server on port 8025? (i would like to test with proven email client instead of dlink box´s email)

El vie, 1 sept 2023 a las 9:43, Walter Altimora @.***>) escribió:

Thxs for the quick response. awesome.

this is my directory structure before running the container:

[image: image.png]

There is only 1 directory created called config.yml, but as far as I understand, I should bind a directory locally to a container directory.

*is this case: * the directory /config.yml inside of slacker folder will bind to /etc/slacker/config.yml as stated on my docker-compose file:

[image: image.png]

Now, as I saw in the documentation, your app expects to have a config.yml file instead of a directory... So, what's wrong with it?

should I map without config.yml declaration? (As follow)

volumes: - ./:/etc/slacker

it means, in the host folder "slacker" bind the container folder "/etc/slacker"

please help me and tryout from your side...

El vie, 1 sept 2023 a las 2:48, ont @.***>) escribió:

Check that ./config.yml path exists during startup. It very likely that you mount inexistent path (or directory named config.yml) into docker container.

— Reply to this email directly, view it on GitHub https://github.com/ont/slacker/issues/14#issuecomment-1702199740, or unsubscribe https://github.com/notifications/unsubscribe-auth/BB7TLMRIBGUNTO6IW6LMH53XYFZJVANCNFSM6AAAAAA4G6BWKM . You are receiving this because you authored the thread.Message ID: @.***>

--

Walter Altimora@.***

--

Walter Altimora@.***

/usr/src/app/handler.py:19: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details. self.config = yaml.load(open(config)) ERROR:mail.log:SMTP session exception Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 595, in urlopen chunked=chunked) File "/usr/local/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 352, in _make_request self._validate_conn(conn) File "/usr/local/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 831, in validate_conn conn.connect() File "/usr/local/lib/python3.6/site-packages/requests/packages/urllib3/connection.py", line 289, in connect ssl_version=resolved_ssl_version) File "/usr/local/lib/python3.6/site-packages/requests/packages/urllib3/util/ssl.py", line 308, in ssl_wrap_socket return context.wrap_socket(sock, server_hostname=server_hostname) File "/usr/local/lib/python3.6/ssl.py", line 407, in wrap_socket _context=self, _session=session) File "/usr/local/lib/python3.6/ssl.py", line 814, in init self.do_handshake() File "/usr/local/lib/python3.6/ssl.py", line 1068, in do_handshake self._sslobj.do_handshake() File "/usr/local/lib/python3.6/ssl.py", line 689, in do_handshake self._sslobj.do_handshake() ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:841) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 423, in send timeout=timeout File "/usr/local/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 621, in urlopen raise SSLError(e) requests.packages.urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:841) During handling of the above exception, another exception occurred: 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 41, in post response = requests.post(url, data=data, verify=True) File "/usr/local/lib/python3.6/site-packages/requests/api.py", line 110, in post return request('post', url, data=data, json=json, **kwargs) File "/usr/local/lib/python3.6/site-packages/requests/api.py", line 56, in request return session.request(method=method, url=url, **kwargs) File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 475, in request resp = self.send(prep, **send_kwargs) File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 596, in send r = adapter.send(request, **kwargs) File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 497, in send raise SSLError(e, request=request) requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:841)

walteroa2023 avatar Sep 01 '23 14:09 walteroa2023

Please update docker image with docker pull ontrif/slacker then do tests again.

You always can connect with netcat, nc, ncat or similar tool to the 8025 port and do simple commands. Connect with:

ncat --crlf localhost 8025

Then enter this commands (server will respond on each command with 250 OK or similar:

HELO test.com
mail from: [email protected]
rcpt to: [email protected]
data
This is test email.
.

Note that pressing <enter> and . and then <enter> is important. Such sequence will indicate end of data.

Full log of communication with server will be look like:

220 51d7d120dea8 Python SMTP 1.4.4.post2
HELO test.com
250 51d7d120dea8
mail from: [email protected]
250 OK
rcpt to: [email protected]
250 OK
data
354 End data with <CR><LF>.<CR><LF>
This is test email.
.

ont avatar Sep 01 '23 15:09 ont

done. all looks pretty good from netcat:

[image: image.png]

but..... *no logs *from your app, even if debug enabled, and of course, no message to slack has been sent...

[image: image.png] [image: image.png]

and last but not least:, env info from portainer: [image: image.png]

Any suggestions? (attached my config.yml file to take a look)

Again, your help is so much appreciated! B.R.

El vie, 1 sept 2023 a las 12:16, ont @.***>) escribió:

Please update image with docker pull ontrif/slacker then do tests again.

You always can connect with netcat, nc, ncat or similar tool to the 8025 port and do simple commands. Connect with:

ncat --crlf localhost 8025

Then enter this commands (server will respond on each command with 250 OK or similar:

HELO test.com mail from: @.*** rcpt to: @.*** data This is test email. .

Note that pressing and . and then is important. Such sequence will indicate end of data.

Full log of communication with server will be look like:

220 51d7d120dea8 Python SMTP 1.4.4.post2 HELO test.com 250 51d7d120dea8 mail from: @.*** 250 OK rcpt to: @.*** 250 OK data 354 End data with <CR><LF>.<CR><LF> This is test email. .

— Reply to this email directly, view it on GitHub https://github.com/ont/slacker/issues/14#issuecomment-1702917450, or unsubscribe https://github.com/notifications/unsubscribe-auth/BB7TLMUDULWKGRTR2MNS26TXYH36FANCNFSM6AAAAAA4G6BWKM . You are receiving this because you authored the thread.Message ID: @.***>

--

Walter Altimora@.***

walteroa2023 avatar Sep 02 '23 09:09 walteroa2023

@walteroa2023 I can't see any logs from you, only [image: image.png] message. Do you send emails to github bot instead of replying in thread on site (https://github.com/ont/slacker/issues/14)?

ont avatar Sep 05 '23 18:09 ont

with this binding in compose:

./config:/app

from netcat commands: srv1:~$ nc localhost 8025 << EOF

HELO mail.wlabs.ar MAIL FROM: [email protected] RCPT TO: [email protected] DATA Test alarm from NAS. . QUIT EOF 220 0ef7cec9b392 Python SMTP 1.4.4.post2 250 0ef7cec9b392 250 OK 250 OK 354 End data with <CR><LF>.<CR><LF>

from console log: docker compose up --force-recreate && docker compose logs -f

[+] Running 1/1 ✔ Container slacker Recreated 12.5s Attaching to slacker slacker | Traceback (most recent call last): slacker | File "/usr/local/bin/aiosmtpd", line 8, in slacker | sys.exit(main()) slacker | ^^^^^^ slacker | File "/usr/local/lib/python3.11/site-packages/aiosmtpd/main.py", line 218, in main slacker | parser, args = parseargs(args=args) slacker | ^^^^^^^^^^^^^^^^^^^^ slacker | File "/usr/local/lib/python3.11/site-packages/aiosmtpd/main.py", line 175, in parseargs slacker | module = import_module(path) slacker | ^^^^^^^^^^^^^^^^^^^ slacker | File "/usr/local/lib/python3.11/importlib/init.py", line 126, in import_module slacker | return _bootstrap._gcd_import(name[level:], package, level) slacker | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ slacker | File "", line 1204, in _gcd_import slacker | File "", line 1176, in _find_and_load slacker | File "", line 1140, in _find_and_load_unlocked slacker | ModuleNotFoundError: No module named 'handler' slacker exited with code 0

walteroa2023 avatar Sep 05 '23 19:09 walteroa2023

If I change the bind in docker-compose to:

./config:/etc/slacker

no errors at all, but , no logs, no debug info neither any slack message... (of course, due to security reasons, slack API key is masked with xxxxx)

config.yml:

default:
    channel: '#srv1-alerts'
    username: Notification Bot
    icon_url: ''
    slack_token: https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    debug: true #false
    format: "subject: %(subject)s; body: %(body)s"  ## default slack message format
rules:
    - name: NAS rule
      from: nas@.*

      options:
          username: Notification Bot
          channel: '#srv1-alerts'
          icon_url: 'https://github.com/walkxcode/dashboard-icons/blob/main/png/d-link.png'
          debug: true #false

walteroa2023 avatar Sep 05 '23 19:09 walteroa2023

@walteroa2023 first of all test that you image is latest:

$ docker images --digests | grep ontrif/slacker
ontrif/slacker                             latest                sha256:c50ec905cf0591cc604e8afa0b849973b27d01272302fec616b0eecddb6d1e15   4174f1dd8735   2 weeks ago    82.2MB

Digest of image must be sha256:c50ec905cf0591cc604e8afa0b849973b27d01272302fec616b0eecddb6d1e15.

Then test it with this command:

docker run -ti --rm -p 8025:8025 -v /tmp/config.yml:/etc/slacker/config.yml ontrif/slacker

Content of /tmp/config.yml in my test was:

default:
    channel: '#test_'
    username: slacker
    icon_url: ''
    slack_token: xoxb-<token>
    debug: false
    format: "subject: %(subject)s; body: %(body)s"


rules:
    - name: Monit rule
      from: monit@.*

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


    - name: Cron rule
      from: root@localhost
      subject: Cron.*

      options:
          username: cron
          channel: '#cron'
          icon_url: ''
          debug: true  ## will output full email with all headers
          format: "email body is: %(body)s"

After sending your commands to port 8025. I was able to see response from my service:

$ ncat --crlf localhost 8025

220 c04a74cb9844 Python SMTP 1.4.4.post2
HELO mail.wlabs.ar
250 c04a74cb9844
MAIL FROM: [email protected]
250 OK
RCPT TO: [email protected]
250 OK
DATA
354 End data with <CR><LF>.<CR><LF>
Test alarm from NAS.
.
250 OK

Response from my service in another console:

{'from': None, 'to': None, 'subject': None, 'body': 'Test alarm from NAS.\r\n'}
matched {'channel': '#test_', 'username': 'slacker', 'icon_url': '', 'slack_token': 'xoxb-....', 'debug': False, 'format': 'subject: %(subject)s; body: %(body)s'}
sending to slack subject: None; body: Test alarm from NAS.
 {'channel': '#test_', 'username': 'slacker', 'icon_url': '', 'slack_token': 'xoxb-....', 'debug': False, 'format': 'subject: %(subject)s; body: %(body)s'}

And message was successfully sent to slack. In my case all works.

  • check that API key from slack is correct and bot has access to channel #srv1-alerts
  • send any message to slack via this api key with curl
  • again, check that you use latest updated version of ontrif/slacker image from dockerhub

ont avatar Sep 16 '23 18:09 ont

Still not working... checked, latest image and digest is correct.

tested with this command: docker run -ti --rm -p 8025:8025 -v ./config/config.yml:/etc/slacker/config.yml ontrif/slacker

after running the ncat (in my case in the alpine environment: nc localhost 8025 << EOF HELO mail.wlabs.ar MAIL FROM: [email protected] RCPT TO: [email protected] DATA Test alarm from NAS . QUIT EOF

i can see this answer:

220 4d645d674471 Python SMTP 1.4.4.post2 250 4d645d674471 250 OK 250 OK 354 End data with <CR><LF>.<CR><LF>

So, first questions are:

  1. the config.yml is taken from /etc/slacker? or is taken from /app? (where the sample file is)
  2. any way to send thru netcat to any public smtp to check email has been sent?
  3. is there any way debug if the config.yml has been taken to parse the incoming email?
  4. any way to verify if after parsing the config.yml something has been sent to slack webhook?

(sorry for my questions, but i guess we are much closer to the end...)

walteroa2023 avatar Sep 20 '23 23:09 walteroa2023

Hi @ont still not working. Did u have the chance to review my questions?

  1. the config.yml is taken from /etc/slacker? or is taken from /app? (where the sample file is)
  2. any way to send thru netcat to any public smtp to check email has been sent?
  3. is there any way debug if the config.yml has been taken to parse the incoming email?
  4. any way to verify if after parsing the config.yml something has been sent to slack webhook?

B.R. Walter

walteroa2023 avatar Sep 29 '23 01:09 walteroa2023

@walteroa2023 sorry for late response.

  1. config is taken from /etc/slacker/config.yml
  2. i don't know any public email servers. Probably any one without authentication will accept your requests without problems.
  3. you can easily add any debug output in https://github.com/ont/slacker/blob/master/handler.py manually. As you can see there is already some debug output for matched config options and there is exists config option debug for more verbose output (https://github.com/ont/slacker/blob/master/handler.py#L30)
  4. see debug option in config

ont avatar Oct 17 '23 21:10 ont