LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   send email notifications in nagios (https://www.linuxquestions.org/questions/linux-newbie-8/send-email-notifications-in-nagios-820952/)

LayTech 07-20-2010 05:03 AM

send email notifications in nagios
 
Hello.

i wanna send email notifications when the servers' services gone down. i have installed nagios successfully in ubuntu 9.10.

in the contacts.cfg, i added this :

define contact{
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of user
host_notifications_enabled 1
service_notifications_enabled 1
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-service-by-email
host_notification_commands notify-host-by-email


email myemail@hotmail.com
}

for the contacts_group in contacts.cfg, i add this :

define contactgroup {
contactgroup_name admins
alias Nagios Administrators
members nagiosadmin
}


for the windows.cfg, i added this:

define host{
use generic-host
host_name qauser-863c2d42
alias qauser-863c2d42
address 172.20.130.71

check_command check-host-alive
max_check_attempts 10

notification_interval 120
notification_period 24x7
notification_options d,u,r
contact_groups admins
notifications_enabled 1
}

in commands.cfg, i changed the /bin/mail to the following:

# 'notify-host-by-email' command definition
define command{
command_name notify-host-by-email



command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" |/usr/bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}

# 'notify-service-by-email' command definition
define command{
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$

}


i have installed postfix too..

what else am i missing? i cant receive email in my email inbox even though the services of the windows server which i'm monitoring are down...

p/s: i have googled for countless of times..it seems i'm on the right track, but what doesn't it work?

please help, thanks lots.

sem007 07-20-2010 07:34 AM

Hi Wel-come to LQ,

Just install postfix server and set it as satellite mail system and point it to your exchange or SMTP server. This info it will ask during initial installation.

run following command if you want to re-configure postfix
Code:

dpkg-reconfigure postfix
HTH

LayTech 07-20-2010 08:48 AM

How to point it to the SMTP server? i think i got installed smtp in one windows server which i'm currently monitoring.. so i just point to that ip address?

thanks

sem007 07-20-2010 08:59 AM

Quote:

How to point it to the SMTP server? i think i got installed smtp in one windows server which i'm currently monitoring.. so i just point to that ip address?
At postfix installation time it asked for relay host. give your smtp server name here.

or you can manual edit your postfix configuration.

Code:

vi /etc/postfix/main.cf

relayhost = smtp.example.com  <=(your smtp server name)

In above example your nagios server use smtp.example.com server to sendmail.

LayTech 07-20-2010 10:08 AM

Can ask a stupid question? sorry i'm a noob.

hmm how to check the smtp server name in windows xp sp2? =X

i tried this:

telnet servername portnumber

but can't

sem007 07-20-2010 10:40 AM

Quote:

i tried this:

telnet servername portnumber

but can't
Are you able to connect on port 25?

for mail server name try below command on linux

Code:

dig example.com MX <= replace example.com with your domain name
It will display mail server entry like

Code:

example.com. 14400 IN MX 0 smtp.example.com
for windows
Code:

open command prompt
c:\>nslookup
>set type=mx <= set query type
>example.com <= enter your domain name

look below link
http://www.tech-recipes.com/rx/381/s...or_open_relay/

LayTech 07-20-2010 07:55 PM

Quote:

Originally Posted by sem007 (Post 4039574)
Are you able to connect on port 25?

Hi,

i got this error when i typed "telnet servername portnumber"

telnet: could not resolve servername/portnumber: Servname not supported for ai_socktype

Hmm okay. i installed smtp server in my ubuntu platform (the one running nagios)

when i typed in "dig server.com MX" i got the following :

Quote:

$ dig server.com MX

; <<>> DiG 9.6.1-P1 <<>> server.com MX
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 63379
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;server.com. IN MX

;; ANSWER SECTION:
server.com. 5 IN MX 0 smtp.secureserver.net.
server.com. 5 IN MX 10 mailstore1.secureserver.net.

;; Query time: 37 msec
;; SERVER: 192.168.142.2#53(192.168.142.2)
;; WHEN: Tue Jul 20 19:02:25 2010
;; MSG SIZE rcvd: 92
And when i tried "telnet 216.69.186.201", i got this error ?

Quote:

name@ubuntu:~$ telnet 216.69.186.201
Trying 216.69.186.201...
telnet: Unable to connect to remote host: Connection refused
layleng@ubuntu:~$ nslookup
> set type=mx
> server.com
Server: 192.168.142.2
Address: 192.168.142.2#53

Non-authoritative answer:
server.com mail exchanger = 0 smtp.secureserver.net.
server.com mail exchanger = 10 mailstore1.secureserver.net.

Authoritative answers can be found from:
smtp.secureserver.net internet address = 216.69.186.201
mailstore1.secureserver.net internet address = 216.69.186.201
> telnet 216.69.186.201 25
Server: 192.168.142.2
Address: 192.168.142.2#53

** server can't find telnet: SERVFAIL

sem007 07-21-2010 03:31 AM

Hi,

use server name instead of IP Address.
Code:

telnet smtp.secureserver.net 25
add smtp.secureserver.net in your postfix configuration file (main.cf)

relayhost = smtp.secureserver.net

restart postfix service
/etc/init.d/postfix restart

and send test mail on one emailID.
mail -s "test mail" -v test@emailID

also check log file for error
tail -f /var/log/mail

Let me know if it gives any error.

HTH

LayTech 07-23-2010 07:08 AM

Hi HTH,

Hmm, sorry i didn't mention earlier that i did not have a 'proper' (don't know if that is the correct word to use) stmp server. I did install this stmp server online : http://www.softstack.com/freesmtp.html but not sure if it can really be used? Cause my email doesn't get send. My teacher said that stmp server i've installed is not the real/correct server? I don't get, :X

And, i've installed postfix in my ubuntu server.

Anymore things i have to add on or am i missing anything?

Thanks

[Add On]:
The stmp server name..i got it on one of my windows xp server, is it ok? Or should i be using the server name of the ubuntu server which had the nagios installed? Sorry, i know i'm noob :x

And thanks again.

LayTech 07-23-2010 09:03 AM

Quote:

Originally Posted by sem007 (Post 4040402)
Hi,

use server name instead of IP Address.
Code:

telnet smtp.secureserver.net 25
add smtp.secureserver.net in your postfix configuration file (main.cf)

relayhost = smtp.secureserver.net

restart postfix service
/etc/init.d/postfix restart

and send test mail on one emailID.
mail -s "test mail" -v test@emailID

also check log file for error
tail -f /var/log/mail

Let me know if it gives any error.

HTH

The 'smtp.secureserver.net' you gave as an example is made up of hostname and domain name respectively right? (smtp = hostname; 'secureserver.net = domain name) A stupid question to ask, how to get the domain name? The domain name of which server? Any windows server which i'm currently monitoring or the ubuntu server which had the nagios installed?

LayTech 07-24-2010 06:34 AM

Hmm, sorry but could someone help me out? x_x sorry.


All times are GMT -5. The time now is 02:46 PM.