Re: set up email alerts notification in RHEL7

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

Re: set up email alerts notification in RHEL7

Post by nib01 »

We have Nagios core currently running on RHEL 7, and would like to know how to setup email notification.

MS outlook is our company email server provider and mailrelay.int.company.com and port # already verified the communication between Nagios core host and mail-relay server is pingable.
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: set up email alerts notification in RHEL7

Post by ssax »

See here:

Code: Select all

https://www.certdepot.net/rhel7-configure-system-forward-email-central-mail-server/
Then it should work assuming you're using the default notification commands.
nib01
Posts: 31
Joined: Tue Oct 09, 2018 9:31 am

Re: set up email alerts notification in RHEL7

Post by nib01 »

Here's the command.cfg file on my nagios core. Not sure what you mean by default notification commands.

define command {

command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios Monitor Core Alert*****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nHost: $HOSTNAME$\n\nState: $HOSTSTATE$\n\nAddress: $HOSTADDRESS$\n\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mailx -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" -S smtp=mailrelay.int.company.com -S from=alerts.gainspeed@company.com $CONTACTEMAIL$
}

define command {

command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios Monitor Core Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\n\nHost: $HOSTALIAS$\n\nAddress: $HOSTADDRESS$\n\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/bin/mailx -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -S smtp=mailrelay.int.company.com -S from=alerts.gainspeed@company.com $CONTACTEMAIL$
}
nib01
Posts: 31
Joined: Tue Oct 09, 2018 9:31 am

Re: set up email alerts notification in RHEL7

Post by nib01 »

Also, It throws some error message when I tried to execute command below.

# systemctl restart postfix.service


