Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
walteroa2023 opened this issue Sep 1, 2023 · 12 comments
Open

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

walteroa2023 opened this issue Sep 1, 2023 · 12 comments

Comments

@walteroa2023
Copy link

walteroa2023 commented Sep 1, 2023

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?

@ont
Copy link
Owner

ont commented Sep 1, 2023

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

@walteroa2023
Copy link
Author

walteroa2023 commented Sep 1, 2023 via email

@walteroa2023
Copy link
Author

walteroa2023 commented Sep 1, 2023 via email

@ont
Copy link
Owner

ont commented Sep 1, 2023

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: sender@test.com
rcpt to: test@gmail.com
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: sender@test.com
250 OK
rcpt to: test@gmail.com
250 OK
data
354 End data with <CR><LF>.<CR><LF>
This is test email.
.

@walteroa2023
Copy link
Author

walteroa2023 commented Sep 2, 2023 via email

@ont
Copy link
Owner

ont commented Sep 5, 2023

@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 (#14)?

@walteroa2023
Copy link
Author

walteroa2023 commented Sep 5, 2023

with this binding in compose:

./config:/app

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

HELO mail.wlabs.ar
MAIL FROM: nas@wlabs.ar
RCPT TO: notification@wlabs.ar
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 .

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
Copy link
Author

walteroa2023 commented Sep 5, 2023

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

@ont
Copy link
Owner

ont commented Sep 16, 2023

@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: nas@wlabs.ar
250 OK
RCPT TO: notification@wlabs.ar
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

@walteroa2023
Copy link
Author

walteroa2023 commented Sep 20, 2023

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: nas@wlabs.ar
RCPT TO: notification@wlabs.ar
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 .

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
Copy link
Author

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

@ont
Copy link
Owner

ont commented Oct 17, 2023

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants