Properly setting email notifications for contacts.

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
AvreageJoe
Posts: 1
Joined: Tue Feb 22, 2022 9:04 am

Properly setting email notifications for contacts.

Post by AvreageJoe »

Hi all!

I've recently started using Nagios Core for my monitoring purposes and right now I'm struggling with proper setup of contacts and / or notifications for contact.

I do have a mailserver already present in my network so I didn't install new one on the Nagios machine ( Postfix, etc ... ).
What I did instead is edited the "notify-host-by-email" command in commands.cfg.

Code: Select all

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/mailx -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" -S smtp="smtp://<myMailServerIP>" -S from="my@email.com( Nagios )" $CONTACTEMAIL$
}
This seems to be working just fine. I had to do some tweaking on the mailserver but I have tested this by just running the command in command line ( filling in some details ). It worked as I expected.

Where my problem lies is correct contact settings ? I guess.

say I have following host:

Code: Select all

define host {

    host_name               akro-200                        
    parents                 akro-gw
    use                     akro-server                         
    alias                   Akropolis DC             
    address                 <IP>                  
    hostgroups              akro-servers                           
    _PORT                   <PORT>
    _TOKEN                  <NCPATOKEN>
}
where use akro-server is:

Code: Select all

define host {
    name                            akro-server          
    use                             generic-host           
    check_period                    24x7                   
    check_interval                  5                       
    retry_interval                  1                       
    max_check_attempts              10                     
    check_command                   check-host-alive-p       
    contact_groups                  admins                  
    contacts                        fsit
    hostgroups                      akro-servers             
    register                        0                      
}
with contact_groups admins and contacts fsit being:

Code: Select all

define contact {

    contact_name            fsit                    
    alias                   fsit                    
    email                   myEmail@address.com      
    
    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
}

define contactgroup {

    contactgroup_name       admins
    alias                   Nagios Administrators
    members                 fsit
    
}
when this host goes down I'm not receiving any emails. Same goes for the services added to this host.
Can anyone tell me how to setup mail notifications properly ? Or tell me what am I doing wrong ?

Thank you all kindly.
Joe
Locked