Job for postfix.service failed because the control process exited with error code. See "systemctl status postfix.service" and "journalctl -xe" for details.
[nagios@nagios2 ~]$ sudo journalctl -xe
[sudo] password for nagios:
Jul 01 12:03:56 nagios2 nagios[19601]: job 55678 (pid=11725): read() returned error 11
Jul 01 12:03:56 nagios2 nagios[19600]: wproc: Core Worker 19601: job 55678 (pid=11725) timed out. Killing it
Jul 01 12:03:56 nagios2 nagios[19600]: wproc: CHECK job 55678 from worker Core Worker 19601 timed out after 30.01s
Jul 01 12:03:56 nagios2 nagios[19600]: wproc: host=sulfur; service=(null);
Jul 01 12:03:56 nagios2 nagios[19600]: wproc: early_timeout=1; exited_ok=0; wait_status=0; error_code=62;
Jul 01 12:03:56 nagios2 nagios[19600]: Warning: Check of host 'sulfur' timed out after 30.01 seconds
Jul 01 12:03:57 nagios2 nagios[19600]: wproc: Core Worker 19601: job 55678 (pid=11725): Dormant child reaped
Jul 01 12:05:16 nagios2 dhclient[9462]: DHCPDISCOVER on eno2 to 255.255.255.255 port 67 interval 3 (xid=0x491cfe60)
Jul 01 12:05:19 nagios2 dhclient[9462]: DHCPDISCOVER on eno2 to 255.255.255.255 port 67 interval 5 (xid=0x491cfe60)
Jul 01 12:05:24 nagios2 dhclient[9462]: DHCPDISCOVER on eno2 to 255.255.255.255 port 67 interval 7 (xid=0x491cfe60)
Jul 01 12:05:31 nagios2 dhclient[9462]: DHCPDISCOVER on eno2 to 255.255.255.255 port 67 interval 8 (xid=0x491cfe60)
Jul 01 12:05:39 nagios2 dhclient[9462]: DHCPDISCOVER on eno2 to 255.255.255.255 port 67 interval 10 (xid=0x491cfe60)
Jul 01 12:05:49 nagios2 dhclient[9462]: DHCPDISCOVER on eno2 to 255.255.255.255 port 67 interval 14 (xid=0x491cfe60)
Jul 01 12:06:03 nagios2 dhclient[9462]: DHCPDISCOVER on eno2 to 255.255.255.255 port 67 interval 12 (xid=0x491cfe60)
Jul 01 12:06:15 nagios2 dhclient[9462]: DHCPDISCOVER on eno2 to 255.255.255.255 port 67 interval 2 (xid=0x491cfe60)
Jul 01 12:06:17 nagios2 dhclient[9462]: No DHCPOFFERS received.
Jul 01 12:06:17 nagios2 dhclient[9462]: No working leases in persistent database - sleeping.
Jul 01 12:06:20 nagios2 polkitd[5302]: Registered Authentication Agent for unix-process:12041:204185302 (system bus name :1.13884 [/usr/bin/pkttyagent --notify-fd 5 --fallback], object path /org/freedesk
Jul 01 12:06:23 nagios2 polkitd[5302]: Operator of unix-process:12041:204185302 successfully authenticated as unix-user:root to gain ONE-SHOT authorization for action org.freedesktop.systemd1.manage-unit
Jul 01 12:06:23 nagios2 systemd[1]: Starting Postfix Mail Transport Agent...
-- Subject: Unit postfix.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/li ... temd-devel
--
-- Unit postfix.service has begun starting up.
Jul 01 12:06:23 nagios2 aliasesdb[12058]: /usr/sbin/postconf: warning: valid_hostname: invalid character 32(decimal): nagios2
Jul 01 12:06:23 nagios2 aliasesdb[12058]: /usr/sbin/postconf: fatal: unable to use my own hostname
Jul 01 12:06:24 nagios2 postfix/sendmail[12061]: warning: valid_hostname: invalid character 32(decimal): nagios2
Jul 01 12:06:24 nagios2 aliasesdb[12058]: newaliases: warning: valid_hostname: invalid character 32(decimal): nagios2
Jul 01 12:06:24 nagios2 aliasesdb[12058]: newaliases: fatal: unable to use my own hostname
Jul 01 12:06:24 nagios2 postfix/sendmail[12061]: fatal: unable to use my own hostname
Jul 01 12:06:24 nagios2 postfix[12068]: warning: valid_hostname: invalid character 32(decimal): nagios2
Jul 01 12:06:24 nagios2 postfix[12068]: fatal: unable to use my own hostname
Jul 01 12:06:25 nagios2 systemd[1]: postfix.service: control process exited, code=exited status=1
Jul 01 12:06:25 nagios2 systemd[1]: Failed to start Postfix Mail Transport Agent.
-- Subject: Unit postfix.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/li ... temd-devel
--
-- Unit postfix.service has failed.
--
-- The result is failed.
Jul 01 12:06:25 nagios2 systemd[1]: Unit postfix.service entered failed state.
Jul 01 12:06:25 nagios2 systemd[1]: postfix.service failed.
Jul 01 12:06:25 nagios2 polkitd[5302]: Unregistered Authentication Agent for unix-process:12041:204185302 (system bus name :1.13884, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en
Jul 01 12:06:59 nagios2 nagios[19602]: job 55688 (pid=12082): read() returned error 11
Jul 01 12:06:59 nagios2 nagios[19600]: wproc: Core Worker 19602: job 55688 (pid=12082) timed out. Killing it
Jul 01 12:06:59 nagios2 nagios[19600]: wproc: CHECK job 55688 from worker Core Worker 19602 timed out after 30.01s
Jul 01 12:06:59 nagios2 nagios[19600]: wproc: host=rancid; service=(null);
Jul 01 12:06:59 nagios2 nagios[19600]: wproc: early_timeout=1; exited_ok=0; wait_status=0; error_code=62;
Jul 01 12:06:59 nagios2 nagios[19600]: Warning: Check of host 'rancid' timed out after 30.01 seconds
Jul 01 12:06:59 nagios2 nagios[19600]: wproc: Core Worker 19602: job 55688 (pid=12082): Dormant child reaped
Jul 01 12:07:12 nagios2 sudo[12153]: nagios : TTY=pts/0 ; PWD=/home/nagios ; USER=root ; COMMAND=/bin/journalctl -xe
Jul 01 12:07:12 nagios2 sudo[12153]: pam_unix(sudo:session): session opened for user root by labuser(uid=0)
Attachments
postfix_installation_error.PNG
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

Re: set up email alerts notification in RHEL7

Post by cdienger »

Decimal 32 is a space. It would appear the configuration has an extra space in the hostname somewhere. Check in main.cf.
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 notification in RHEL7

Post by nib01 »

main.cfg
(26.36 KiB) Downloaded 216 times
The "myhostname" lines in main.cf file are commented out.

I tried adding my nagioscore server hostname in main.cf, but same error message.

nagioscore.mycompany.com
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

Re: set up email alerts notification in RHEL7

Post by cdienger »

It may be referenced elsewhere. Try "grep -R nagios2 /etc/" and looking at any configuration that may have been touched.
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 notification in RHEL7

Post by nib01 »

I was able to fix the error by changing the hostname format.

Now, we have a nagioscore system already running on Ubuntu. My company is currently in transition from Ubuntu to Redhat.

Below is the existing nagioscore system .mailrc configuration file.
[nagios@nagioscore ~]$ vi .mailrc

set -S smtp=mailrelay.int.company.com
set -S from=alerts.gainspeed@company.com

Not sure If I can follow the Null-client configuration on RHEL with .mailrc configuration on Ubuntu is much easier to configure than main.conf on Redhat .
nib01
Posts: 31
Joined: Tue Oct 09, 2018 9:31 am

Re: set up email alerts notification in RHEL7

Post by nib01 »

Here's Null-client Configuration. Ran all the Check the syntax commands everything passed. But Test failed. See error messages below:

# systemctl restart postfix
myhostname = nagios2.gainspeed.nsn-rdnet.net
mydomain = gainspeed.nsn-rdnet.net
myorigin = alerts.gainspeed@nokia.com
relayhost = mailrelay.int.company.com

Check the syntax:

# postfix check
Check the non-default configuration:

# postconf -n
Reload the postfix configuration:

# systemctl restart postfix


[user@nagiosmon ~]$ mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
15F37A43D0 500 Mon Jul 8 19:04:45 "user@alerts.gainspeed"@company.com
(Host or domain name not found. Name service error for name=mailrelay.int.company.com type=MX: Host not found, try again)
john.smith@company.com

9468BA43ED 500 Mon Jul 8 19:21:22 "user@alerts.gainspeed"@company.com
(Host or domain name not found. Name service error for name=mailrelay.int.company.com type=MX: Host not found, try again)
john.smith@company.com
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

Re: set up email alerts notification in RHEL7

Post by cdienger »

MX: Host not found, try again
This is an issue with find an MX record for company.com. Make sure valid entries are returned when you run:

Code: Select all

nslookup
set q=mx
company.com
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Locked