Getting Email Alerts working
Posted: Wed Oct 02, 2019 2:31 pm
I have been trying to get Nagios to send out an email when a server is off or down. I thought I had all the .cfg files configured correctly. I am using PostFix and I am able to send a test email from the terminal and it works I get the email. This is what I use to test with:
But when I turn off a server for testing I never get the emial from Nagios. This is how my config files are setup:
1. /usr/local/nagios/etc/objects/contacts.cfg
I also added this entry in the contacts.cfg file;
2. /usr/local/nagios/etc/objects/templates.cfg
3. /usr/local/nagios/etc/objects/commands.cfg. In this commands file I tired setting this both ways like /bin/mail/postfix and /bin/mail -s which was the default.
There was a # mark in the front of 'notify-host-by-email' command definition I have added it and removed it. I also just tried to adding this to the windows.cfg file
4. /usr/local/nagios/etc/objects/windows.cfg
Is there another file I need to configure? Also in the commands.cfg I changed /bin/mail/postfix then i changed it back to /bin/mail -s. This is the output of the nagios.log:
Any help to get this to work will be greatly appreciated, and also any guidance on configuration on getting an email sent out on specific things like disk space to high for a server or CPU too high for too long thinks like that.
Code: Select all
[root@mpnagios objects]# mail [email protected]
Subject: This is a test from Nagios
This is testing the Nagios server can send
Emails. Thanks
.
EOT1. /usr/local/nagios/etc/objects/contacts.cfg
Code: Select all
define contact {
contact_name Alan
use generic-contact
alias Alan
email myemailhere
service_notification_period 24x7
service_notification_options w,u,c,r,f,s
service_notification_commands notify-service-by-email
host_notification_period 24x7
host_notification_options d,u,r,f,s
host_notification_commands notify-host-by-email
}Code: Select all
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
email myemailhere ; Add email here
}Code: Select all
define host{
name svr-ome ; The name of this host template
use generic-host ; Inherit default values from the generic-host template
check_period 24x7 ; By default, Windows servers are monitored round the clock
check_interval 5 ; Actively check the server every 5 minutes
retry_interval 1 ; Schedule host check retries at 1 minute intervals
max_check_attempts 10 ; Check each server 10 times (max)
check_command check-host-alive ; Default command to check if servers are "alive"
notification_period 24x7 ; Send notification out at any time - day or night
notification_interval 30 ; Resend notifications every 30 minutes
notification_options d,r ; Only send notifications for specific host states
contact_groups admins ; Notifications get sent to the admins by default
hostgroups windows-servers ; Host groups that Windows servers should be a member of
register 0 ; DONT REGISTER THIS - ITS JUST A TEMPLATE
}Code: Select all
'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" | /bin/mail/postfix "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}4. /usr/local/nagios/etc/objects/windows.cfg
Code: Select all
define host{
use windows-server ; Inherit default values from a template
host_name svr-ome ; The name we're giving to this host
alias My Windows Server ; A longer name associated with the host
address 172.17.20.8 ; IP address of the host
}Code: Select all
SERVICE ALERT: Svr-ome;Disk Usage;UNKNOWN;HARD;5;UNKNOWN: Error occurred while running the plugin. Use the verbose flag for more details.
[1570042422] SERVICE NOTIFICATION: nagiosadmin;Svr-ome;Disk Usage;UNKNOWN;notify-service-by-email;UNKNOWN: Error occurred while running the plugin. Use the verbose flag for more details.
[1570042425] HOST ALERT: Svr-ome;DOWN;SOFT;1;UNKNOWN: Error occurred while running the plugin. Use the verbose flag for more details.
[1570042472] SERVICE ALERT: Svr-ome;CPU Usage;UNKNOWN;HARD;5;UNKNOWN: Error occurred while running the plugin. Use the verbose flag for more details.
[1570042475] HOST ALERT: Svr-ome;DOWN;SOFT;2;UNKNOWN: Error occurred while running the plugin. Use the verbose flag for more details.
[1570042487] SERVICE ALERT: Svr-ome;Process Count;UNKNOWN;HARD;5;UNKNOWN: Error occurred while running the plugin. Use the verbose flag for more details.
[1570042490] HOST ALERT: Svr-ome;DOWN;SOFT;3;UNKNOWN: Error occurred while running the plugin. Use the verbose flag for more details.
[1570042553] HOST ALERT: Svr-ome;DOWN;SOFT;4;UNKNOWN: Error occurred while running the plugin. Use the verbose flag for more details.
[1570042593] SERVICE ALERT: Svr-ome;Memory Usage;UNKNOWN;SOFT;1;UNKNOWN: Error occurred while running the plugin. Use the verbose flag for more details.
[1570042596] HOST ALERT: Svr-ome;DOWN;HARD;5;UNKNOWN: Error occurred while running the plugin. Use the verbose flag for more details.
[1570042596] HOST NOTIFICATION: nagiosadmin;Svr-ome;DOWN;notify-host-by-email;UNKNOWN: Error occurred while running the plugin. Use the verbose flag for more details.
[1570042596] wproc: NOTIFY job 313 from worker Core Worker 11435 is a non-check helper but exited with return code 126
[1570042596] wproc: host=Svr-ome; service=(none); contact=nagiosadmin
[1570042596] wproc: early_timeout=0; exited_ok=1; wait_status=32256; error_code=0;
[1570042596] wproc: stderr line 01: /bin/sh: /bin/mail/postfix: Not a directory
[1570042596] wproc: stderr line 02: /usr/bin/printf: write error: Broken pipe