Send notification only if notificationtype=PROBLEM

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
julab
Posts: 2
Joined: Thu Jun 04, 2015 3:50 am

Send notification only if notificationtype=PROBLEM

Post by julab »

Hello,

I would like to send a notification only in case of a problem. I don't want to send notification when it is recovery or flapping.

I tried this but it does not work :

Code: Select all

define command {
        command_name    notify-service-problem-by-email
        command_line    [ "$NOTIFICATIONTYPE$" = "PROBLEM" ] && /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$" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
        }
Any idea ?
Thanks
jdalrymple
Skynet Drone
Posts: 2620
Joined: Wed Feb 11, 2015 1:56 pm

Re: Send notification only if notificationtype=PROBLEM

Post by jdalrymple »

Is there a reason you're not doing this in notification options:
Object Definitions wrote: notification_options:
This directive is used to determine when notifications for the service should be sent out. Valid options are a combination of one or more of the following: w = send notifications on a WARNING state, u = send notifications on an UNKNOWN state, c = send notifications on a CRITICAL state, r = send notifications on recoveries (OK state), f = send notifications when the service starts and stops flapping, and s = send notifications when scheduled downtime starts and ends. If you specify n (none) as an option, no service notifications will be sent out. If you do not specify any notification options, Nagios will assume that you want notifications to be sent out for all possible states. Example: If you specify w,r in this field, notifications will only be sent out when the service goes into a WARNING state and when it recovers from a WARNING state.
julab
Posts: 2
Joined: Thu Jun 04, 2015 3:50 am

Re: Send notification only if notificationtype=PROBLEM

Post by julab »

Thanks for the reply. Didn't know this trick. Works fine now.
Locked