Skip to content

Commit 6eb8ca3

Browse files
committed
start of 3164 testing
1 parent fb5d52e commit 6eb8ca3

3 files changed

Lines changed: 150 additions & 1 deletion

File tree

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[flake8]
22
application-import-names = simple_syslog,tests
33
select = B,B9,BLK,C,D,DAR,E,F,I,S,W
4-
ignore = E203,W503,E501,D100,B024
4+
ignore = E203,W503,E501,D100,B024,B950
55
max-line-length = 88
66
max-complexity = 10
77
docstring-convention = google

tests/conftest.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@
5454
+ " State changed from starting to up"
5555
)
5656

57+
OCTET_MESSAGE_3164 = (
58+
"83 <181>Aug 6 17:26:31 10.34.84.145 Aug 7 00:45:43 stage-pdp01"
59+
+ " CISE_Profiler 0000024855 1 0 2014-08-07 00:45:43.741 -07:00 0000288542 80002 INFO Profiler: Profiler"
60+
+ " EndPoint profiling event occurred, ConfigVersionId=113, EndpointCertainityMetric=10,"
61+
+ " EndpointIPAddress=10.56.111.14, EndpointMacAddress=3C:97:0E:C3:F8:F1, EndpointMatchedPolicy=Nortel-Device,"
62+
+ " EndpointNADAddress=10.56.72.127, EndpointOUI=Wistron InfoComm(Kunshan)Co.\\,Ltd.,"
63+
+ " EndpointPolicy=Nortel-Device, EndpointProperty=StaticAssignment=false\\,PostureApplicable=Yes\\,"
64+
+ "PolicyVersion=402\\,IdentityGroupID=0c1d9270-68a6-11e1-bc72-0050568e013c\\,Total Certainty Factor=10\\,"
65+
+ "BYODRegistration=Unknown\\,FeedService=false\\,EndPointPolicyID=49054ed0-68a6-11e1-bc72-0050568e013c\\,"
66+
+ "FirstCollection=1407397543718\\,MatchedPolicyID=49054ed0-68a6-11e1-bc72-0050568e013c\\,TimeToProfile=19\\,"
67+
+ "StaticGroupAssignment=false\\,NmapSubnetScanID=0\\,DeviceRegistrationStatus=NotRegistered\\,PortalUser=,"
68+
+ " EndpointSourceEvent=SNMPQuery Probe, EndpointIdentityGroup=Profiled, ProfilerServer=stage-pdp01.cisco.com"
69+
)
70+
5771
SYSLOG_LINE_ALL = (
5872
"<14>1 2014-06-20T09:14:07+00:00 loggregator"
5973
+ " d0602076-b14a-4c55-852a-981e7afeed38 DEA MSG-01"
@@ -236,6 +250,16 @@ def octet_message() -> str:
236250
return OCTET_MESSAGE
237251

238252

253+
@pytest.fixture
254+
def octet_message_3164() -> str:
255+
"""Octet message.
256+
257+
Returns:
258+
return octet message
259+
"""
260+
return OCTET_MESSAGE_3164
261+
262+
239263
@pytest.fixture
240264
def syslog_line_all() -> str:
241265
"""ALL options message.

tests/test_3164_parser.py

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Copyright 2022-2024 simple-syslog authors
2+
# All rights reserved.
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from io import TextIOBase
16+
from typing import Generator, List
17+
18+
from simple_syslog.builder import DefaultBuilder
19+
from simple_syslog.data import SyslogDataSet
20+
from simple_syslog.keys import (
21+
DefaultKeyProvider,
22+
SyslogFieldKey,
23+
SyslogFieldKeyDefaults,
24+
)
25+
from simple_syslog.parser import AbstractSyslogParser, Rfc3164SyslogParser
26+
from simple_syslog.specification import SyslogSpecification
27+
28+
expectedMessageOne = (
29+
"CISE_RADIUS_Accounting 0018032501 1 0 2018-09-14 10:54:09.095"
30+
" +10:00 0221114759 3002 NOTICE Radius-Accounting: RADIUS Accounting watchdog update, ConfigVersionId=73, "
31+
"Device IP Address=00.00.000.0, RequestLatency=2, NetworkDeviceName=foo, "
32+
"User-Name=ACCOUNT-01\\\\\\\\D622322, NAS-IP-Address=00.00.000.0, NAS-Port=50742, "
33+
"Framed-IP-Address=00.00.000.000, Class=CACS:0A3D720400016DBFE530A22E:lzpqrst/323409315/14578982, "
34+
"Called-Station-ID=00-CA-E5-B1-21-AA, Calling-Station-ID=54-E1-AD-A1-27-72, Acct-Status-Type=Interim-Update, "
35+
"Acct-Delay-Time=10, Acct-Input-Octets=379294, Acct-Output-Octets=1053336, Acct-Session-Id=00025EB8, "
36+
"Acct-Input-Packets=1657, Acct-Output-Packets=2018, Event-Timestamp=1536886439, NAS-Port-Type=Ethernet, "
37+
"NAS-Port-Id=GigabitEthernet7/0/42, cisco-av-pair=dc-profile-name=Microsoft-Workstation, "
38+
"cisco-av-pair=dc-device-name=MSFT 5.0, cisco-av-pair=dc-device-class-tag=Workstation:Microsoft-Workstation, "
39+
"cisco-av-pair=dc-certainty-metric=10, "
40+
"cisco-av-pair=dc-opaque=\\000\\000\\000\\002\\000\\000\\000\\001\\000\\000\\000\\000, "
41+
"cisco-av-pair=dc-protocol-map=9, "
42+
"cisco-av-pair=dhcp-option=pad="
43+
"1b:2e:01:08:ff:2e:01:08:ff:0a:90:84:51:0a:2c:08:0a:d0:52:31:0a:d0:5a:1b:2e:01:08:ff:2e:01:08:ff:79:f9:2b:"
44+
"ff:43:17:73:6d:73:62:6f:6f:74:5c:78:38:36:5c:77:64:73:6e:62:70:2e:63:6f:6d:00:ff:6f:6d:00:ff:00:00:00:00:00:"
45+
"00:00:00:00:00:00:00:00:00:00:00:00:00:00:22:23:54:00:00, cisco-av-pair=dhcp-option=00:ff:00:00, "
46+
"cisco-av-pair=dhcp-option=dhcp-parameter-request-list="
47+
"1\\\\, 15\\\\, 3\\\\, 6\\\\, 44\\\\, 46\\\\, 47\\\\, 31\\\\, 33\\\\, 121\\\\, 249\\\\, 43\\\\, 252,"
48+
" cisco-av-pair=dhcp-option=dhcp-class-identifier=MSFT 5.0, cisco-av-pair=dhcp-option=host-name=W00000PC0R1JC3,"
49+
" cisco-av-pair=dhcp-option=dhcp-client-identifier=01:54:e1:ad:a1:27:72,"
50+
" cisco-av-pair=dhcp-option=dhcp-message-type=8, cisco-av-pair=audit-session-id=0A3D720400016DBFE530A22E,"
51+
" cisco-av-pair=method=dot1x, AcsSessionID=lzpqrst/323409315/14579377, SelectedAccessService=PEAP_MAB,"
52+
" Step=11004, Step=11017, Step=15049, Step=15008, Step=22094, Step=11005, NetworkDeviceGroups=Stage#Deployment"
53+
" Type#Secure Mode D2, NetworkDeviceGroups=Location#All Locations#Placename#500 Exhibition St"
54+
" CompanyPlace#Level 18, NetworkDeviceGroups=Device Type#All Device Types#Access Switch#Catalyst 3850,"
55+
" NetworkDeviceGroups=Location Type#Location Type#Office, CPMSessionID=0A3D720400016DBFE530A22E,"
56+
" Stage=Stage#Deployment Type#Secure Mode D2, Location=Location#All Locations#Placename#500 Exhibition St"
57+
" CompanyPlace#Level 18, Device Type=Device Type#All Device Types#Access Switch#Catalyst 3850, Network Device"
58+
" Profile=Cisco, Location Type=Location Type#Location Type#Office"
59+
)
60+
expectedHostNameOne = "lzpqrst-admin.in.mycompany.com.lg"
61+
expectedPriOne = "181"
62+
expectedTimestampOne = "2018-09-14T00:54:09+00:00"
63+
expectedFacilityOne = "22"
64+
expectedSeverityOne = "5"
65+
66+
67+
def test_parse_octet_line(octet_message_3164) -> None:
68+
"""Test that we can parse octet prefixed line."""
69+
builder = DefaultBuilder(
70+
specification=SyslogSpecification.RFC_6587_3164,
71+
key_provider=DefaultKeyProvider(),
72+
nil_policy=None,
73+
allowed_deviations=None,
74+
)
75+
parser = Rfc3164SyslogParser(builder, SyslogSpecification.RFC_6587_3164)
76+
syslog_data: SyslogDataSet = parser.parse(octet_message_3164)
77+
assert syslog_data
78+
79+
80+
def test_parse_line(file_of_3164_single_ise_txt) -> None:
81+
"""Test parsing regular line."""
82+
builder = DefaultBuilder(
83+
specification=SyslogSpecification.RFC_3164,
84+
key_provider=DefaultKeyProvider(),
85+
nil_policy=None,
86+
allowed_deviations=None,
87+
)
88+
parser = Rfc3164SyslogParser(builder)
89+
data_sets: List[SyslogDataSet] = []
90+
with file_of_3164_single_ise_txt.open("r") as f:
91+
g = generate_from_file(f, parser)
92+
for ds in g:
93+
data_sets.append(ds)
94+
assert len(data_sets) == 1
95+
assert (
96+
expectedMessageOne
97+
== data_sets[0].data[SyslogFieldKeyDefaults[SyslogFieldKey.MESSAGE]]
98+
)
99+
assert (
100+
expectedHostNameOne
101+
== data_sets[0].data[SyslogFieldKeyDefaults[SyslogFieldKey.HEADER_HOSTNAME]]
102+
)
103+
assert (
104+
expectedPriOne
105+
== data_sets[0].data[SyslogFieldKeyDefaults[SyslogFieldKey.HEADER_PRI]]
106+
)
107+
assert (
108+
expectedSeverityOne
109+
== data_sets[0].data[SyslogFieldKeyDefaults[SyslogFieldKey.HEADER_PRI_SEVERITY]]
110+
)
111+
assert (
112+
expectedFacilityOne
113+
== data_sets[0].data[SyslogFieldKeyDefaults[SyslogFieldKey.HEADER_PRI_FACILITY]]
114+
)
115+
assert (
116+
expectedTimestampOne
117+
== data_sets[0].data[SyslogFieldKeyDefaults[SyslogFieldKey.HEADER_TIMESTAMP]]
118+
)
119+
120+
121+
def generate_from_file(
122+
f: TextIOBase, parser: AbstractSyslogParser[SyslogDataSet]
123+
) -> Generator[SyslogDataSet, None, None]:
124+
"""Open a Path and return the generator."""
125+
return parser.generate(f)

0 commit comments

Comments
 (0)