xref: /freebsd/sys/contrib/openzfs/cmd/zed/zed.d/all-syslog.sh (revision dd41de95a84d979615a2ef11df6850622bf6184e)
1#!/bin/sh
2#
3# Copyright (C) 2013-2014 Lawrence Livermore National Security, LLC.
4# Copyright (c) 2020 by Delphix. All rights reserved.
5#
6
7#
8# Log the zevent via syslog.
9#
10
11[ -f "${ZED_ZEDLET_DIR}/zed.rc" ] && . "${ZED_ZEDLET_DIR}/zed.rc"
12. "${ZED_ZEDLET_DIR}/zed-functions.sh"
13
14zed_exit_if_ignoring_this_event
15
16# build a string of name=value pairs for this event
17msg="eid=${ZEVENT_EID} class=${ZEVENT_SUBCLASS}"
18
19if [ "${ZED_SYSLOG_DISPLAY_GUIDS}" = "1" ]; then
20    [ -n "${ZEVENT_POOL_GUID}" ] && msg="${msg} pool_guid=${ZEVENT_POOL_GUID}"
21    [ -n "${ZEVENT_VDEV_GUID}" ] && msg="${msg} vdev_guid=${ZEVENT_VDEV_GUID}"
22else
23    [ -n "${ZEVENT_POOL}" ] && msg="${msg} pool='${ZEVENT_POOL}'"
24    [ -n "${ZEVENT_VDEV_PATH}" ] && msg="${msg} vdev=$(basename "${ZEVENT_VDEV_PATH}")"
25fi
26
27# log pool state if state is anything other than 'ACTIVE'
28[ -n "${ZEVENT_POOL_STATE_STR}" ] && [ "$ZEVENT_POOL_STATE" -ne 0 ] && \
29    msg="${msg} pool_state=${ZEVENT_POOL_STATE_STR}"
30
31# Log the following payload nvpairs if they are present
32[ -n "${ZEVENT_VDEV_STATE_STR}" ]  && msg="${msg} vdev_state=${ZEVENT_VDEV_STATE_STR}"
33[ -n "${ZEVENT_CKSUM_ALGORITHM}" ] && msg="${msg} algorithm=${ZEVENT_CKSUM_ALGORITHM}"
34[ -n "${ZEVENT_ZIO_SIZE}" ]        && msg="${msg} size=${ZEVENT_ZIO_SIZE}"
35[ -n "${ZEVENT_ZIO_OFFSET}" ]      && msg="${msg} offset=${ZEVENT_ZIO_OFFSET}"
36[ -n "${ZEVENT_ZIO_PRIORITY}" ]    && msg="${msg} priority=${ZEVENT_ZIO_PRIORITY}"
37[ -n "${ZEVENT_ZIO_ERR}" ]         && msg="${msg} err=${ZEVENT_ZIO_ERR}"
38[ -n "${ZEVENT_ZIO_FLAGS}" ]       && msg="${msg} flags=$(printf '0x%x' "${ZEVENT_ZIO_FLAGS}")"
39
40# log delays that are >= 10 milisec
41[ -n "${ZEVENT_ZIO_DELAY}" ] && [ "$ZEVENT_ZIO_DELAY" -gt 10000000 ] && \
42    msg="${msg} delay=$((ZEVENT_ZIO_DELAY / 1000000))ms"
43
44# list the bookmark data together
45[ -n "${ZEVENT_ZIO_OBJSET}" ] && \
46    msg="${msg} bookmark=${ZEVENT_ZIO_OBJSET}:${ZEVENT_ZIO_OBJECT}:${ZEVENT_ZIO_LEVEL}:${ZEVENT_ZIO_BLKID}"
47
48zed_log_msg "${msg}"
49
50exit 0
51