set up email alerts using mailx
set up email alerts using mailx
Im trying to set up email notifications using mailx on Centos 7.5. However, test mail failed to send due to AUTH LOGIN error as shown below. Please help!
[nagios@nagioscore objects]$ mailx -v -s "test email" john.smith@company.com
.
EOT
Null message body; hope that's ok
Password:
Resolving host mailrelay.int.company.com . . . done.
Connecting to 10.13.158.21:smtp . . . connected.
220 fihe3nok0734.emar.snn-net.net ESMTP Sat, 15 Dec 2018 00:05:38 GMT
>>> EHLO nagioscore
250-fihe3nok0734.emea.nsn-net.net Hello [10.3.17.130], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE 36700160
250-DSN
250-ETRN
250-AUTH GSSAPI
250-STARTTLS
250-DELIVERBY
250 HELP
>>> AUTH LOGIN
504 5.3.3 AUTH mechanism LOGIN not available
smtp-server: 504 5.3.3 AUTH mechanism LOGIN not available
"/home/nagios/dead.letter" 11/337
. . . message not sent.
[nagios@nagioscore objects]$
[nagios@nagioscore objects]$ mailx -v -s "test email" john.smith@company.com
.
EOT
Null message body; hope that's ok
Password:
Resolving host mailrelay.int.company.com . . . done.
Connecting to 10.13.158.21:smtp . . . connected.
220 fihe3nok0734.emar.snn-net.net ESMTP Sat, 15 Dec 2018 00:05:38 GMT
>>> EHLO nagioscore
250-fihe3nok0734.emea.nsn-net.net Hello [10.3.17.130], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE 36700160
250-DSN
250-ETRN
250-AUTH GSSAPI
250-STARTTLS
250-DELIVERBY
250 HELP
>>> AUTH LOGIN
504 5.3.3 AUTH mechanism LOGIN not available
smtp-server: 504 5.3.3 AUTH mechanism LOGIN not available
"/home/nagios/dead.letter" 11/337
. . . message not sent.
[nagios@nagioscore objects]$
Re: set up email alerts using mailx
Hello nib01,
Does your smtp server require authentication? SSL, TLS? Are you connecting via directives in a /etc/postfix/main.cf file? We would need more information to diagnose your issue. Please attach the output of:
Immediately after attempting to send the message.
Thank you!
Does your smtp server require authentication? SSL, TLS? Are you connecting via directives in a /etc/postfix/main.cf file? We would need more information to diagnose your issue. Please attach the output of:
Code: Select all
tail -100 /var/log/maillog
Thank you!
Re: set up email alerts using mailx
Initially postfix was used to send and receive but couldn't make it to work so I tried to using mailx instead.
We are not using any type of SMTP authentication. Internal smtp mailrelay used is below:
SMTP Hostname: mailrelay.int.company.com
Port: 25
Here's ~/.mailrc config file:
set -S smtp=mailrelay.int.nokia.com
set -S from=alerts.gainspeed@nokia.com
~
nagios@nagioscore ~]$ mailx -v -s "test email 6" ricson.liberato@nokia.com
.
EOT
Null message body; hope that's ok
Password:
Resolving host mailrelay.int.nokia.com . . . done.
Connecting to 10.130.128.21:smtp . . . connected.
220 fihe3nok0734.emea.nsn-net.net ESMTP Mon, 17 Dec 2018 18:48:03 GMT
>>> EHLO nagioscore
250-fihe3nok0734.emea.nsn-net.net Hello [10.3.17.130], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE 36700160
250-DSN
250-ETRN
250-AUTH GSSAPI
250-STARTTLS
250-DELIVERBY
250 HELP
>>> AUTH LOGIN
504 5.3.3 AUTH mechanism LOGIN not available
smtp-server: 504 5.3.3 AUTH mechanism LOGIN not available
"/home/nagios/dead.letter" 11/337
. . . message not sent.
No output for /var/log/maillog
[nagios@nagioscore objects]$ tail -100 /var/log/maillog
[nagios@nagioscore objects]$
We are not using any type of SMTP authentication. Internal smtp mailrelay used is below:
SMTP Hostname: mailrelay.int.company.com
Port: 25
Here's ~/.mailrc config file:
set -S smtp=mailrelay.int.nokia.com
set -S from=alerts.gainspeed@nokia.com
~
nagios@nagioscore ~]$ mailx -v -s "test email 6" ricson.liberato@nokia.com
.
EOT
Null message body; hope that's ok
Password:
Resolving host mailrelay.int.nokia.com . . . done.
Connecting to 10.130.128.21:smtp . . . connected.
220 fihe3nok0734.emea.nsn-net.net ESMTP Mon, 17 Dec 2018 18:48:03 GMT
>>> EHLO nagioscore
250-fihe3nok0734.emea.nsn-net.net Hello [10.3.17.130], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE 36700160
250-DSN
250-ETRN
250-AUTH GSSAPI
250-STARTTLS
250-DELIVERBY
250 HELP
>>> AUTH LOGIN
504 5.3.3 AUTH mechanism LOGIN not available
smtp-server: 504 5.3.3 AUTH mechanism LOGIN not available
"/home/nagios/dead.letter" 11/337
. . . message not sent.
No output for /var/log/maillog
[nagios@nagioscore objects]$ tail -100 /var/log/maillog
[nagios@nagioscore objects]$
Re: set up email alerts using mailx
Hello nib01,
This would appear to be a misconfigured sendmail.cf file, or your email server requires authentication, or your trying to send an email to an account outside of your domain. As this is clearly a sendmail issue rather than a nagios issue, you're more likely to find a solution on a general linux board than here on the Nagios Support Forum.
Thank you!
This would appear to be a misconfigured sendmail.cf file, or your email server requires authentication, or your trying to send an email to an account outside of your domain. As this is clearly a sendmail issue rather than a nagios issue, you're more likely to find a solution on a general linux board than here on the Nagios Support Forum.
Thank you!
Re: set up email alerts using mailx
It finally worked after modifying the /etc/mail.rc config file (I've removed previously added config file in this file). The test email using mailx it sent successfully to my corporate email.
However, email notification still didn't work after doing some testing by shutting down the target machine.
Below is command.cfg config file on my nagioscore:
################################################################################
#
# SAMPLE NOTIFICATION COMMANDS
#
# These are some example notification commands. They may or may not work on
# your system without modification. As an example, some systems will require
# you to use "/usr/bin/mailx" instead of "/usr/bin/mail" in the commands below.
#
################################################################################
define command {
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios Monitor Core Alert*****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mailx -v -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}
define command {
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios Monitor Core Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/bin/mailx -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}
However, email notification still didn't work after doing some testing by shutting down the target machine.
Below is command.cfg config file on my nagioscore:
################################################################################
#
# SAMPLE NOTIFICATION COMMANDS
#
# These are some example notification commands. They may or may not work on
# your system without modification. As an example, some systems will require
# you to use "/usr/bin/mailx" instead of "/usr/bin/mail" in the commands below.
#
################################################################################
define command {
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios Monitor Core Alert*****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mailx -v -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}
define command {
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios Monitor Core Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/bin/mailx -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}
-
- Support Tech
- Posts: 3457
- Joined: Mon May 15, 2017 5:00 pm
Re: set up email alerts using mailx
@nib01, Please force a few checks into a critical state and then send in the /usr/local/nagios/var/nagios.log file. I would like to see whether nagios is attempting to send a notification. This problem could be related to a general notification settings misconfiguration.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Re: set up email alerts using mailx
The below link is facing the same issue and he removed all the 'n" on both host /service command.
So, I've removed all the extra "\n" within "command.cfg config file", but same results. Please see attached file about the nagios error log file .
From this:
define command {
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios Monitor Core Alert*****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mailx -v -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}
define command {
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios Monitor Core Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/bin/mailx -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}
To this:
define command {
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios Monitor Core Alert*****\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mailx -v -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}
define command {
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios Monitor Core Alert *****\nNotification Type: $NOTIFICATIONTYPE$\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\nDate/Time: $LONGDATETIME$\nAdditional Info:\n$SERVICEOUTPUT$\n" | /usr/bin/mailx -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}
https://support.nagios.com/forum/viewto ... =7&t=39208
So, I've removed all the extra "\n" within "command.cfg config file", but same results. Please see attached file about the nagios error log file .
From this:
define command {
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios Monitor Core Alert*****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mailx -v -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}
define command {
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios Monitor Core Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/bin/mailx -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}
To this:
define command {
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios Monitor Core Alert*****\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mailx -v -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}
define command {
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios Monitor Core Alert *****\nNotification Type: $NOTIFICATIONTYPE$\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\nDate/Time: $LONGDATETIME$\nAdditional Info:\n$SERVICEOUTPUT$\n" | /usr/bin/mailx -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}
https://support.nagios.com/forum/viewto ... =7&t=39208
- Attachments
-
- nagios.log
- (1.16 MiB) Downloaded 350 times
Re: set up email alerts using mailx
Everytime the command runs, it generates this error
Except for the notify-host-by-email command, you should remove the -v (verbose option) from the command.
Make sure there is not an error in the /etc/mail.rc config file that is causing the missing " message.
So there may be a missing " somewhere but the commands do look correct.[1545110238] wproc: stderr line 01: /bin/sh: -c: line 0: unexpected EOF while looking for matching `"'
[1545110238] wproc: stderr line 02: /bin/sh: -c: line 1: syntax error: unexpected end of file
Except for the notify-host-by-email command, you should remove the -v (verbose option) from the command.
Make sure there is not an error in the /etc/mail.rc config file that is causing the missing " message.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: set up email alerts using mailx
I've removed "-v" from the command. I checked/review /etc/mail.rc config file, in fact I never edit this file before since nagios core was installed on the system. I've attached the mail.rc file as well as reference.
- Attachments
-
- mail.rc.txt
- /etc/mail.rc
- (2 KiB) Downloaded 383 times
Re: set up email alerts using mailx
That file look OK.
Can you post the full commands.cfg file here so we can view it?
Also, run these commands as root and post the output here.
Can you post the full commands.cfg file here so we can view it?
Also, run these commands as root and post the output here.
Code: Select all
ls -l /usr/bin/printf
ls -l /usr/bin/mailx
Be sure to check out our Knowledgebase for helpful articles and solutions!