Page 1 of 1

Setup Email Notifications in Nagios Core

Posted: Wed Oct 10, 2018 9:52 am
by nib01
I have already installed Nagios Core (latest version) on centos 7.

Our company is currently using office 365 outlook as mail client, and would like to use SMTP, or what do you recommend as the best to use on Centos 7?

Id like to setup an email account that could send email from using nagios-email_alert@company.com. This account should be only send email but does not receive.

Re: Setup Email Notifications in Nagios Core

Posted: Wed Oct 10, 2018 4:37 pm
by cdienger
I don't have any personal experience with either, but finding a tutorial on setting up a sendmail relay to office 365 is more difficult to find than a postfix guide:

https://linuxhowtoguide.blogspot.com/20 ... relay.html
https://geekdudes.wordpress.com/2018/04 ... ffice-365/

Some other links of interest:

https://support.nagios.com/forum/viewto ... 34&t=46180
https://support.nagios.com/forum/viewto ... 26&t=39588
https://exchange.nagios.org/directory/T ... on/details

Re: Setup Email Notifications in Nagios Core

Posted: Wed Oct 10, 2018 4:53 pm
by scottwilkerson
This really is more of a server admin question, but at a basic level on a CentOS machine you should be able to modify your notification commands and add a

Code: Select all

-r nagios-email_alert@company.com
so something like this:

Code: Select all

define command {
    command_name    notify-host-by-email
    command_line    /usr/bin/printf "%b" "***** Nagios Monitor XI Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -r nagios-email_alert@company.com -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}

define command {
    command_name    notify-service-by-email
    command_line    /usr/bin/printf "%b" "***** Nagios Monitor XI Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /bin/mail -r nagios-email_alert@company.com -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}
per man mail

Code: Select all

-r address
              Sets the From address. Overrides any from variable specified in environment or startup files.  Tilde escapes are disabled.  The -r address options are passed  to  the  mail
              transfer agent unless SMTP is used.  This option exists for compatibility only; it is recommended to set the from variable directly instead.

Re: Setup Email Notifications in Nagios Core

Posted: Tue Oct 16, 2018 9:22 am
by nib01
So I've added "-r nagios-email_alert@company.com -s" in the command.conf file of nagioscore as shown below. My nagioscore which the smarthost is currently running on Centos 7, and would like to setup up a mail relay from this host (Centos 7) to office 365 Internal mail relay server as shown below:

Company Internal mail relay service:
Server: mailrelay.int.company.com
Server IP addresses: 10.130.128.21, 10.130.128.30
Port: 25


define command {
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios Monitor XI Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -r nagios-email_alert@company.com -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}

define command {
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios Monitor XI Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /bin/mail -r nagios-email_alert@company.com -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$

My question is..from Centos 7 point of view, what should I use as mail transfer agent to handle the delivery of the email alert/notification from, that it works very well with office 365, and also from smarthost (Centos 7) there should be a mail protocol that need to be enabled (which Im not sure what that is)

Re: Setup Email Notifications in Nagios Core

Posted: Wed Oct 17, 2018 9:56 am
by scottwilkerson
This is not really a nagios issue and more of a how to setup postfix issue.

Here is a document I found on the Internet that goes through setting up a mail relay in postfix

See the "Configure Postfix Server as a Relay" section at
https://www.lisenet.com/2018/configure- ... -centos-7/

Re: Setup Email Notifications in Nagios Core

Posted: Wed Oct 17, 2018 12:35 pm
by nib01
Im able to configure postfix server relay section by following this guide: https://www.lisenet.com/2018/configure- ... -centos-7/

But Im confused whether I need to create the following file.

Create a new file /etc/postfix/sasl_passwd and add the authentication details of the external SMTP server:

[mail.example.com]:587 user@example.com:passwd
Prevent non-root access:

# chmod 0600 /etc/postfix/sasl_passwd
Create a database file:

# postmap /etc/postfix/sasl_passwd
Check configuration and restart Postfix service:

# postfix check
# systemctl restart postfix
Configure Postfix on a Null Client
When we configure other homelab servers to us Postfix to relay emails via admin1 and admin2, we can have a fallback relay defined (taken from the Postfix configuration file /etc/postfix/main.cf that’s on the Katello server):

relayhost = [admin1.hl.local]
fallback_relay = [admin2.hl.local]

Re: Setup Email Notifications in Nagios Core

Posted: Wed Oct 17, 2018 3:54 pm
by ssax
If your relay server requires authentication then yes, you will need to create that file and follow the provided instructions.