set up email alerts using mailx

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.

set up email alerts using mailx

Postby nib01 » Fri Dec 14, 2018 7:21 pm

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

Re: set up email alerts using mailx

Postby bolson » Mon Dec 17, 2018 10:34 am

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!
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Brian Olson
Nagios Support Team
---
Nagios Enterprises, LLC
Email: customersupport@nagios.com
Web: https://www.nagios.com/
User avatar
bolson
The Closer
 
Posts: 777
Joined: Tue Jul 11, 2017 10:34 am

Re: set up email alerts using mailx

Postby nib01 » Mon Dec 17, 2018 2:36 pm

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

Re: set up email alerts using mailx

Postby bolson » Mon Dec 17, 2018 3:32 pm

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!
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Brian Olson
Nagios Support Team
---
Nagios Enterprises, LLC
Email: customersupport@nagios.com
Web: https://www.nagios.com/
User avatar
bolson
The Closer
 
Posts: 777
Joined: Tue Jul 11, 2017 10:34 am

Re: set up email alerts using mailx

Postby nib01 » Mon Dec 17, 2018 4:45 pm

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

Re: set up email alerts using mailx

Postby npolovenko » Mon Dec 17, 2018 5:58 pm

@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.
User avatar
npolovenko
Support Tech
 
Posts: 2846
Joined: Mon May 15, 2017 5:00 pm

Re: set up email alerts using mailx

Postby nib01 » Tue Dec 18, 2018 3:43 pm

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$
}


viewtopic.php?f=7&t=39208
Attachments
nagios.log
(1.16 MiB) Downloaded 36 times
nib01
 
Posts: 19
Joined: Tue Oct 09, 2018 9:31 am

Re: set up email alerts using mailx

Postby tgriep » Wed Dec 19, 2018 5:57 pm

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.
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: 7557
Joined: Thu Oct 30, 2014 9:02 am

Re: set up email alerts using mailx

Postby nib01 » Thu Dec 20, 2018 1:10 pm

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

Re: set up email alerts using mailx

Postby tgriep » Thu Dec 20, 2018 1:43 pm

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
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: 7557
Joined: Thu Oct 30, 2014 9:02 am

Next

Return to Nagios Core

Who is online

Users browsing this forum: rfaraci and 40 guests