diff --git a/tests/fixtures/generic/syslog-5424.json b/tests/fixtures/generic/syslog-5424.json new file mode 100644 index 00000000..42528945 --- /dev/null +++ b/tests/fixtures/generic/syslog-5424.json @@ -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"}] diff --git a/tests/fixtures/generic/syslog-5424.out b/tests/fixtures/generic/syslog-5424.out new file mode 100644 index 00000000..93f7174b --- /dev/null +++ b/tests/fixtures/generic/syslog-5424.out @@ -0,0 +1,12 @@ +<165>1 2003-08-24T05:14:15.000003-07:00 192.0.2.1 myproc 8710 - - %% It's time to make the do-nuts. +<34>1 203-10-11T22:14:15.003Z mymachine.example.com su - ID47 - BOM'su root' failed for lonvick on /dev/pts/8 +<34>1 2003-10-11T22:14:15.003Z mymachine.example.com su - ID47 - BOM'su root' failed for lonvick on /dev/pts/8 + +<165>1 2003-08-24T05:14:15.000003-07:00 192.0.2.1 myproc 8710 - - %% It's time to make the do-nuts. +1 2003-10-11T22:14:15.003Z mymachine.example.com su - ID47 - BOM'su root' failed for lonvick on /dev/pts/8 +<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 + +<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 +2003-10-11T22:14:15.003Z mymachine.example.com evntslog - ID47 [exampleSDID@32473 iut="3" eventSource="Application" eventID="1011"][examplePriority@32473 class="high"] +<1>12 - mymachine - - ID47 - asd asdaasd + diff --git a/tests/test_syslog.py b/tests/test_syslog.py new file mode 100644 index 00000000..2a05e4a4 --- /dev/null +++ b/tests/test_syslog.py @@ -0,0 +1,35 @@ +import os +import unittest +import json +import jc.parsers.syslog + +THIS_DIR = os.path.dirname(os.path.abspath(__file__)) + + +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.json'), 'r', encoding='utf-8') as f: + self.syslog_json = json.loads(f.read()) + + + def test_syslog_nodata(self): + """ + Test 'syslog' with no data + """ + self.assertEqual(jc.parsers.syslog.parse('', quiet=True), []) + + def test_syslog_sample(self): + """ + Test 'syslog' with sample data + """ + self.assertEqual(jc.parsers.syslog.parse(self.syslog, quiet=True), self.syslog_json) + + +if __name__ == '__main__': + unittest.main()