+# -----------------------------------------------------------------------------
+# filter recipients based on the criticality of each
+
+filter_recipient_by_criticality() {
+ local method="${1}" x="${2}" r s
+ shift
+
+ r="${x/|*/}"
+ s="${x/*|/}"
+
+ # no severity filtering for this person
+ [ "${r}" = "${s}" ] && return 0
+
+ # the severity is invalid
+ s="${s^^}"
+ [ "${s}" != "CRITICAL" ] && return 0
+
+ # the new or the old status matches the severity
+ if [ "${s}" = "${status}" -o "${s}" = "${old_status}" ]
+ then
+ [ ! -d "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}" ] && \
+ mkdir -p "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}"
+
+ # we need to keep track of the notifications we sent
+ # so that the same user will receive the recovery
+ # even if old_status does not match the required severity
+ touch "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}"
+ return 0
+ fi
+
+ # it is a cleared alarm we have sent notification for
+ if [ "${status}" != "WARNING" -a "${status}" != "CRITICAL" -a -f "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}" ]
+ then
+ rm "${NETDATA_CACHE_DIR}/alarm-notify/${method}/${r}/${alarm_id}"
+ return 0
+ fi
+
+ return 1
+}
+