#!/bin/sh
LOG_LEVEL="${1}"
shift
LOG_TYPE="${1}"
shift

RSFSYSEVENTD="/opt/HAC/RSF-1/bin/rsfsyseventd"

# SUP-84/SG-535 We don't need this in Linux/BSD
if [ ! -f "${RSFSYSEVENTD}" ] ; then
    exit 0
fi

case "${LOG_TYPE}" in
    ACTIVE_SCRIPTS)	extra_flags="--immediate-delivery"	;;
    *)			extra_flags=""				;;
esac


exec "${RSFSYSEVENTD}" $extra_flags --request rsf_publicevent \
    --rsfevent-log-level="${LOG_LEVEL}" --rsfevent-log-type="${LOG_TYPE}" "$@"

exit 1				# Stop now if exec failed

# This is a filter to remove some events from the RSF-1 event stream.
# This example removes disc heartbeat events, eg.
# LOG_INFO RSF_HEARTBEAT heartbeat=5 type=disc from=test2 state=Unavailable
# LOG_INFO RSF_SERVICE service=pool2 state=stopped mode=manual block=unblocked SERVICE_ZPOOL_GUID="11914438232075897384"
#
# To use this find out what the current event logger is called, by
# looking in /opt/HAC/RSF-1/etc/config for the logging definition
# line. This will be a line with either EVENT_NOTIFY or NEXENTA_NOTIFY
# as the first keyword, followed by a string identifying the
# programme, eg. NEXENTA_NOTIFY "/opt/HAC/RSF-1/bin/nexenta_event_notifier"
# Rename this programme to something else, eg.
# mv "/opt/HAC/RSF-1/bin/nexenta_event_notifier" \
#    "/opt/HAC/RSF-1/bin/real_event_notifier"
# and edit the following line to contain the new programme name
real_event_notifier="/opt/HAC/RSF-1/bin/real_event_notifier"

# Finally put this script as edited in place of the original event
# notifier referenced in the config file.

# A filename globbing style pattern match with no external programme calls.
# Usage: match "string" "pattern"  # Is true for a match, false if not
match()
{
    case "$1" in
        $2) return 0 ;;
    esac
    return 1
}

match "$*" "*RSF_HEARTBEAT*type=disc*" && exit 0
exec "$real_event_notifier" "$@"
