Setup Email Notifications in Nagios Core

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.

Setup Email Notifications in Nagios Core

Postby nib01 » Wed Oct 10, 2018 9:52 am

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

Re: Setup Email Notifications in Nagios Core

Postby cdienger » Wed Oct 10, 2018 4:37 pm

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:

viewtopic.php?f=34&t=46180
viewtopic.php?f=26&t=39588
https://exchange.nagios.org/directory/T ... on/details
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
cdienger
Support Tech
 
Posts: 2211
Joined: Tue Feb 07, 2017 11:26 am

Re: Setup Email Notifications in Nagios Core

Postby scottwilkerson » Wed Oct 10, 2018 4:53 pm

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.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
scottwilkerson
DevOps Engineer
 
Posts: 12656
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises

Re: Setup Email Notifications in Nagios Core

Postby nib01 » Tue Oct 16, 2018 9:22 am

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 [b]-r nagios-email_alert@company.com -s[/b] "** $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)
nib01
 
Posts: 6
Joined: Tue Oct 09, 2018 9:31 am

Re: Setup Email Notifications in Nagios Core

Postby scottwilkerson » Wed Oct 17, 2018 9:56 am

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-postfix-to-relay-mail-to-an-external-smtp-server-on-centos-7/
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
scottwilkerson
DevOps Engineer
 
Posts: 12656
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises

Re: Setup Email Notifications in Nagios Core

Postby nib01 » Wed Oct 17, 2018 12:35 pm

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

Re: Setup Email Notifications in Nagios Core

Postby ssax » Wed Oct 17, 2018 3:54 pm

If your relay server requires authentication then yes, you will need to create that file and follow the provided instructions.
Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
ssax
Dreams In Code
 
Posts: 3464
Joined: Wed Feb 11, 2015 12:54 pm


Return to Nagios Core

Who is online

Users browsing this forum: No registered users and 34 guests