File: cron-disk.test

package info (click to toggle)
zeekctl 2.2.0%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,544 kB
  • sloc: python: 5,639; sh: 1,374; makefile: 71; awk: 24
file content (85 lines) | stat: -rw-r--r-- 1,851 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# 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