blob: d0935495a49ade7c00ce26d154c7c12f1f69ba08 (
plain)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
{
config,
...
}:
{
system.newsyslog = {
enable = true;
files = {
myapp = [
{
logfilename = "/var/log/myapp.log";
owner = "myuser";
group = "wheel";
mode = "644";
count = 7;
size = "4096";
flags = [
"Z"
"C"
];
pidFile = "/var/run/myapp.pid";
signal = "USR1";
}
{
logfilename = "/var/log/myapp-debug.log";
owner = "myuser";
mode = "600";
count = 3;
size = "2048";
flags = [ "Z" ];
}
];
system = [
{
logfilename = "/var/log/system.log";
mode = "644";
count = 5;
when = "@T00";
flags = [ "Z" ];
}
{
logfilename = "/var/log/mail.log";
group = "mail";
mode = "640";
count = 10;
size = "1024";
flags = [
"B"
"Z"
];
pidFile = "/var/run/syslogd.pid";
}
];
minimal = [
{
logfilename = "/tmp/test.log";
mode = "644";
count = 2;
size = "100K";
}
];
both-size-when = [
{
logfilename = "/var/log/both.log";
mode = "644";
count = 3;
size = "2048";
when = "@T12";
flags = [ "Z" ];
}
];
empty-flags = [
{
logfilename = "/var/log/empty-flags.log";
mode = "644";
count = 1;
size = "1024";
}
];
pidfile-empty-flags = [
{
logfilename = "/var/log/pidfile-empty-flags.log";
mode = "644";
count = 1;
size = "1024";
pidFile = "/var/run/pidfile-empty-flags.pid";
}
];
};
};
test = ''
set -e
check_pattern() {
local pattern="$1"
local file="$2"
echo "--> Checking for pattern: '$pattern'"
echo " in file: '$file'"
if grep --color=never -E "$pattern" "$file"; then
echo " +++ PASS: Pattern found."
echo
else
echo " --- FAIL: Pattern NOT found."
exit 1
fi
}
echo "checking newsyslog.d configuration files exist"
test -f ${config.out}/etc/newsyslog.d/myapp.conf
test -f ${config.out}/etc/newsyslog.d/system.conf
test -f ${config.out}/etc/newsyslog.d/minimal.conf
test -f ${config.out}/etc/newsyslog.d/both-size-when.conf
test -f ${config.out}/etc/newsyslog.d/empty-flags.conf
test -f ${config.out}/etc/newsyslog.d/pidfile-empty-flags.conf
echo
echo "checking file content patterns"
check_pattern "myuser:wheel.*644.*7.*4096.*\*.*ZC.*USR1" ${config.out}/etc/newsyslog.d/myapp.conf
check_pattern "myuser:.*600.*3.*2048.*\*.*Z" ${config.out}/etc/newsyslog.d/myapp.conf
check_pattern "system.log.*644.*5.*\*.*@T00.*Z" ${config.out}/etc/newsyslog.d/system.conf
check_pattern ":mail.*640.*10.*1024.*\*.*BZ" ${config.out}/etc/newsyslog.d/system.conf
check_pattern "test.log.*644.*2.*100K.*\*" ${config.out}/etc/newsyslog.d/minimal.conf
check_pattern "both.log.*644.*3.*2048.*@T12.*Z" ${config.out}/etc/newsyslog.d/both-size-when.conf
check_pattern "empty-flags.log.*644.*1.*1024.*\*" ${config.out}/etc/newsyslog.d/empty-flags.conf
check_pattern "pidfile-empty-flags.log.*644.*1.*1024.*\*.*-.*pidfile-empty-flags.pid" ${config.out}/etc/newsyslog.d/pidfile-empty-flags.conf
# Verify no colons in minimal.conf (no owner/group)
echo "--> Verifying no colons in minimal.conf"
if grep -v "^#" ${config.out}/etc/newsyslog.d/minimal.conf | grep -q ":"; then
echo " --- FAIL: minimal.conf should not contain colons"
exit 1
else
echo " +++ PASS: No colons found."
fi
# Verify group-only format
echo "--> Verifying group-only format in system.conf"
if ! grep -q ":mail" ${config.out}/etc/newsyslog.d/system.conf; then
echo " --- FAIL: Did not find group-only format ':mail'"
exit 1
else
echo " +++ PASS: Found group-only format."
fi
echo
echo "All tests passed successfully."
'';
}
|