set up email alerts using mailx

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
nib01
Posts: 31
Joined: Tue Oct 09, 2018 9:31 am

set up email alerts using mailx

Post by nib01 »

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]$
bolson

Re: set up email alerts using mailx

Post by bolson »

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:

Code: Select all

tail -100 /var/log/maillog
Immediately after attempting to send the message.

Thank you!
nib01
Posts: 31
Joined: Tue Oct 09, 2018 9:31 am

Re: set up email alerts using mailx

Post by nib01 »

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]$
bolson

Re: set up email alerts using mailx

Post by bolson »

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!
nib01
Posts: 31
Joined: Tue Oct 09, 2018 9:31 am

Re: set up email alerts using mailx

Post by nib01 »

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$
}
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: set up email alerts using mailx

Post by npolovenko »

@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.
nib01
Posts: 31
Joined: Tue Oct 09, 2018 9:31 am

Re: set up email alerts using mailx

Post by nib01 »

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
Attachments
nagios.log
(1.16 MiB) Downloaded 233 times
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: set up email alerts using mailx

Post by tgriep »

Everytime the command runs, it generates this error
[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
So there may be a missing " somewhere but the commands do look correct.
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!
nib01
Posts: 31
Joined: Tue Oct 09, 2018 9:31 am

Re: set up email alerts using mailx

Post by nib01 »

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 262 times
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: set up email alerts using mailx

Post by tgriep »

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.

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!
Locked