To set up e-mail alerts, first you need to make sure the following things.
- Install ssmtp and configure
- Make sure DNS is configured properly and destinations mail domain and source domain are getting resolved.
- Add your and destinations mail id's in contacts, contact groups.
[root@nagios ~]# yum install ssmtp -y
[root@nagios ~]# yum remove sendmail
[root@nagios ~]# rm -rvf /usr/sbin/sendmail
[root@nagios ~]# vim /etc/ssmtp/ssmtp.conf
root=nagadmin@geekinlinux.com
mailhub=mail.geekinlinux.com:25
rewriteDomain=geekinlinux.com
AuthUser=nagadmin
AuthPass=password
FromLineOverride=YES
[root@nagios ~]# ln -s /usr/sbin/ssmtp /usr/sbin/sendmail
[root@nagios ~]# yum remove sendmail
[root@nagios ~]# rm -rvf /usr/sbin/sendmail
[root@nagios ~]# vim /etc/ssmtp/ssmtp.conf
root=nagadmin@geekinlinux.com
mailhub=mail.geekinlinux.com:25
rewriteDomain=geekinlinux.com
AuthUser=nagadmin
AuthPass=password
FromLineOverride=YES
[root@nagios ~]# ln -s /usr/sbin/ssmtp /usr/sbin/sendmail
check dns, status should be NOERROR and ANSWER must be other than 0, like below. see setting up DNS server.
[root@nagios ~]# dig geekinlinux.com mx
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 15065
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2
[root@nagios ~]# dig gmail.com mx
[root@hawk VM-Servers]# dig gmail.com MX
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.10.rc1.el6 <<>> gmail.com MX
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 46293
;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 4, ADDITIONAL: 3
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 15065
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2
[root@nagios ~]# dig gmail.com mx
[root@hawk VM-Servers]# dig gmail.com MX
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.10.rc1.el6 <<>> gmail.com MX
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 46293
;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 4, ADDITIONAL: 3
since our destinations mail id is gmail in this example, i also checked dig for gmail.com. Now configuring Nagios.
[root@nagios ~]# vim /usr/local/nagios/etc/objects/contacts.cfg
define contact {
contact_name nagadmin
use generic-contact
alias Nagios Admin
email gil@gmail.com
}
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members nagadmin
}
define contact {
contact_name nagadmin
use generic-contact
alias Nagios Admin
email gil@gmail.com
}
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members nagadmin
}
[root@nagios ~]# vim /usr/local/nagios/etc/servers/linux-servers/web.cfg
define host{
use linux-server
host_name web
alias apache
address 192.168.85.10
contact_groups admins
}
define host{
use linux-server
host_name web
alias apache
address 192.168.85.10
contact_groups admins
}
Try stopping any service and check if Nagios could send e-mail alert for the failed service/host or not.
0 Comments