Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

This question already has an answer here:

I want to set Nagios up to issue warnings (e.g. mildly high load or disk usage) via email, but for critical items to alert by pager.

Right now we notify via email and pager simultaneously for all warnings. My generic contact definition is as follows:

define contact{
    name                            generic-contact
    service_notification_options    w,u,c,r,f,s
    host_notification_options       d,u,r,f,s
    service_notification_commands   notify-service-by-email,notify-service-by-pager
    host_notification_commands      notify-host-by-email,notify-host-by-pager
    register                        0

    service_notification_period     24x7
    host_notification_period        24x7
}

How can I make it so that the email notification occurs for both warnings and critical, but paging for critical only?

share|improve this question

marked as duplicate by quanta, mdpc, Khaled, Tom O'Connor, dunxd Feb 20 '13 at 12:50

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
The question isn't an exact duplicate, but the answer is the correct answer for this question too - you need to set up multiple contacts for the same person, then assign these contacts according to how you require notification. –  dunxd Feb 20 '13 at 12:50
add comment

3 Answers

up vote 4 down vote accepted

You should be able to achieve this by defining different contacts - one for pager notification only, one for email notification only - and assigning different values of host/service_notification_options:

define contact{
    name                            email-contact
    service_notification_options    w,u,c,r,f,s
    host_notification_options       d,u,r,f,s
    service_notification_commands   notify-service-by-email
    host_notification_commands      notify-host-by-email
    register                        0

    service_notification_period     24x7
    host_notification_period        24x7
}

define contact{
    name                            pager-contact
    service_notification_options    c,r
    host_notification_options       d,u,r
    service_notification_commands   notify-service-by-pager
    host_notification_commands      notify-host-by-pager
    register                        0

    service_notification_period     24x7
    host_notification_period        24x7
}

If you want to keep host/service definition overhead low, you should aggregate them in a contactgroup like this:

define contactgroup{

    contactgroup_name       pager-email
    members         pager-contact,email-contact
}

and use the contactgroup instead of individual contacts.

share|improve this answer
    
Even better, nice solution +1 –  Lucas Kauffman Apr 13 '12 at 19:12
add comment

I don't know if this is the best option, but I can't recall of Nagios being able to page only on a special flag. What you can do however is duplicate the contact with his name and something to id him as sms (name-sms). This will cause redundant contacts. However if you are using groups you can just add the contact to the group.

define contact{
    name                            generic-contact-sms
    service_notification_options    c
    host_notification_options       d,u,r,f,s
    service_notification_commands   notify-service-by-pager
    host_notification_commands      notify-host-by-pager
    register                        0

    service_notification_period     24x7
    host_notification_period        24x7
}
share|improve this answer
add comment

To send the WARNING alert via email and the CRITICAL alert via SMS, I also defined 2 contacts: one for email and one for SMS. It's working fine but below are what I have tried to accomplish this with only one contact.

The idea is re-write the (service|host)_notification_commands to check the $SERVICESTATE$ macro then use the corresponding method.

command.cfg

define command{
    command_name    notify-service
    command_line    $USER1$/notify.sh $SERVICESTATE$ $LASTSERVICESTATE$ $NOTIFICATIONTYPE$ $SERVICEDESC$ $HOSTALIAS$ $HOSTADDRESS$ "$LONGDATETIME$" "$SERVICEOUTPUT$" "$SERVICENOTESURL$" $CONTACTEMAIL$ $CONTACTPAGER$ $TIME$
    }

notify.sh

#!/bin/bash

SERVICESTATE=$1
LASTSERVICESTATE=$2
NOTIFICATIONTYPE=$3
SERVICEDESC=$4
HOSTALIAS=$5
HOSTADDRESS=$6
LONGDATETIME=$7
SERVICEOUTPUT=$8
SERVICENOTESURL=$9
CONTACTEMAIL=${10}
CONTACTPAGER=${11}
TIME=${12}

send_email() {
    /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: $SERVICEOUTPUT\n\nURL: $SERVICENOTESURL" | /bin/mail -s "** $NOTIFICATIONTYPE Service Alert: $HOSTALIAS/$SERVICEDESC is $SERVICESTATE **" $CONTACTEMAIL
}

send_sms() {
    /usr/bin/wget --user=notifier --password=x "http://ip:port/smsgate/sms?tos=$CONTACTPAGER&content=$NOTIFICATIONTYPE, $SERVICEDESC, $HOSTADDRESS, $SERVICESTATE, $TIME, $SERVICEOUTPUT"

}

if [ $NOTIFICATIONTYPE = "PROBLEM" ]; then
    if [ $SERVICESTATE = "WARNING" ]; then
        send_email
    elif [ $SERVICESTATE = "CRITICAL" ]; then
        send_email
        send_sms
    fi
elif [ $NOTIFICATIONTYPE = "RECOVERY" ]; then
    if [ $LASTSERVICESTATE = "WARNING" ]; then
        send_email
    elif [ $LASTSERVICESTATE = "CRITICAL" ]; then
        send_email
        send_sms
    fi
fi

Notice that when the service is OK, I need to check the $LASTSERVICESTATE$ macro to decide which method to use.

contacts.cfg

define contact{
        contact_name                    quanta
        use                             single-contact
        alias                           Quan Tong Anh
        service_notifications_enabled   1
        host_notifications_enabled      1
        service_notification_period     24x7
        host_notification_period        24x7
        service_notification_options    c,w,r
        host_notification_options       d,u,r
        email                           quanta@domain.com
        pager                           0912345678
        }

templates.cfg

define contact{
        name                            single-contact
        service_notification_period     24x7
        host_notification_period        24x7
        service_notification_options    w,u,c,r,f,s
        host_notification_options       d,u,r,f,s
        service_notification_commands   notify-service
        host_notification_commands      notify-host
        register                        0
        }

Give it a try.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.