LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Nagios Email notifications (https://www.linuxquestions.org/questions/linux-newbie-8/nagios-email-notifications-683098/)

jackie001 11-13-2008 05:12 AM

Nagios Email notifications
 
Hi experts,
I have set up Nagios 3 monitoring some machines and their services. I am now trying to set up email notifications.
I have installed the following on the linux box:
eSMTP- run
procmail
I can send emails with the following line:
echo "test" | /usr/bin/esmtp - C ~/esmtprc me@outsideemailaddress - f me@internalemailaddress
This sends me an email from our mail server. However when i try:
mailx -s tacos myemail@email.com
this just hangs.

The commands.cfg files contains:
# 'notify-host-by-email' command definition
define command{
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotificatio$... | /usr/bin/mailx -s "** $NOTIFICATIONTYPE$ Host...
}

# 'notify-service-by-email' command definition
define command{
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotificatio$... | /usr/bin/mailx -s "** $NOTIFICATIONTYPE$ Host
}


Can i make modifications to these commands to use esmtp and not mailx or any suggestions to getting mailx working with eSMTP.
Also how can you force nagios to send email notifications for testing.

Thanks for any advice

marozsas 11-13-2008 07:51 AM

Sure you can modify notify-host/service-by-email command_line entry.
Code:

command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotificatio$... |  /usr/bin/esmtp -C /full/path/to/nagios/esmtprc_file - f nagios@yourdomain.com
I don't have eSMTP server installed, so I don't recall right now the option to subject. Check eSMTP man page and add it to the end of command, just after -f nagios@yourdomain.com and use the same subject string from original mailx.

Don't forget to restart your nagios after that.

williebens 11-13-2008 01:54 PM

Hello jackie001:

If you get this to work, please let me know. I am stuck in getting nagios to send notifications.

Thanks.

jackie001 11-14-2008 10:58 AM

Thanks for the response.
For esmtp there is no sytax to use a subject line so i has to leave out -s and the following lines.
I checked the syntax at the command line and it works! thanks so much. The file now reads:

# '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/esmtp -C /etc/esmtprc $CONTACTEMAIL$ -f nagios@dpd.ie -X /tmp/esmtp.log
}

# '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$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/esmtp -C /etc/esmtprc $CONTACTEMAIL$ -f nagios@dpd.ie -X /tmp/esmtp.log
}




However i still dont recieve emails! The mistake must lie in the config files. Ive been over and over these files maybe you could have a quick look it might be a simple mistake. everything compiles correctly and the web interface is working perfectly.
The windows.cfg contains the following, all of the host , hostgroup and service definitions are basically the same. Should i also add lines to the host definition like notifications_enabled 1 etc.Is it enough fro it to be in the services definition and the contacts.cfg file


define host{
use windows-pcs ; Inherit default values from a template
host_name invoicepc ; The name we're giving to this host
alias invoicingpc ; A longer name associated with the host
address x.x.x.x ; IP address of the host
}
define hostgroup{
hostgroup_name windows-pcs ; The name of the hostgroup
alias Windows PCs ; Long name of the group
members invoicepc
}
define service{
use generic-service
hostgroup_name windows-pcs
service_description Uptime
check_command check_nt!UPTIME
contact_groups admins
check_period 24x7
max_check_attempts 3
normal_check_interval 5
retry_check_interval 1
contact_groups admins
notification_options w,u,c,r
notification_interval 1440
notification_period 24x7
}

The contacts.cfg file reads:
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_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 x@email.com ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}


All times are GMT -5. The time now is 12:11 PM.