Nagios is an open-source software that can help you monitor your infrastructure 24/7. It has a function that will notify you whenever there's a problem on your servers, switches, applications or services. By sending an email with the information you need to fix the problem.
Click here if you want to know how to install Nagios.
Step 1: Configure contacts.cfg
Edit the contacts.cfg, if the other variables already set just add the others not included.
vi /usr/local/nagios/etc/objects/contacts.cfg
define contact {
Contact_name nagiosadmin
Use generic-contact
Alias Admin
Email admin@localhost.com ←- change to desired email address
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r,s,f
host_notification_options d,u,r,f,s
service_notification_commands notify-service-by-email
host_notification_commands notify-host-by-email
}
[Esc] :wq
Verify if there's no error.
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Step 2: Install dependencies
Install postfix & mailx
yum install –y postfix mailx
alternatives --set mta /usr/sbin/postfix
If above command not work and you get the output as “/usr/sbin/postfix has not been configured as an alternative for mta“. Use below command.
alternatives --set mta /usr/sbin/sendmail.postfix
Configure Postfix uncomment and edit
vi /etc/postfix/main.cf
relayhost = [smtp.gmail.com]:587
smtp_use_tls=yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_mechanism_filter = plain
smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt
[Esc] :wq
Step 3: Get a unique pass
Get the unique pass from google
Step 1: Sign in first to the google account you will use.
Step 2: Go to the google account, click your profile and click Google Account
Step 3: Go to Security tab
Step 4: In the “Signing in to Google” make sure the 2 step verification is On if not just click it and wait for the text message of google to turn on the 2 step verification.
Step 5: After you set the 2-step verification click on the app password and request for it
Step 6: Select mail then select the device to receive the unique app pass from google
Step 4: Configure sasl_passwd
vi /etc/postfix/sasl_passwd
[smtp.gmail.com]:587 <your_email_address@gmail.com>:<unique_app_pass_from_google>
[Esc] :wq
postmap /etc/postfix/sasl_passwd
Step 5: Configure master.cf
vi /etc/postfix/master.cf
Change:
smtp inet n - n - - smtpd
Into:
587 inet n - n - - smtpd
[Esc] :wq
Step 6: Install mail fonts and start postfix
Install this for the mail font
yum -y install cyrus-sasl cyrus-sasl-plain
service postfix restart
chkconfig postfix on
Step 7: Test to send mail
Test if the mail is sending then check the mail logs.
echo "Test mail from postfix" | mail -s "Test Postfix" <your_email_address>@gmail.com
tail /var/log/maillog
No comments:
Post a Comment