-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathtest_log_parse.py
More file actions
135 lines (108 loc) · 6.7 KB
/
test_log_parse.py
File metadata and controls
135 lines (108 loc) · 6.7 KB
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
# https://docs.python.org/3/library/unittest.html
import unittest
from log_parse import LogParse
import os
class LogParseTest(unittest.TestCase):
"""Unit test structure for LogParse"""
# https://docs.python.org/3/library/unittest.html#unittest.TestCase
# Sample syslog file
fname = 'syslogs.txt'
# Create a LogParse object and parse the test syslog file
lp = LogParse()
# https://pandas.pydata.org/docs/user_guide/index.html
df = lp.parse_syslog_file(os.path.join(fname))
def test_log_parse(self):
"""Basic test case to show that LogParse loads OK"""
self.assertEqual('LogParse', self.lp.log_parse_id())
def test_syslog_file(self):
"""Checks to make sure the syslog file appears valid"""
# https://www.cisco.com/c/en/us/td/docs/security/asa/syslog/b_syslog/syslogs-sev-level.html
fname = 'syslogs.txt'
# Open the syslog file
# https://docs.python.org/3/tutorial/inputoutput.html
with open(os.path.join(fname), encoding='utf-8') as f:
line_num = 1
for line in f:
# create a string with the current file name and line number
# for use in error messages
ln = fname+':'+str(line_num)+' '
# expect all lines to begin with %ASA-
# https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertRegex
self.assertRegex(line, r'^%ASA-', ln+'does not start with %ASA-')
# Make sure there are no other %ASA which would indicate a
# merged line or other problem in the syslog file
self.assertNotRegex(line, r'.%ASA', ln+'extra %ASA found')
line_num += 1
def test_ASA_1_103004(self):
# %ASA-1-103004: (Primary) Other firewall reports this firewall failed. Reason: reason-string.
self.assertTrue(self.df.loc[103004, 'Type'] == 'ASA')
self.assertTrue(self.df.loc[103004, 'Severity'] == 1)
self.assertTrue(self.df.loc[103004, 'Text'] == '(Primary) Other firewall reports this firewall failed. Reason: '
'reason-string.')
self.assertTrue(self.df.loc[103004, 'Reason'] == 'reason-string.')
def test_ASA_1_114001(self):
# %ASA-1-114001: Failed to initialize 4GE SSM I/O card (error error_string).
print(self.df.loc[114001])
self.assertTrue(self.df.loc[114001, 'Type'] == 'ASA')
self.assertTrue(self.df.loc[114001, 'Severity'] == 1)
self.assertTrue(self.df.loc[114001, 'Text'] == 'Failed to initialize 4GE SSM I/O card (error error_string).')
self.assertTrue(self.df.loc[114001, 'Error'] == 'error_string')
def test_ASA_3_114010(self):
# %ASA-3-114010: Failed to set multicast hardware address in 4GE SSM I/O card (error error_string).
self.assertTrue(self.df.loc[114010, 'Type'] == 'ASA')
self.assertTrue(self.df.loc[114010, 'Severity'] == 3)
self.assertTrue(self.df.loc[114010, 'Text'] == 'Failed to set multicast hardware address in 4GE SSM I/O card (error error_string).')
self.assertTrue(self.df.loc[114010, 'Error'] == 'error_string')
def test_ASA_3_114012(self):
# %ASA-3-114012: Failed to delete multicast hardware address in 4GE SSM I/O card (error error_string).
print(self.df.loc[114012])
self.assertTrue(self.df.loc[114012, 'Type'] == 'ASA')
self.assertTrue(self.df.loc[114012, 'Severity'] == 3)
self.assertTrue(self.df.loc[114012, 'Text'] == 'Failed to delete multicast hardware address in 4GE SSM I/O card'
' (error error_string).')
self.assertTrue(self.df.loc[114012, 'Error'] == 'error_string')
def test_ASA_3_114013(self):
# %ASA-3-114013: Failed to set mac address table in 4GE SSM I/O card (error error_string).
print(self.df.loc[114013])
self.assertTrue(self.df.loc[114013, 'Type'] == 'ASA')
self.assertTrue(self.df.loc[114013, 'Severity'] == 3)
self.assertTrue(self.df.loc[114013, 'Text'] == 'Failed to set mac address table in 4GE SSM I/O card (error '
'error_string).')
self.assertTrue(self.df.loc[114013, 'Error'] == 'error_string')
def test_ASA_3_114017(self):
# %ASA-3-114017: Failed to get link status in 4GE SSM I/O card (error error_string).
print(self.df.loc[114017])
self.assertTrue(self.df.loc[114017, 'Type'] == 'ASA')
self.assertTrue(self.df.loc[114017, 'Severity'] == 3)
self.assertTrue(self.df.loc[114017, 'Text'] == 'Failed to get link status in 4GE SSM I/O card (error error_string).')
self.assertTrue(self.df.loc[114017, 'Error'] == 'error_string')
def test_ASA_3_114009(self):
# %ASA-3-114009: Failed to initialize 4GE SSM I/O card (error error_string).
print(self.df.loc[114009])
self.assertTrue(self.df.loc[114009, 'Type'] == 'ASA')
self.assertTrue(self.df.loc[114009, 'Severity'] == 3)
self.assertTrue(self.df.loc[114009, 'Text'] == 'Failed to set multicast address in 4GE SSM I/O card (error error_string).')
self.assertTrue(self.df.loc[114009, 'Error'] == 'error_string')
def test_ASA_3_114011(self):
# %ASA-3-114011: Failed to delete multicast address in 4GE SSM I/O card (error error_string).
print(self.df.loc[114011])
self.assertTrue(self.df.loc[114011, 'Type'] == 'ASA')
self.assertTrue(self.df.loc[114011, 'Severity'] == 3)
self.assertTrue(self.df.loc[114011, 'Text'] == 'Failed to delete multicast address in 4GE SSM I/O card (error error_string).')
self.assertTrue(self.df.loc[114011, 'Error'] == 'error_string')
def test_ASA_3_114006(self):
# %ASA-3-114006: Failed to initialize 4GE SSM I/O card (error error_string).
print(self.df.loc[114009])
self.assertTrue(self.df.loc[114006, 'Type'] == 'ASA')
self.assertTrue(self.df.loc[114006, 'Severity'] == 3)
self.assertTrue(self.df.loc[114006, 'Text'] == 'Failed to get port statistics in 4GE SSM I/O card (error error_string).')
self.assertTrue(self.df.loc[114006, 'Error'] == 'error_string')
def test_ASA_3_114014(self):
# %ASA-3-114014: Failed to set mac address in 4GE SSM I/O card (error error_string).
print(self.df.loc[114014])
self.assertTrue(self.df.loc[114014, 'Type'] == 'ASA')
self.assertTrue(self.df.loc[114014, 'Severity'] == 3)
self.assertTrue(self.df.loc[114014, 'Text'] == 'Failed to set mac address in 4GE SSM I/O card (error error_string).')
self.assertTrue(self.df.loc[114014, 'Error'] == 'error_string')
if __name__ == '__main__':
unittest.main()