Multiple eventhandlers per check

Good morning,

I was just wondering: can we have multiple eventhandlers per service check? If yes, how would the format in the service config look like?

Hi,

As I know only one event handler is possible. More information can be found here: Monitoring Basics - Icinga 2

But what you can do is to put some if-then-else or switch/case blocks in your event handler script, where you can handle different situations.

Yes, that would be my Plan-B.

like: have some custom service variable in the service and check on that in the eventhandler script. I’ll think about that.
Now I would need to find out how to grab the custom service variable in a script…

That’s easy. Pass the macros (e.g. $service.state$) you need as arguments to your script :wink:

Okay so, for the records :slight_smile:

services.conf

vars.event_options = "pager_duty"

commands.conf

"-e" = "$service.vars.event_options$"

eventhandler script

19 while getopts ":o:t:g:e:n:s:a:h:g:v" opt; do
 20    case $opt in
 21       t)    SERVICE_TYPE=$OPTARG >&2 ;;
 22       s)    SERVICE_STATE=$OPTARG >&2 ;;
 23       a)    SERVICE_CHECK_ATTEMPT=$OPTARG >&2 ;;
 24       h)    HOST_NAME=$OPTARG >&2 ;;
 25       n)    SERVICE_NAME=$OPTARG >&2 ;;
 26       g)    HOST_GROUPS=$OPTARG >&2 ;;
 27       o)    SERVICE_OUTPUT=$OPTARG >&2 ;;
 28       e)    EXTRA_VAR=$OPTARG >&2 ;;
 29       \?)   echo "Invalid option: -$OPTARG" >&2
 30             exit $STATE_UNKNOWN
 31       ;;
 32       :)    echo "Option -$OPTARG requires an argument." >&2
 33             exit $STATE_UNKNOWN
 34       ;;
 35    esac
 36 done
.
.
.
if [ "$EXTRA_VAR" == "pager_duty" ]; then
    /bin/logger "Alert - $DESCRIPTION"
fi