Skip to content

Commit

Permalink
Change delimiter for ZED email scripts
Browse files Browse the repository at this point in the history
When the ZED_EMAIL_INTERVAL_SECS="3600" option is set in zed.rc
configuration file then notification emails should be rate limited.

Rate limiting is accomplished by maintaining a colon delimited state
file which includes the device name.  Unfortunately there are valid
device names which include a colon and therefore prevent the rate
limiting for working properly.  For this reason the delimiter has
been changed to a semi-colon.

Signed-off-by: louwrentius <louwrentius@gmail.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Chris Dunlap <cdunlap@llnl.gov>
Closes openzfs#2645
  • Loading branch information
louwrentius authored and behlendorf committed Sep 2, 2014
1 parent 76c3a61 commit bcd9624
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions cmd/zed/zed.d/data-email.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# 4: unsupported event class
# 5: internal error
# State File Format:
# POOL:TIME_OF_LAST_EMAIL
# POOL;TIME_OF_LAST_EMAIL
#
test -f "${ZED_SCRIPT_DIR}/zed.rc" && . "${ZED_SCRIPT_DIR}/zed.rc"

Expand Down Expand Up @@ -47,7 +47,7 @@ flock -x 8

# Query state for last time email was sent for this pool.
TIME_NOW=`date +%s`
TIME_LAST=`egrep "^${ZEVENT_POOL}:" "${STATEFILE}" 2>/dev/null | cut -d: -f2`
TIME_LAST=`egrep "^${ZEVENT_POOL};" "${STATEFILE}" 2>/dev/null | cut -d ";" -f2`
if test -n "${TIME_LAST}"; then
TIME_DELTA=`expr "${TIME_NOW}" - "${TIME_LAST}"`
if test "${TIME_DELTA}" -lt "${ZED_EMAIL_INTERVAL_SECS:=3600}"; then
Expand All @@ -67,8 +67,8 @@ EOF
MAIL_STATUS=$?

# Update state.
egrep -v "^${ZEVENT_POOL}:" "${STATEFILE}" 2>/dev/null > "${STATEFILE}.$$"
echo "${ZEVENT_POOL}:${TIME_NOW}" >> "${STATEFILE}.$$"
egrep -v "^${ZEVENT_POOL};" "${STATEFILE}" 2>/dev/null > "${STATEFILE}.$$"
echo "${ZEVENT_POOL};${TIME_NOW}" >> "${STATEFILE}.$$"
mv -f "${STATEFILE}.$$" "${STATEFILE}"

if test "${MAIL_STATUS}" -ne 0; then
Expand Down
10 changes: 5 additions & 5 deletions cmd/zed/zed.d/io-email.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# 4: unsupported event class
# 5: internal error
# State File Format:
# POOL:VDEV_PATH:TIME_OF_LAST_EMAIL
# POOL;VDEV_PATH;TIME_OF_LAST_EMAIL
#
test -f "${ZED_SCRIPT_DIR}/zed.rc" && . "${ZED_SCRIPT_DIR}/zed.rc"

Expand Down Expand Up @@ -49,8 +49,8 @@ flock -x 8

# Query state for last time email was sent for this pool/vdev.
TIME_NOW=`date +%s`
TIME_LAST=`egrep "^${ZEVENT_POOL}:${ZEVENT_VDEV_PATH}:" "${STATEFILE}" \
2>/dev/null | cut -d: -f3`
TIME_LAST=`egrep "^${ZEVENT_POOL};${ZEVENT_VDEV_PATH};" "${STATEFILE}" \
2>/dev/null | cut -d ";" -f3`
if test -n "${TIME_LAST}"; then
TIME_DELTA=`expr "${TIME_NOW}" - "${TIME_LAST}"`
if test "${TIME_DELTA}" -lt "${ZED_EMAIL_INTERVAL_SECS:=3600}"; then
Expand All @@ -71,9 +71,9 @@ EOF
MAIL_STATUS=$?

# Update state.
egrep -v "^${ZEVENT_POOL}:${ZEVENT_VDEV_PATH}:" "${STATEFILE}" \
egrep -v "^${ZEVENT_POOL};${ZEVENT_VDEV_PATH};" "${STATEFILE}" \
2>/dev/null > "${STATEFILE}.$$"
echo "${ZEVENT_POOL}:${ZEVENT_VDEV_PATH}:${TIME_NOW}" >> "${STATEFILE}.$$"
echo "${ZEVENT_POOL};${ZEVENT_VDEV_PATH};${TIME_NOW}" >> "${STATEFILE}.$$"
mv -f "${STATEFILE}.$$" "${STATEFILE}"

if test "${MAIL_STATUS}" -ne 0; then
Expand Down

0 comments on commit bcd9624

Please sign in to comment.