Patrick Kelley 8fd444092b initial
2025-05-07 15:35:15 -04:00

86 lines
1.8 KiB
Plaintext

# Test that the zeekctl cron command sends an email warning on low disk free
# space only when the amount of free disk space crosses the threshold
# specified by the mindiskspace zeekctl option.
#
# @TEST-EXEC: bash %INPUT
. zeekctl-test-setup
while read line; do installfile $line; done << EOF
etc/zeekctl.cfg__test_sendmail
bin/df__diskfull --new
bin/sendmail__test --new
EOF
replaceprefix etc/zeekctl.cfg
# Check if a low disk space email was received. Return 0 if yes, and 1 if no.
check_email() {
email=$ZEEKCTL_INSTALL_PREFIX/sendmail.out
test ! -e $email && return 1
# Verify the contents of mail are correct (this should never fail).
grep -q "Disk space low on localhost:/dev/sda6" $email
rm $email
}
zeekctl install
# Verify the default value of mindiskspace
zeekctl config | sed 's/ //g' > tmp
grep -q mindiskspace=5 tmp
################
# Test with lots of free disk space (no email warning)
zeekctl cron
! check_email
################
# Test with a disk that is almost full (email warning)
export ZEEKCTL_TEST_DISK_FULL=1
zeekctl cron
check_email
################
# Test again with same disk usage as before (no duplicate warning is sent)
zeekctl cron
! check_email
################
# Test with lots of free disk space (no email warning)
ZEEKCTL_TEST_DISK_FULL=
zeekctl cron
! check_email
################
# Test with a disk that is almost full (another warning is sent)
ZEEKCTL_TEST_DISK_FULL=1
zeekctl cron
check_email
################
# Test with lots of free disk space, but different mindiskspace (email warning)
# Remove previous free disk space records (otherwise we won't get an email)
rm $ZEEKCTL_INSTALL_PREFIX/spool/state.db
# Update configuration
echo "mindiskspace=50" >> $ZEEKCTL_INSTALL_PREFIX/etc/zeekctl.cfg
zeekctl install
ZEEKCTL_TEST_DISK_FULL=
zeekctl cron
check_email