mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-08-06 22:32:54 +02:00
add syslog streaming tests
This commit is contained in:
1
tests/fixtures/generic/syslog-3164-streaming.json
vendored
Normal file
1
tests/fixtures/generic/syslog-3164-streaming.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
[{"priority":34,"date":"Oct 11 22:14:15","hostname":"mymachine","tag":"su","content":"'su root' failed for lonvick on /dev/pts/8"},{"unparsable":"<3444>Oct 11 22:14:15 mymachine su: 'su root' failed for lonvick on /dev/pts/8"},{"priority":null,"date":"Oct 11 22:14:15","hostname":"mymachine","tag":"su","content":"'su root' failed for lonvick on /dev/pts/8"},{"priority":35,"date":"Oct 12 22:14:15","hostname":"client_machine","tag":"su","content":"'su root' failed for joe on /dev/pts/2"},{"priority":35,"date":"Mar 7 04:02:16","hostname":"avas","tag":"clamd","content":"[11165]: /var/amavis/amavis-20040307T033734-10329/parts/part-00003: Worm.Mydoom.F FOUND"},{"priority":null,"date":"Mar 7 04:05:55","hostname":"avas","tag":"clamd","content":"[11240]: /var/amavis/amavis-20040307T035901-10615/parts/part-00002: Worm.SomeFool.Gen-1 FOUND"},{"priority":5,"date":"Mar 7 09:00:51","hostname":"avas","tag":"clamd","content":"[27173]: SelfCheck: Database status OK."},{"priority":null,"date":"Mar 7 05:59:02","hostname":"avas","tag":"clamd","content":"[27173]: Database correctly reloaded (20400 viruses)"},{"priority":null,"date":"Mar 7 04:02:16","hostname":"avas","tag":"clamd","content":"[11165]: /var/amavis/amavis-20040307T033734-10329/parts/part-00003: Worm.Mydoom.F FOUND"},{"priority":null,"date":"Mar 7 04:05:55","hostname":"avas","tag":"clamd","content":"[11240]: /var/amavis/amavis-20040307T035901-10615/parts/part-00002: Worm.SomeFool.Gen-1 FOUND"},{"priority":null,"date":"Mar 7 09:00:51","hostname":"avas","tag":"clamd","content":"[27173]: SelfCheck: Database status OK."},{"priority":null,"date":"Mar 7 05:59:02","hostname":"avas","tag":"clamd","content":"[27173]: Database correctly reloaded (20400 viruses)"},{"priority":null,"date":"Mar 7 11:14:35","hostname":"avas","tag":"dccd","content":"[13284]: 21 requests/sec are too many from anonymous 205.201.1.56,2246"},{"priority":null,"date":"Mar 8 00:22:57","hostname":"avas","tag":"dccifd","content":"[9933]: write(MTA socket,4): Broken pipe"},{"priority":null,"date":"Mar 7 21:23:22","hostname":"avas","tag":"dccifd","content":"[6191]: missing message body"},{"priority":null,"date":"Mar 9 16:05:17","hostname":"avas","tag":"named","content":"[12045]: zone PLNet/IN: refresh: non-authoritative answer from master 10.0.0.253#53"},{"priority":null,"date":"Mar 10 00:38:16","hostname":"avas","tag":"dccifd","content":"[23069]: continue not asking DCC 17 seconds after failure"},{"priority":null,"date":"Mar 10 09:42:11","hostname":"avas","tag":"named","content":"client 127.0.0.1#55524: query: 23.68.27.142.sa-trusted.bondedsender.org IN TXT"},{"priority":null,"date":"Mar 9 03:48:07","hostname":"avas","tag":"dccd","content":"[145]: automatic dbclean; starting `dbclean -DPq -i 1189 -L info,local5.notice -L error,local5.err`"},{"priority":null,"date":"Mar 9 11:58:18","hostname":"avas","tag":"kernel","content":"i810_audio: Connection 0 with codec id 2"},{"priority":null,"date":"Mar 9 19:41:13","hostname":"avas","tag":"dccd","content":"[3004]: \"packet length 44 too small for REPORT\" sent to client 1 at 194.63.250.215,47577"},{"priority":null,"date":"Mar 8 09:01:07","hostname":"avas","tag":"sshd","content":"(pam_unix)[21839]: session opened for user tom by (uid=35567)"},{"priority":null,"date":"Mar 8 03:52:04","hostname":"avas","tag":"dccd","content":"[13284]: 1.2.32 database /home/dcc/dcc_db reopened with 997 MByte window"},{"priority":null,"date":"Mar 8 16:05:26","hostname":"avas","tag":"arpwatch","content":"listening on eth0"},{"priority":null,"date":"Mar 10 10:00:06","hostname":"avas","tag":"named","content":"[6986]: zone PLNet/IN: refresh: non-authoritative answer from master 192.75.26.21#53"},{"priority":null,"date":"Mar 10 10:00:10","hostname":"avas","tag":"named","content":"[6986]: client 127.0.0.1#55867: query: mail.canfor.ca IN MX"},{"priority":null,"date":"Mar 8 15:18:40","hostname":"avas","tag":null,"content":"last message repeated 11 times"},{"priority":null,"date":"Mar 8 15:18:40","hostname":"127:0:ab::1","tag":"sshd","content":"unauthorized request"},{"priority":null,"date":"Mar 8 15:18:40","hostname":"server.example.com","tag":"sshd","content":"unauthorized request"},{"priority":null,"date":"Mar 8 15:18:40","hostname":"192.168.1.1","tag":"sshd","content":"unauthorized request"},{"priority":35,"date":"Mar 8 15:18:40","hostname":"server.example.com","tag":"sshd","content":"unauthorized request"},{"unparsable":"<7>unparsable line"}]
|
1
tests/fixtures/generic/syslog-5424-streaming.json
vendored
Normal file
1
tests/fixtures/generic/syslog-5424-streaming.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
[{"priority":165,"version":1,"timestamp":"2003-08-24T05:14:15.000003-07:00","hostname":"192.0.2.1","appname":"myproc","proc_id":8710,"msg_id":null,"structured_data":null,"message":"%% It's time to make the do-nuts.","timestamp_epoch":1061727255,"timestamp_epoch_utc":null},{"unparsable":"<34>1 203-10-11T22:14:15.003Z mymachine.example.com su - ID47 - BOM'su root' failed for lonvick on /dev/pts/8"},{"priority":34,"version":1,"timestamp":"2003-10-11T22:14:15.003Z","hostname":"mymachine.example.com","appname":"su","proc_id":null,"msg_id":"ID47","structured_data":null,"message":"BOM'su root' failed for lonvick on /dev/pts/8","timestamp_epoch":1065935655,"timestamp_epoch_utc":1065910455},{"priority":165,"version":1,"timestamp":"2003-08-24T05:14:15.000003-07:00","hostname":"192.0.2.1","appname":"myproc","proc_id":8710,"msg_id":null,"structured_data":null,"message":"%% It's time to make the do-nuts.","timestamp_epoch":1061727255,"timestamp_epoch_utc":null},{"priority":null,"version":1,"timestamp":"2003-10-11T22:14:15.003Z","hostname":"mymachine.example.com","appname":"su","proc_id":null,"msg_id":"ID47","structured_data":null,"message":"BOM'su root' failed for lonvick on /dev/pts/8","timestamp_epoch":1065935655,"timestamp_epoch_utc":1065910455},{"priority":190,"version":1,"timestamp":"2003-10-11T22:14:15.003Z","hostname":"mymachine.example.com","appname":"evntslog","proc_id":null,"msg_id":"ID47","structured_data":[{"identity":"exampleSDID@32473","parameters":{"iut":"3","eventSource":"Application","eventID":"10] 11"}}],"message":"BOMAn application event log entry..[ ] sadasd","timestamp_epoch":1065935655,"timestamp_epoch_utc":1065910455},{"unparsable":"<190)1 2003-10-11T22:14:15.003Z mymachine.example.com evntslog - ID47 [exampleSDID@32473 iut=\"3\" eventSource=\"Application\" eventID=\"10\\] 11\"] BOMAn application event log entry..[ ] sadasd"},{"priority":null,"version":null,"timestamp":"2003-10-11T22:14:15.003Z","hostname":"mymachine.example.com","appname":"evntslog","proc_id":null,"msg_id":"ID47","structured_data":[{"identity":"exampleSDID@32473","parameters":{"iut":"3","eventSource":"Application","eventID":"1011"}},{"identity":"examplePriority@32473","parameters":{"class":"high"}}],"message":null,"timestamp_epoch":1065935655,"timestamp_epoch_utc":1065910455},{"priority":1,"version":12,"timestamp":null,"hostname":"mymachine","appname":null,"proc_id":null,"msg_id":"ID47","structured_data":null,"message":"asd asdaasd"}]
|
37
tests/test_syslog_bsd_s.py
Normal file
37
tests/test_syslog_bsd_s.py
Normal file
@ -0,0 +1,37 @@
|
||||
import os
|
||||
import json
|
||||
import unittest
|
||||
import jc.parsers.syslog_bsd_s
|
||||
|
||||
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
# To create streaming output use:
|
||||
# $ cat syslog.out | jc --syslog-bsd-s | jello -c > syslog-bsd-streaming.json
|
||||
|
||||
|
||||
class MyTests(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
# input
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/syslog-3164.out'), 'r', encoding='utf-8') as f:
|
||||
self.syslog_bsd = f.read()
|
||||
|
||||
# output
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/syslog-3164-streaming.json'), 'r', encoding='utf-8') as f:
|
||||
self.syslog_bsd_streaming_json = json.loads(f.read())
|
||||
|
||||
def test_syslog_bsd_s_nodata(self):
|
||||
"""
|
||||
Test 'syslog_bsd' with no data
|
||||
"""
|
||||
self.assertEqual(list(jc.parsers.syslog_bsd_s.parse([], quiet=True)), [])
|
||||
|
||||
def test_syslog_bsd_s(self):
|
||||
"""
|
||||
Test bsd Syslog
|
||||
"""
|
||||
self.assertEqual(list(jc.parsers.syslog_bsd_s.parse(self.syslog_bsd.splitlines(), quiet=True)), self.syslog_bsd_streaming_json)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
37
tests/test_syslog_s.py
Normal file
37
tests/test_syslog_s.py
Normal file
@ -0,0 +1,37 @@
|
||||
import os
|
||||
import json
|
||||
import unittest
|
||||
import jc.parsers.syslog_s
|
||||
|
||||
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
# To create streaming output use:
|
||||
# $ cat syslog.out | jc --syslog-s | jello -c > syslog-streaming.json
|
||||
|
||||
|
||||
class MyTests(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
# input
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/syslog-5424.out'), 'r', encoding='utf-8') as f:
|
||||
self.syslog = f.read()
|
||||
|
||||
# output
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/syslog-5424-streaming.json'), 'r', encoding='utf-8') as f:
|
||||
self.syslog_streaming_json = json.loads(f.read())
|
||||
|
||||
def test_syslog_s_nodata(self):
|
||||
"""
|
||||
Test 'syslog' with no data
|
||||
"""
|
||||
self.assertEqual(list(jc.parsers.syslog_s.parse([], quiet=True)), [])
|
||||
|
||||
def test_syslog_s(self):
|
||||
"""
|
||||
Test syslog file
|
||||
"""
|
||||
self.assertEqual(list(jc.parsers.syslog_s.parse(self.syslog.splitlines(), quiet=True)), self.syslog_streaming_json)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Reference in New Issue
Block a user