1#!/bin/ksh -p 2# 3# CDDL HEADER START 4# 5# The contents of this file are subject to the terms of the 6# Common Development and Distribution License (the "License"). 7# You may not use this file except in compliance with the License. 8# 9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10# or https://opensource.org/licenses/CDDL-1.0. 11# See the License for the specific language governing permissions 12# and limitations under the License. 13# 14# When distributing Covered Code, include this CDDL HEADER in each 15# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16# If applicable, add the following below this CDDL HEADER, with the 17# fields enclosed by brackets "[]" replaced with your own identifying 18# information: Portions Copyright [yyyy] [name of copyright owner] 19# 20# CDDL HEADER END 21# 22 23# 24# Copyright (c) 2018 by Lawrence Livermore National Security, LLC. 25# Use is subject to license terms. 26# 27 28# DESCRIPTION: 29# Verify zed.rc ZED_SYSLOG_SUBCLASS_INCLUDE/EXCLUDE event filtering works. 30# 31# STRATEGY: 32# 1. Execute zpool sub-commands on a pool. 33# 2. Test different combinations of ZED_SYSLOG_SUBCLASS_INCLUDE filtering. 34# 3. Execute zpool sub-commands on a pool. 35# 4. Test different combinations of ZED_SYSLOG_SUBCLASS_EXCLUDE filtering. 36 37. $STF_SUITE/include/libtest.shlib 38. $STF_SUITE/tests/functional/events/events_common.kshlib 39 40verify_runnable "both" 41 42function cleanup 43{ 44 log_must zed_stop 45 zed_rc_restore $zedrc_backup 46} 47 48log_assert "Verify zpool sub-commands generate expected events" 49log_onexit cleanup 50 51log_must zpool events -c 52log_must zed_stop 53log_must zed_start 54 55# Backup our zed.rc 56zedrc_backup=$(zed_rc_backup) 57 58log_note "Include a single event type" 59zed_rc_set ZED_SYSLOG_SUBCLASS_INCLUDE history_event 60run_and_verify -p "$TESTPOOL" -e "sysevent.fs.zfs.history_event" \ 61 "zfs set compression=off $TESTPOOL/$TESTFS" 62 63log_note "Include a single event type with wildcards" 64zed_rc_set ZED_SYSLOG_SUBCLASS_INCLUDE '*history_event*' 65run_and_verify -p "$TESTPOOL" -e "sysevent.fs.zfs.history_event" \ 66 "zfs set compression=off $TESTPOOL/$TESTFS" 67 68log_note "Test a filter of a non-match and a match" 69zed_rc_set ZED_SYSLOG_SUBCLASS_INCLUDE 'foobar|*history_event*' 70run_and_verify -p "$TESTPOOL" -e "sysevent.fs.zfs.history_event" \ 71 "zfs set compression=off $TESTPOOL/$TESTFS" 72 73log_note "Include multiple events" 74zed_rc_set ZED_SYSLOG_SUBCLASS_INCLUDE 'scrub_start|scrub_finish' 75run_and_verify -p "$TESTPOOL" -e "sysevent.fs.zfs.scrub_start" \ 76 -e "sysevent.fs.zfs.scrub_finish" \ 77 "zpool scrub $TESTPOOL && wait_scrubbed $TESTPOOL" 78 79# We can't use run_and_verify() for exclusions, so run the rest of the tests 80# manually. 81log_note "Test one exclusion" 82zed_rc_set ZED_SYSLOG_SUBCLASS_EXCLUDE 'history_event' 83truncate -s 0 $ZED_DEBUG_LOG 84log_must zfs set compression=off $TESTPOOL/$TESTFS 85log_must file_wait $ZED_DEBUG_LOG 3 86log_mustnot grep -q history_event $ZED_DEBUG_LOG 87 88log_note "Test one exclusion with wildcards" 89zed_rc_set ZED_SYSLOG_SUBCLASS_EXCLUDE '*history_event*' 90truncate -s 0 $ZED_DEBUG_LOG 91log_must zfs set compression=off $TESTPOOL/$TESTFS 92log_must file_wait $ZED_DEBUG_LOG 3 93log_mustnot grep -q history_event $ZED_DEBUG_LOG 94 95log_note "Test one inclusion and one exclusion" 96zed_rc_set ZED_SYSLOG_SUBCLASS_INCLUDE 'scrub_start' 97zed_rc_set ZED_SYSLOG_SUBCLASS_EXCLUDE 'scrub_finish' 98truncate -s 0 $ZED_DEBUG_LOG 99zpool scrub $TESTPOOL 100wait_scrubbed $TESTPOOL 101log_must file_wait $ZED_DEBUG_LOG 3 102log_must grep -q scrub_start $ZED_DEBUG_LOG 103log_mustnot grep -q scrub_finish $ZED_DEBUG_LOG 104 105log_pass "zed.rc event filtering works correctly." 106