Unable to sent mail with postfix and s-nail

An open discussion forum for obtaining help with Nagios Core. Nagios Core users of all experience levels are welcome here. Subforum have been created for the discussion of Nagios Core and Nagios Plugin development.

NOTE: The SourceForge.net mailing lists have been deprecated in favor of this forum in order to expedite support and provide additional features not available on the old mailing list.

Unable to sent mail with postfix and s-nail

Postby nymon » Fri Sep 28, 2018 10:50 am

Hello dear community,

I'm struggling since 1 week now because of a right permission that I don't find the location. Let me please clarify myself :

Everytime I want to send a notification for a host I got this error from nagios log :

Code: Select all
[1538148656] wproc:   stderr line 01: Can't canonicalize "./Maildir"
[1538148656] wproc:   stderr line 02: ./Maildir/sent: No such file or directory
[1538148656] wproc:   stderr line 03: Failed to save message in "./Maildir/sent" - message not sent
[1538148656] wproc:   stdout line 01: "./dead.letter" 20/397


My Postfix is working with my current user, I can send email but every time nagios wants to send an email, it doesn't work. I'm pretty sure it's a question of permissions because I did create Maildir on the current user.

Could someone explain me or help me with ?

It will be super grateful !

Have a good end of week.

Nymon
nymon
 
Posts: 4
Joined: Fri Sep 28, 2018 10:42 am

Re: Unable to sent mail with postfix and s-nail

Postby ssax » Fri Sep 28, 2018 3:52 pm

Try running these commands to see if it resolves the issue:

Code: Select all
mkdir -p /home/nagios/Maildir/{cur,new,tmp}
chown -R nagios.nagios /home/nagios/Maildir
echo 'init' | mail -s 'init' nagios
Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
ssax
Dreams In Code
 
Posts: 3205
Joined: Wed Feb 11, 2015 12:54 pm

Re: Unable to sent mail with postfix and s-nail

Postby nymon » Mon Oct 01, 2018 2:43 am

Hello ssax,

Thank you for your reply.

I did the following commands and it works fine. The problem is when nagios wants to send notification by himself. Here is the /usr/local/nagios/var/nagios.log :

Code: Select all
[1538379482] EXTERNAL COMMAND: SEND_CUSTOM_SVC_NOTIFICATION;kx-poe;Port Ethernet 1/1/48 Link Status;0;Nagios Admin;test
[1538379482] SERVICE NOTIFICATION: nagiosadmin;kx-poe;Port Ethernet 1/1/48 Link Status;CUSTOM (OK);notify-service-by-email;SNMP OK - 1;Nagios Admin;test
[1538379482] wproc: NOTIFY job 0 from worker Core Worker 16102 is a non-check helper but exited with return code 1
[1538379482] wproc:   host=kx-poe; service=Port Ethernet 1/1/48 Link Status; contact=nagiosadmin
[1538379482] wproc:   early_timeout=0; exited_ok=1; wait_status=256; error_code=0;
[1538379482] wproc:   stderr line 01: Can't canonicalize "./Maildir"
[1538379482] wproc:   stderr line 02: ./Maildir/sent: No such file or directory
[1538379482] wproc:   stderr line 03: Failed to save message in "./Maildir/sent" - message not sent
[1538379482] wproc:   stdout line 01: "./dead.letter" 20/396


Did I miss something ? I have the impression that Nagios is using root instead of nagios to send email. Can we change that ?

Thank you in advance,

Nymon
nymon
 
Posts: 4
Joined: Fri Sep 28, 2018 10:42 am

Re: Unable to sent mail with postfix and s-nail

Postby ssax » Tue Oct 02, 2018 2:28 pm

Please attach your /etc/postfix/main.cf file so that I can review your settings.
Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
ssax
Dreams In Code
 
Posts: 3205
Joined: Wed Feb 11, 2015 12:54 pm

Re: Unable to sent mail with postfix and s-nail

Postby nymon » Fri Oct 05, 2018 8:23 am

Hello ssax,

Please find my /etc/postifx/main.cf configuration :

Code: Select all
# See /usr/share/postfix/main.cf.dist for a commented, more complete version
# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# See http://www.postfix.org/COMPATIBILITY_README.html -- default to 2 on
# fresh installs.
compatibility_level = 2

# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = ubuntu-test
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = ubuntu-test, ubuntu-test, localhost.localdomain, localhost
relayhost = [smtp.office365.com]:587
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = ipv4
home_mailbox = Maildir/
virtual_alias_maps = hash:/etc/postfix/virtual
myorigin = /etc/mailname

# Configuration SMTP
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd

smtp_use_tls = yes
smtp_tls_security_level = may
smtp_tls_CAfile = /etc/postfix/cacert.pem
sender_canonical_maps = regexp:/etc/postfix/sender_canonical


Thanks in advance,
nymon
 
Posts: 4
Joined: Fri Sep 28, 2018 10:42 am

Re: Unable to sent mail with postfix and s-nail

Postby ssax » Fri Oct 05, 2018 2:45 pm

What is the output of these commands:

Code: Select all
ls -la /home/nagios
ls -la /home/nagios/Maildir
ls -la /home/nagios/Maildir/*
Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
ssax
Dreams In Code
 
Posts: 3205
Joined: Wed Feb 11, 2015 12:54 pm

Re: Unable to sent mail with postfix and s-nail

Postby nymon » Mon Oct 08, 2018 3:27 am

Here is what you asked :

Code: Select all
nagios@snmp-server:~$ ls -la /home/nagios
total 44
drwxr-xr-x 6 nagios nagios 4096 Sep 28 15:43 .
drwxr-xr-x 5 root   root   4096 Sep 28 15:10 ..
-rw------- 1 nagios nagios 4595 Oct  5 17:49 .bash_history
-rw-r--r-- 1 nagios nagios  220 Sep 28 15:10 .bash_logout
-rw-r--r-- 1 nagios nagios 3771 Sep 28 15:10 .bashrc
drwx------ 2 nagios nagios 4096 Sep 28 15:17 .cache
drwx------ 3 nagios nagios 4096 Sep 28 15:17 .gnupg
drwxrwxr-x 3 nagios nagios 4096 Sep 28 15:25 .local
drwxrwxr-x 5 nagios nagios 4096 Sep 28 16:31 Maildir
-rw-r--r-- 1 nagios nagios  807 Sep 28 15:10 .profile
-rw-r--r-- 1 nagios nagios    0 Sep 28 15:35 .sudo_as_admin_successful


Code: Select all
nagios@snmp-server:~$ ls -la /home/nagios/Maildir
total 24
drwxrwxr-x 5 nagios nagios 4096 Sep 28 16:31 .
drwxr-xr-x 6 nagios nagios 4096 Sep 28 15:43 ..
drwxrwxr-x 2 nagios nagios 4096 Sep 28 15:43 cur
drwxrwxr-x 2 nagios nagios 4096 Sep 28 15:43 new
-rw-rw-r-- 1 nagios nagios  472 Oct  1 09:36 sent
drwxrwxr-x 2 nagios nagios 4096 Sep 28 15:43 tmp


Code: Select all
nagios@snmp-server:~$ ls -la /home/nagios/Maildir/*
-rw-rw-r-- 1 nagios nagios  472 Oct  1 09:36 /home/nagios/Maildir/sent

/home/nagios/Maildir/cur:
total 8
drwxrwxr-x 2 nagios nagios 4096 Sep 28 15:43 .
drwxrwxr-x 5 nagios nagios 4096 Sep 28 16:31 ..

/home/nagios/Maildir/new:
total 8
drwxrwxr-x 2 nagios nagios 4096 Sep 28 15:43 .
drwxrwxr-x 5 nagios nagios 4096 Sep 28 16:31 ..

/home/nagios/Maildir/tmp:
total 8
drwxrwxr-x 2 nagios nagios 4096 Sep 28 15:43 .
drwxrwxr-x 5 nagios nagios 4096 Sep 28 16:31 ..


Regards ,
nymon
 
Posts: 4
Joined: Fri Sep 28, 2018 10:42 am

Re: Unable to sent mail with postfix and s-nail

Postby tgriep » Mon Oct 08, 2018 3:58 pm

What OS and release version are you running Nagios and Postfix on?

What errors do you see in the /var/log/maillog file when the system tries to send the emails?

You may have to setup a canonical mapping for the Nagios user account so postfix can generate an email as the nagios user.
See these links for more details.
http://www.postfix.org/ADDRESS_REWRITING_README.html
http://www.postfix.org/canonical.5.html
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
tgriep
Madmin
 
Posts: 7031
Joined: Thu Oct 30, 2014 9:02 am


Return to Nagios Core

Who is online

Users browsing this forum: No registered users and 14 guests