Skip to content

Commit 956f2b6

Browse files
committed
test: new syslog test to verify property based filtering
Signed-off-by: Joachim Wiberg <[email protected]>
1 parent ed6db59 commit 956f2b6

File tree

6 files changed

+197
-0
lines changed

6 files changed

+197
-0
lines changed

test/case/ietf_syslog/all.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@
1313

1414
- name: Syslog Hostname Filtering
1515
case: hostname_filter/test.py
16+
17+
- name: Syslog Property Filtering
18+
case: property_filter/test.py
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test.adoc
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
=== Syslog Property Filtering
2+
3+
ifdef::topdoc[:imagesdir: {topdoc}../../test/case/ietf_syslog/property_filter]
4+
5+
==== Description
6+
7+
Verify property-filter feature: filtering syslog messages based on various
8+
message properties with different operators, case-insensitivity, and negation.
9+
10+
==== Topology
11+
12+
image::topology.svg[Syslog Property Filtering topology, align=center, scaledwidth=75%]
13+
14+
==== Sequence
15+
16+
. Set up topology and attach to target DUT
17+
. Clean up old log files
18+
. Configure syslog with property filters
19+
. Send test messages
20+
. Verify myapp log contains only myapp messages
21+
. Verify not-error log excludes ERROR messages
22+
. Verify case-test log matches case-insensitive 'warning'
23+
. Verify baseline log contains all messages
24+
25+
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#!/usr/bin/env python3
2+
"""Syslog Property Filtering
3+
4+
Verify property-filter feature: filtering syslog messages based on various
5+
message properties with different operators, case-insensitivity, and negation.
6+
7+
"""
8+
9+
import infamy
10+
import time
11+
12+
TEST_MESSAGES = [
13+
("myapp", "Application startup"),
14+
("myapp", "Processing request"),
15+
("otherapp", "Different program"),
16+
("test", "ERROR: Connection failed"),
17+
("test", "INFO: Normal message"),
18+
("test", "WARNING: Check config"),
19+
("test", "Warning: lowercase"),
20+
]
21+
22+
with infamy.Test() as test:
23+
with test.step("Set up topology and attach to target DUT"):
24+
env = infamy.Env()
25+
target = env.attach("target", "mgmt")
26+
tgtssh = env.attach("target", "mgmt", "ssh")
27+
28+
with test.step("Clean up old log files"):
29+
tgtssh.runsh("sudo rm -f /var/log/{myapp,not-error,case-test,baseline}")
30+
31+
with test.step("Configure syslog with property filters"):
32+
target.put_config_dicts({
33+
"ietf-syslog": {
34+
"syslog": {
35+
"actions": {
36+
"file": {
37+
"log-file": [{
38+
"name": "file:myapp",
39+
"infix-syslog:property-filter": {
40+
"property": "programname",
41+
"operator": "isequal",
42+
"value": "myapp"
43+
},
44+
"facility-filter": {
45+
"facility-list": [{
46+
"facility": "all",
47+
"severity": "info"
48+
}]
49+
}
50+
}, {
51+
"name": "file:not-error",
52+
"infix-syslog:property-filter": {
53+
"property": "msg",
54+
"operator": "contains",
55+
"value": "ERROR",
56+
"negate": True
57+
},
58+
"facility-filter": {
59+
"facility-list": [{
60+
"facility": "all",
61+
"severity": "info"
62+
}]
63+
}
64+
}, {
65+
"name": "file:case-test",
66+
"infix-syslog:property-filter": {
67+
"property": "msg",
68+
"operator": "contains",
69+
"value": "warning",
70+
"case-insensitive": True
71+
},
72+
"facility-filter": {
73+
"facility-list": [{
74+
"facility": "all",
75+
"severity": "info"
76+
}]
77+
}
78+
}, {
79+
"name": "file:baseline",
80+
"facility-filter": {
81+
"facility-list": [{
82+
"facility": "all",
83+
"severity": "info"
84+
}]
85+
}
86+
}]
87+
}
88+
}
89+
}
90+
}
91+
})
92+
93+
time.sleep(2)
94+
95+
with test.step("Send test messages"):
96+
for tag, msg in TEST_MESSAGES:
97+
tgtssh.runsh(f"logger -t {tag} -p daemon.info '{msg}'")
98+
time.sleep(1)
99+
100+
with test.step("Verify myapp log contains only myapp messages"):
101+
rc = tgtssh.runsh("grep -c 'myapp' /var/log/myapp 2>/dev/null")
102+
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
103+
if count != 2:
104+
test.fail(f"Expected 2 myapp messages in /var/log/myapp, got {count}")
105+
106+
rc = tgtssh.runsh("grep -c 'otherapp' /var/log/myapp 2>/dev/null")
107+
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
108+
if count != 0:
109+
test.fail(f"Expected 0 otherapp messages in /var/log/myapp, got {count}")
110+
111+
with test.step("Verify not-error log excludes ERROR messages"):
112+
rc = tgtssh.runsh("grep -c 'test' /var/log/not-error 2>/dev/null")
113+
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
114+
if count != 3:
115+
test.fail(f"Expected 3 non-ERROR messages in /var/log/not-error, got {count}")
116+
117+
rc = tgtssh.runsh("grep -c 'ERROR' /var/log/not-error 2>/dev/null")
118+
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
119+
if count != 0:
120+
test.fail(f"Expected 0 ERROR messages in /var/log/not-error, got {count}")
121+
122+
with test.step("Verify case-test log matches case-insensitive 'warning'"):
123+
rc = tgtssh.runsh("grep -c 'WARNING\\|Warning' /var/log/case-test 2>/dev/null")
124+
count = int(rc.stdout.strip()) if rc.returncode == 0 else 0
125+
if count != 2:
126+
test.fail(f"Expected 2 warning messages in /var/log/case-test, got {count}")
127+
128+
with test.step("Verify baseline log contains all messages"):
129+
for tag, msg in TEST_MESSAGES:
130+
rc = tgtssh.runsh(f"grep -q '{msg}' /var/log/baseline 2>/dev/null")
131+
if rc.returncode != 0:
132+
test.fail(f"Expected message '{msg}' not found in /var/log/baseline")
133+
134+
test.succeed()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../infamy/topologies/1x1.dot
Lines changed: 33 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)