Closed segatrsrv closed 1 year ago
Hi @segatrsrv !
Thanks for reaching out!
Hummm...I don't see anything wrong in the configuration itself (if I didn't miss something). I have a few questions:
1) Did this setup work before? 2) Did it just stop working with the newest image? 3) Did you try an alternative notification method for testing purposes? (e.g. plain email or NTFY just to test the notifications are working otherwise) 4) I haven't used the SMTP_to_telegram image, so not sure, but are there any error logs in that image? 5) Did you update SMTP_to_telegram recently as well?
Hope I can help, j
- Did this setup work before?
it worked, but I haven't updated your image for a long time (I can't specify the exact release, which worked without problems)
- Did it just stop working with the newest image?
this is the problem that when installing the first notification goes away and is successfully delivered to Telegram, and after that this error begins to appear
- Did you try an alternative notification method for testing purposes? (e.g. plain email or NTFY just to test the notifications are working otherwise)
I tried, but I couldn't send emails from Docker, so I switched to SMTP_to_Telegram. With other apps it works correctly and without failures
- I haven't used the SMTP_to_telegram image, so not sure, but are there any error logs in that image?
there is a log and it matches log.alert
time="2022-12-29T17:30:56Z" level=debug msg="Writing response to client: \n554 Error: Post \"https://api.telegram.org/bot***/sendMessage?disable_web_page_preview=true\": dial tcp: lookup api.telegram.org on 127.0.0.11:53: read udp 127.0.0.1:38988->127.0.0.11:53: i/o timeout\r\n"
time="2022-12-29T17:30:56Z" level=debug msg="Client sent: rset"
time="2022-12-29T17:30:56Z" level=debug msg="Writing response to client: \n250 2.1.0 OK\r\n"
time="2022-12-29T17:30:56Z" level=debug msg="Client sent: "
time="2022-12-29T17:30:56Z" level=warning msg="Client closed the connection: 172.23.0.1" error=EOF
time="2022-12-29T17:31:08Z" level=debug msg="[0.0.0.0:2525] Waiting for a new client. Next Client ID: 3520"
time="2022-12-29T17:31:08Z" level=info msg="Handle client [172.23.0.1], id: 3519"
time="2022-12-29T17:31:08Z" level=debug msg="Writing response to client: \n220 5de9edc94043 SMTP Guerrilla(unknown) #3519 (1) 2022-12-29T17:31:08Z\r\n"
time="2022-12-29T17:31:08Z" level=debug msg="Client sent: ehlo [127.0.1.1]"
time="2022-12-29T17:31:08Z" level=debug msg="Writing response to client: \n250-5de9edc94043 Hello\r\n250-SIZE 50000000\r\n250-PIPELINING\r\n250-ENHANCEDSTATUSCODES\r\n250 HELP\r\n"
time="2022-12-29T17:31:08Z" level=debug msg="Client sent: mail FROM:<use2r@gmail.com> size=7979"
time="2022-12-29T17:31:08Z" level=debug msg="Writing response to client: \n250 2.1.0 OK\r\n"
time="2022-12-29T17:31:08Z" level=debug msg="Client sent: rcpt TO:<user@gmail.com>"
time="2022-12-29T17:31:08Z" level=debug msg="Writing response to client: \n250 2.1.5 OK\r\n"
time="2022-12-29T17:31:08Z" level=debug msg="Client sent: data"
time="2022-12-29T17:31:08Z" level=debug msg="Writing response to client: \n354 Enter message, ending with '.' on a line by itself\r\n"
time="2022-12-29T17:31:18Z" level=error msg="Post \"https://api.telegram.org/bot***/sendMessage?disable_web_page_preview=true\": dial tcp: lookup api.telegram.org on 127.0.0.11:53: read udp 127.0.0.1:38284->127.0.0.11:53: i/o timeout"
- Did you update SMTP_to_telegram recently as well?
I installed the latest image (and it turns out he recently updated, before that he hadn't updated "Last pushed 20 days ago by kostyaesmukov" for a long time)
By searching for an error, I found the following similar problems, where everything boils down to incorrect report formation
@jokob-sk Thank you for your help, and I apologize for my English
Hi @segatrsrv !
Thanks for investigating!
According to the linked issues, this seems an upstream bug. What I think is happening is that the email which goes thru doesn't contain a character which causes this issue, the next one does. If I'm correct, there are I think 2 ways how to solve this:
1) I implement a text-only email option
2) You use a different middle-ware instead of smtp_to_telegram
I think apprise supports telegram as well, so if you could, give it a try: https://github.com/caronc/apprise/wiki/Notify_telegram
If others reading see value in implementing number 1, please do let me know and I'll consider it.
EDIT: Your English is great, don't apologize 👍 EDIT2:
- Did this setup work before?
it worked, but I haven't updated your image for a long time (I can't specify the exact release, which worked without problems)
This makes me wonder. I didn't touch the email sending code as far as I remember. Either way, can you try apprise if it is not too much work and if the issue persists, I'll look into debugging smtp_to_telegram
.
Thanks, j
Hi @jokob-sk
A few days ago, I completely reinstalled my Stack on VM (Virtual Machine), and messages started coming, and continue to arrive in Telegram without problems =)).
I have deleted only one line from my "docker-compose.yml", namely "ST_TELEGRAM_MESSAGE_TEMPLATE: "Subject: {subject}\\n\\n{body}""
.
The error in "smtp_to_telegram
" continues to be displayed periodically, but messages are successfully received every time with each alert
Errors in "smtp_to_telegram"
time="2023-01-02T17:42:36Z" level=debug msg="[0.0.0.0:2525] Waiting for a new client. Next Client ID: 78" time="2023-01-02T17:42:36Z" level=info msg="Handle client [172.23.0.1], id: 77" time="2023-01-02T17:42:36Z" level=debug msg="Writing response to client: \n220 64e9bc96689b SMTP Guerrilla(unknown) #77 (1) 2023-01-02T17:42:36Z\r\n" time="2023-01-02T17:42:36Z" level=debug msg="Client sent: ehlo [127.0.1.1]" time="2023-01-02T17:42:36Z" level=debug msg="Writing response to client: \n250-64e9bc96689b Hello\r\n250-SIZE 50000000\r\n250-PIPELINING\r\n250-ENHANCEDSTATUSCODES\r\n250 HELP\r\n" time="2023-01-02T17:42:36Z" level=debug msg="Client sent: mail FROM:use2r@gmail.com size=3607" time="2023-01-02T17:42:36Z" level=debug msg="Writing response to client: \n250 2.1.0 OK\r\n" time="2023-01-02T17:42:36Z" level=debug msg="Client sent: rcpt TO:user@gmail.com" time="2023-01-02T17:42:36Z" level=debug msg="Writing response to client: \n250 2.1.5 OK\r\n" time="2023-01-02T17:42:36Z" level=debug msg="Client sent: data" time="2023-01-02T17:42:36Z" level=debug msg="Writing response to client: \n354 Enter message, ending with '.' on a line by itself\r\n" time="2023-01-02T17:42:36Z" level=debug msg="Writing response to client: \n250 2.0.0 OK: queued as f527e4024949e2592f3fef1d20d138a1\r\n" time="2023-01-02T17:42:36Z" level=debug msg="Client sent: quit" time="2023-01-02T17:42:36Z" level=debug msg="Writing response to client: \n221 2.0.0 Bye\r\n"
The problem seems to lie in one of the two blocks (subject\body).
Regarding "Notify_telegram" I will try to install it the other day, I already had experience installing it, but I refused in favor of "smtp_to_telegram" as a more rational tool, because not all applications can interact with "Notify" (at least with which I work), but absolutely everyone can send messages via smtp. I'll write later how it turned out...
I attached a short message (which is not working now) and a full message (which works, but is not convenient to read and does not fit in the notification curtain) to understand the problem\situation.
Hey there!
Could you please elaborate on:
(which is not working now) and a full message (which works, but is not convenient to read and does not fit in the notification curtain)
Do you have screenshot of a badly formatted message? I'm not sure how I can help in this regard since you are using middle-ware.
You can use a different middleware as well, such as n8n which I use myself.
j
Hi, @jokob-sk.
I found the root of the problem, it turned out to be a Pi-Hole. Without (Pi-Hole) everything works with any restrictions on the "smtp_to_telegram" side, including "ST_TELEGRAM_MESSAGE_TEMPLATE" (if it will be useful to anyone). I haven't figured out exactly what the problem is yet (there is a suspicion of the network, or rather that it is not divided into internal and external, I plan to share this through Traefik). At the same time, if you put it in turn (Pi-alert\ smtp_to_telegram \ Pi-hole), then everything works, but only until the first reboot, and then writes the connection error again, while there are no locks or errors in the pi-hole logs.
But since I've already bothered you, I wanted to write a wish for future improvements to pi.alert: in the Report in Events, to be able to change the order of display of blocks, i.e. now "Name: \MAC: \IP: \Time: \Event: \More Info:" (at least this is how it is displayed for me), to a different display order (Name: \Event: \IP: \Time: \MAC: \More Info:). By the way, "More Info:" I always have an empty one (but it's not critical)
P.S.2. thank you for "n8n" it's really a worthwhile thing, but I didn't quite understand how to get data from pi.alert? what integration do you use to connect to pi.alert?
Hi @segatrsrv ,
Thanks for the nice words, really appreciate them :)
Glad to hear you narrowed the issue down further.
No need to apologize ;)
Regarding the request: I assume you mean in the sent emails? I'll consider it when doing work around that area of the app. Thanks for the suggestion!
Regarding n8n, you can set up PiAlert sending a webhook to n8n, n8n catches the webhook, then you have the full JSON data (see sample here) of the alert and you can re-structure it however you want into a new email (or any other notification supported by n8n) and forward it. Here are a few screenshots of a very simple sample setup:
See sample JSON if you want to see the JSON paths used in the email template below
Hi @jokob-sk it seems I have a similar problem just with e-mail, I don't use any other messaging. After error the container restarts.
Find attached the part of the log with the error maessages and a cleaned config file. But the error messages indicates it's the same or at least a very similar problem.
If you need further information, just ask...
And also from my side, thanks for the work.
Hi @WAdama !
Your SMTP configuration seems to be the issue:
[2023-01-06 23:01:01] Scan: Nmap for max 120s (2.0min) per device
Estimated max delay: 0s (0.0min)
Check if something to report
Changes detected, sending reports
Sending report by Email
Traceback (most recent call last):
File "/home/pi/pialert/back/pialert.py", line 3264, in <module>
sys.exit(main())
File "/home/pi/pialert/back/pialert.py", line 726, in main
send_notifications()
File "/home/pi/pialert/back/pialert.py", line 2389, in send_notifications
send_email (mail_text, mail_html)
File "/home/pi/pialert/back/pialert.py", line 2594, in send_email
smtp_connection = smtplib.SMTP (SMTP_SERVER, SMTP_PORT)
File "/usr/lib/python3.9/smtplib.py", line 253, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python3.9/smtplib.py", line 341, in connect
(code, msg) = self.getreply()
File "/usr/lib/python3.9/smtplib.py", line 398, in getreply
raise SMTPServerDisconnected("Connection unexpectedly closed")
smtplib.SMTPServerDisconnected: Connection unexpectedly closed
Nothing to do here.
mkdir: cannot create directory '/run/php': File exists
Starting nginx: nginx.
Can you try to adjust your SMTP settings or use a different SMTP provider? E.g. I can assist you with send in blue, which has the following config:
# Email
#---------------------------
REPORT_MAIL=True
SMTP_SERVER='smtp-relay.sendinblue.com'
SMTP_PORT=587
REPORT_TO='toemail@gmail.com'
REPORT_FROM='Pi.Alert <email@gmail.com>'
SMTP_SKIP_LOGIN=False
SMTP_USER='email@gmail.com'
SMTP_PASS='passw0rd'
SMTP_SKIP_TLS=False
Hope this helps, j
@jokob-sk I'm not quite sure, I can follow you. This is a configuration I use for several other services and it never caused a problem. So which part in your opinion is causing this?
But to be on the sure side, I will test another provider.
Regards Ingo
Problem solved in my case. It seems the mail component of Pi.Alert can't work with port 465 TLS for mail sending.
Thankfully Strato allows also for mail sending STARTTLS over port 587. Changing to this made the mailing work.
@WAdama thanks for the update!
Glad to hear it works now. I still think it was a configuration issue (maybe you needed to specify to skip TLS as it was on a different port?) not sure, but I'm using pretty standard email sending code here: https://github.com/jokob-sk/Pi.Alert/blob/main/back/pialert.py#L2397
Anyway, glad it's working for you now!
The difference between 465 and 587 is that 465 starts direct with SSL/TLS where 587 is on start plain text and then negotiates out if SSL/TLS is possible and changes then to SSL/TLS.
So 465 would be the better choice.
And if you look in your code line 2398 you try to open a STARTTLS connection. So I think this is causing the the error.
Hey @WAdama !
Thanks for the info!
And if you look in your code line 2398 you try to open a STARTTLS connection. So I think this is causing the the error.
If you enable the SMTP_SKIP_TLS
setting that part of the code is skipped so you can use your 465 port instead
Enable SMTP_SKIP_TLS
does not do the trick, the container crashes again.
I think in this case the problem is that 465 is TLS.
It should be documented that the mail option supports only STARTTLS but not pure TLS.
@WAdama Thansk for letting me know!
Hopefully this will fix it: https://github.com/jokob-sk/Pi.Alert/commit/121b5cdf32c71ba13653de9c170cb036521f189e
This is not yet in the production image, just in the dev image. Will be part of the next release
I'll wait for next release. It is working, so I have no hurry, if it's ok for you...
Should be in the latest production image. Closing for now, will re-open if issues persist.
Hi @jokob-sk
I just had time to test it and I'm afraid the problem still persists. This is the actual log content:
[2023-01-14 13:39:09] Scan Devices: arp-scan start Processing scan results Devices Detected.......: 16 arp-scan detected..: 14 Pi-hole detected...: +0 New Devices........: 0 Devices in this cycle..: 16 Down Alerts........: 0 New Down Alerts....: 0 New Connections....: 0 Disconnections.....: 2 IP Changes.........: 0 Updating DB Info Sessions Events (connect / discconnect) Creating new devices Updating Devices Info Voiding false (ghost) disconnections Pairing session events (connection / disconnection) Creating sessions snapshot Inserting scan results into Online_History Skipping repeated notifications sys.exit(main()) File "/home/pi/pialert/back/pialert.py", line 541, in main send_notifications() File "/home/pi/pialert/back/pialert.py", line 2182, in send_notifications send_email (mail_text, mail_html) File "/home/pi/pialert/back/pialert.py", line 2387, in send_email Check if something to report Changes detected, sending reports Sending report by Email smtp_connection = smtplib.SMTP (SMTP_SERVER, SMTP_PORT) File "/usr/lib/python3.9/smtplib.py", line 253, in __init__ (code, msg) = self.connect(host, port) File "/usr/lib/python3.9/smtplib.py", line 341, in connect (code, msg) = self.getreply() File "/usr/lib/python3.9/smtplib.py", line 398, in getreply raise SMTPServerDisconnected("Connection unexpectedly closed") smtplib.SMTPServerDisconnected: Connection unexpectedly closed Nothing to do here. mkdir: cannot create directory '/run/php': File exists Starting nginx: nginx.
Hummm, what SMTP service are you using so I can create a test account there and test it there with a 465 port?
That's a paid mail service over Strato.de. That's a service provider in Germany with several services like mail, website or servers. www.strato.de
But I think there's no test account creatable.
But just checked: You can test it with gmx.net. They also support strict TLS over port 465 and the behaviour is the same:
Check if something to report
Changes detected, sending reports
Sending report by Email
Traceback (most recent call last):
File "/home/pi/pialert/back/pialert.py", line 3139, in
File "/home/pi/pialert/back/pialert.py", line 541, in main
send_notifications()
File "/home/pi/pialert/back/pialert.py", line 2182, in send_notifications
send_email (mail_text, mail_html)
File "/home/pi/pialert/back/pialert.py", line 2387, in send_email
smtp_connection = smtplib.SMTP (SMTP_SERVER, SMTP_PORT)
File "/usr/lib/python3.9/smtplib.py", line 253, in init
(code, msg) = self.connect(host, port)
File "/usr/lib/python3.9/smtplib.py", line 341, in connect
(code, msg) = self.getreply()
File "/usr/lib/python3.9/smtplib.py", line 398, in getreply
raise SMTPServerDisconnected("Connection unexpectedly closed")
smtplib.SMTPServerDisconnected: Connection unexpectedly closed
Hey!
I've added more logging (and a force SSL option) in the latest release which I've released a couple of hours ago. The additional debug output might help you to find what's the issue in your setup.
If you happen to figure out how to get this working, please let me know and I can write a guide around it.
Thanks! j
This Gmail as SMTP guide might help you as well. Closing for now and will re-open if needed.
Hello, there was a problem with sending reports to Telegram. docker image I use the latest one. Maybe an error in the settings?
Thanks in advance for your help.
Paste last few lines from
pialert.log
Paste your
pialert.conf
(remove personal info)Paste your
docker-compose.yml
and.env
(remove personal info)docker-compose.yml