Skip to content

Commit cf158cf

Browse files
hsekowski-splunkArtem Rys
authored andcommitted
feat: allow *.xml (beside *.log) files as sample input files (#550)
1 parent 166f846 commit cf158cf

File tree

5 files changed

+77
-8
lines changed

5 files changed

+77
-8
lines changed

pytest_splunk_addon/standard_lib/event_ingestors/requirement_event_ingester.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def get_events(self):
110110
if os.path.isdir(req_file_path):
111111
for file1 in os.listdir(req_file_path):
112112
filename = os.path.join(req_file_path, file1)
113-
if filename.endswith(".log"):
113+
if filename.endswith(".log") or filename.endswith(".xml"):
114114
if self.check_xml_format(filename):
115115
root = self.get_root(filename)
116116
for event_tag in root.iter("event"):
@@ -213,7 +213,7 @@ def get_events(self):
213213
)
214214
else:
215215
LOGGER.error(
216-
"Requirement event ingestion failure: Invalid file format not .log {}".format(
216+
"Requirement event ingestion failure: Invalid file format not .log or .xml {}".format(
217217
filename
218218
)
219219
)

pytest_splunk_addon/standard_lib/requirement_tests/test_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def generate_cim_req_params(self):
118118
for file1 in os.listdir(req_file_path):
119119
filename = os.path.join(req_file_path, file1)
120120
LOGGER.info(filename)
121-
if filename.endswith(".log"):
121+
if filename.endswith(".log") or filename.endswith(".xml"):
122122
try:
123123
self.check_xml_format(filename)
124124
except Exception:
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0"?>
2+
<device>
3+
<vendor>Juniper</vendor>
4+
<product>JunOS</product>
5+
<version id="16.2R1" />
6+
<version id="17.1R1" />
7+
<version id="17.2R1" />
8+
<event code="" name="RT_FLOW_SESSION_CREATE" format="syslog">
9+
<transport type="syslog" />
10+
<source>
11+
<jira id="ADDON-25170"/>
12+
<comment>Got this event form Juniper document.</comment>
13+
</source>
14+
<raw>
15+
<![CDATA[<111> 2020-02-12T03:27:09+10:00 sample.dvc RT_FLOW: RT_FLOW_SESSION_CREATE: session created 1.1.1.1/34667->10.0.0.1/5048 0x0 junos-http 1.1.1.2/34667->10.0.0.2/5048 0x0 sample_src_rule_type sample_src_rule_name sample_dst_rule_type sample_dest_rule_n**ame 6 1660(global) SAMPLE-SERVER-ZONE DUMMY_ZONE 113256 user2(admin) gg-0/0/0.1 SNMP DUMMY_APP UNKNOWN]]>
16+
</raw>
17+
<cim>
18+
<models>
19+
<model>Network Traffic</model>
20+
</models>
21+
<cim_fields>
22+
<field name="action" value="allowed"/>
23+
<field name="dest" value="10.0.0.1"/>
24+
<field name="dest_ip" value="10.0.0.1"/>
25+
<field name="dest_port" value="5048"/>
26+
<field name="dest_zone" value="DUMMY_ZONE"/>
27+
<field name="dvc" value="sample.dvc"/>
28+
<field name="rule" value="sample_src_rule_name sample_dest_rule_n**ame 1660(global)"/>
29+
<field name="session_id" value="113256"/>
30+
<field name="src" value="1.1.1.1"/>
31+
<field name="src_ip" value="1.1.1.1"/>
32+
<field name="src_port" value="34667"/>
33+
<field name="src_zone" value="SAMPLE-SERVER-ZONE"/>
34+
<field name="src_interface" value="gg-0/0/0.1"/>
35+
<field name="user" value="user2"/>
36+
<field name="app" value="SNMP DUMMY_APP"/>
37+
<field name="transport" value="tcp"/>
38+
<field name="protocol" value="ip"/>
39+
<field name="vendor_product" value="Incorrect vendor product"/>
40+
</cim_fields>
41+
<missing_recommended_fields>
42+
<field>bytes</field>
43+
<field>bytes_in</field>
44+
<field>bytes_out</field>
45+
</missing_recommended_fields>
46+
<exceptions>
47+
<field name="vendor_product" value="Incorrect vendor product" reason="testing exceptions"/>
48+
</exceptions>
49+
</cim>
50+
<test></test>
51+
</event>
52+
</device>

tests/test_splunk_addon.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,8 @@ def empty_method():
551551
result.stdout.fnmatch_lines_random(
552552
constants.TA_REQUIREMENTS_PASSED + constants.TA_REQUIREMENTS_FAILED
553553
)
554-
result.assert_outcomes(passed=len(constants.TA_REQUIREMENTS_PASSED), failed=1)
554+
result.assert_outcomes(passed=2, failed=1)
555+
# passed=2 as the successful data comes from 2 sources (log & xml)
555556

556557
# make sure that that we get a non '0' exit code for the testsuite as it contains failure
557558
assert result.ret != 0

tests/unit/tests_standard_lib/test_requirement_tests/test_test_generator.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,27 @@ def test_extract_params():
133133
["requirement.xml"],
134134
[True],
135135
["syslog"],
136-
{"event": ["event_1", "event_2"]},
137-
[["model_1:dataset_1", "model_2:dataset_2"], ["model_3:dataset_3"]],
138-
["event_name_2"],
136+
{"event": ["<34>Oct 11 22:14:15 machine1 pr1:event_1"]},
137+
[["model_1:dataset_1", "model_2:dataset_2"]],
138+
["event_name_1"],
139139
[{"field1": "value1", "field2": "value2"}, {"field3": "value3"}],
140-
[],
140+
[
141+
(
142+
{
143+
"model_list": [
144+
("model_1", "dataset_1", ""),
145+
("model_2", "dataset_2", ""),
146+
],
147+
"escaped_event": "event_1",
148+
"exceptions_dict": {"field3": "value3"},
149+
"Key_value_dict": {"field1": "value1", "field2": "value2"},
150+
"modinput_params": None,
151+
"transport_type": "syslog",
152+
},
153+
"model_1:dataset_1 "
154+
"model_2:dataset_2::fake_path/requirement.xml::event_no::1::event_name::event_name_1",
155+
),
156+
],
141157
),
142158
(
143159
["req.log"],

0 commit comments

Comments
 (0)