#! /bin/bash export YES_COLOR=1 lnav_test="${top_builddir}/src/lnav-test" unset XDG_CONFIG_HOME run_cap_test ${lnav_test} -nN \ -c ";SELECT 1 = ?" run_cap_test ${lnav_test} -n \ -c ";.read nonexistent-file" \ ${test_dir}/logfile_empty.0 run_test ${lnav_test} -n \ -c ";.read ${test_dir}/file_for_dot_read.sql" \ -c ':write-csv-to -' \ ${test_dir}/logfile_syslog.0 check_output ".read did not work?" <,2015-11-03 09:23:38.000,0,info,0,,,,# is up,aff2bfc3c61e7b86329b83190f0912b3 1,,2015-11-03 09:23:38.000,0,info,0,,,,# is up,aff2bfc3c61e7b86329b83190f0912b3 2,,2015-11-03 09:23:38.000,0,info,0,,,,# is down,506560b3c73dee057732e69a3c666718 EOF run_test ${lnav_test} -n \ -c ";SELECT fields FROM logfmt_log" \ -c ":write-json-to -" \ ${test_dir}/logfile_logfmt.0 check_output "logfmt fields are not handled correctly?" < logfile_json.json.gz dd if=logfile_json.json.gz of=logfile_json-trunc.json.gz bs=64 count=2 # TODO re-enable this #run_test ${lnav_test} -n \ # -c ";SELECT content FROM lnav_file" \ # logfile_json-trunc.json.gz #check_error_output "invalid gzip file working?" <,2011-11-03 00:19:26.452,0,info,0,,,,1320279566.452687,CwFs1P2UcUdlSxD2La,192.168.2.76,52026,132.235.215.119,80,1,GET,www.reddit.com,/,,1.1,Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:7.0.1) Gecko/20100101 Firefox/7.0.1,0,109978,200,OK,,,,,,,,,,Ftw3fJ2JJF3ntMTL2,,text/html 1,,2011-11-03 00:19:26.831,379,info,0,,,,1320279566.831619,CJxSUgkInyKSHiju1,192.168.2.76,52030,72.21.211.173,80,1,GET,e.thumbs.redditmedia.com,/E-pbDbmiBclPkDaX.jpg,http://www.reddit.com/,1.1,Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:7.0.1) Gecko/20100101 Firefox/7.0.1,0,2300,200,OK,,,,,,,,,,FFTf9Zdgk3YkfCKo3,,image/jpeg 2,,2011-11-03 00:19:26.831,0,info,0,,,,1320279566.831563,CJwUi9bdB9c1lLW44,192.168.2.76,52029,72.21.211.173,80,1,GET,f.thumbs.redditmedia.com,/BP5bQfy4o-C7cF6A.jpg,http://www.reddit.com/,1.1,Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:7.0.1) Gecko/20100101 Firefox/7.0.1,0,2272,200,OK,,,,,,,,,,FfXtOj3o7aub4vbs2j,,image/jpeg 3,,2011-11-03 00:19:26.831,0,info,0,,,,1320279566.831473,CoX7zA3OJKGUOSCBY2,192.168.2.76,52027,72.21.211.173,80,1,GET,e.thumbs.redditmedia.com,/SVUtep3Rhg5FTRn4.jpg,http://www.reddit.com/,1.1,Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:7.0.1) Gecko/20100101 Firefox/7.0.1,0,2562,200,OK,,,,,,,,,,F21Ybs3PTqS6O4Q2Zh,,image/jpeg 4,,2011-11-03 00:19:26.831,0,info,0,,,,1320279566.831643,CT0JIh479jXIGt0Po1,192.168.2.76,52031,72.21.211.173,80,1,GET,f.thumbs.redditmedia.com,/uuy31444rLSyKdHS.jpg,http://www.reddit.com/,1.1,Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:7.0.1) Gecko/20100101 Firefox/7.0.1,0,1595,200,OK,,,,,,,,,,Fdk0MZ1wQmKWAJ4WH4,,image/jpeg EOF run_test env TZ=UTC ${lnav_test} -n \ -c ";SELECT * FROM bro_http_log WHERE log_level = 'error'" \ -c ":write-csv-to -" \ ${test_dir}/logfile_bro_http.log.0 check_output "bro logs are not recognized?" <,2011-11-03 00:19:49.337,18,error,0,,,,1320279589.337053,CBHHuR1xFnm5C5CQBc,192.168.2.76,52074,74.125.225.76,80,1,GET,i4.ytimg.com,/vi/gDbg_GeuiSY/hqdefault.jpg,,1.1,Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:7.0.1) Gecko/20100101 Firefox/7.0.1,0,893,404,Not Found,,,,,,,,,,F2GiAw3j1m22R2yIg2,,image/jpeg EOF run_test ${lnav_test} -n \ -c ';select log_time from access_log where log_line > 100000' \ -c ':switch-to-view db' \ ${test_dir}/logfile_access_log.0 check_output "out-of-range query failed?" < -100000' \ ${test_dir}/logfile_access_log.0 run_test ${lnav_test} -n \ -c ';select log_time from access_log where log_line < -10000' \ -c ':switch-to-view db' \ ${test_dir}/logfile_access_log.0 check_output "out-of-range query failed?" < -10000' \ ${test_dir}/logfile_access_log.0 run_test ${lnav_test} -n \ -c ';select log_time from access_log where log_line < 0' \ -c ':switch-to-view db' \ ${test_dir}/logfile_access_log.0 check_output "out-of-range query failed?" <= 0' \ -c ':switch-to-view db' \ ${test_dir}/logfile_access_log.0 run_cap_test ${lnav_test} -n \ -c ';select sc_bytes from access_log' \ -c ':spectrogram sc_bytes' \ ${test_dir}/logfile_access_log.0 run_cap_test ${lnav_test} -n \ -c ';select log_time,sc_bytes from access_log' \ -c ':spectrogram sc_byes' \ ${test_dir}/logfile_access_log.0 run_cap_test ${lnav_test} -n \ -c ';select log_time,c_ip from access_log' \ -c ':spectrogram c_ip' \ ${test_dir}/logfile_access_log.0 run_cap_test env TZ=UTC LC_NUMERIC=C ${lnav_test} -n \ -c ':spectrogram bro_response_body_len' \ ${test_dir}/logfile_bro_http.log.0 run_cap_test ${lnav_test} -n \ -c ';select log_time,sc_bytes from access_log order by log_time desc' \ -c ':spectrogram sc_bytes' \ ${test_dir}/logfile_access_log.0 cp ${srcdir}/logfile_syslog_with_mixed_times.0 logfile_syslog_with_mixed_times_test.0 touch -t 201511030923 logfile_syslog_with_mixed_times_test.0 run_test ${lnav_test} -n \ -c ";select log_time,log_actual_time from syslog_log" \ -c ':write-csv-to -' \ logfile_syslog_with_mixed_times_test.0 check_output "log_actual_time column not working" < 1,middle 2,middle EOF run_test ${lnav_test} -n \ -c ";update access_log set log_part = 'middle' where log_line = 1" \ -c ";update access_log set log_part = NULL where log_line = 1" \ -c ';select log_line, log_part from access_log' \ -c ':write-csv-to -' \ ${test_dir}/logfile_access_log.0 check_output "setting log_part is not working" < 1, 2, EOF run_test ${lnav_test} -n \ -c ";update access_log set log_part = 'middle' where log_line = 1" \ -c ";update access_log set log_part = NULL where log_line = 2" \ -c ';select log_line, log_part from access_log' \ -c ':write-csv-to -' \ ${test_dir}/logfile_access_log.0 check_output "setting log_part is not working" < 1,middle 2,middle EOF run_test ${lnav_test} -n \ -I "${top_srcdir}/test" \ -c ";select * from web_status" \ -c ':write-csv-to -' \ ${test_dir}/logfile_access_log.0 check_output "access_log table is not working" <,2009-07-20 22:59:26.000,0,info,0,,,,192.168.202.254,GET,-,,/vmw/cgi/tramp,gPXE/0.9.7,-,HTTP/1.0,134,200, 1,,2009-07-20 22:59:29.000,3000,error,0,,,,192.168.202.254,GET,-,,/vmw/vSphere/default/vmkboot.gz,gPXE/0.9.7,-,HTTP/1.0,46210,404, 2,,2009-07-20 22:59:29.000,0,info,0,,,,192.168.202.254,GET,-,,/vmw/vSphere/default/vmkernel.gz,gPXE/0.9.7,-,HTTP/1.0,78929,200, EOF run_test ${lnav_test} -n \ -c ";select * from access_log where log_level >= 'warning'" \ -c ':write-csv-to -' \ ${test_dir}/logfile_access_log.0 check_output "loglevel collator is not working" <,2009-07-20 22:59:29.000,3000,error,0,,,,192.168.202.254,GET,-,,/vmw/vSphere/default/vmkboot.gz,gPXE/0.9.7,-,HTTP/1.0,46210,404, EOF # XXX The timestamp on the file is used to determine the year for syslog files. touch -t 200711030923 ${test_dir}/logfile_syslog.0 run_test ${lnav_test} -n \ -c ";select * from syslog_log" \ -c ':write-csv-to -' \ ${test_dir}/logfile_syslog.0 check_output "syslog_log table is not working" <,2007-11-03 09:23:38.000,0,error,0,,,,veridian,,7998,,automount,,automount[7998], 1,,2007-11-03 09:23:38.000,0,info,0,,,,veridian,,16442,,automount,,automount[16442], 2,,2007-11-03 09:23:38.000,0,error,0,,,,veridian,,7999,,automount,,automount[7999], 3,,2007-11-03 09:47:02.000,1404000,info,0,,,,veridian,,,,sudo,,sudo, EOF run_test ${lnav_test} -n \ -c ";select * from syslog_log where log_time >= NULL" \ -c ':write-csv-to -' \ ${test_dir}/logfile_syslog.0 check_output "log_time collation failed on null" <= datetime('2007-11-03T09:47:02.000')" \ -c ':write-csv-to -' \ ${test_dir}/logfile_syslog.0 check_output "log_time collation is wrong" < 60000" \ -c ':write-to -' \ ${test_dir}/logfile_access_log.0 export SQL_ENV_VALUE="foo bar,baz" run_test ${lnav_test} -n \ -c ';select $SQL_ENV_VALUE as val' \ -c ':write-csv-to -' \ ${test_dir}/logfile_access_log.0 check_output "env vars are not working in SQL" <,2015-04-07 00:49:42.000 1,middle,2015-04-07 05:49:53.000 18,middle,2015-04-07 07:31:56.000 20,middle,2015-04-07 07:31:56.000 21,end,2015-04-07 07:31:56.000 22,end,2015-04-07 07:32:56.000 EOF run_test ${lnav_test} -n \ -c ":goto 1" \ -c ":partition-name middle" \ -c ":clear-partition" \ -c ";select log_line, log_part from access_log" \ -c ":write-csv-to -" \ ${test_dir}/logfile_access_log.0 check_output "clear-partition does not work" < 1, 2, EOF run_test ${lnav_test} -n \ -c ":goto 1" \ -c ":partition-name middle" \ -c ":goto 2" \ -c ":clear-partition" \ -c ";select log_line, log_part from access_log" \ -c ":write-csv-to -" \ ${test_dir}/logfile_access_log.0 check_output "clear-partition does not work when in the middle of a part" < 1, 2, EOF run_test ${lnav_test} -n \ -c ";SELECT * FROM openam_log" \ -c ":write-json-to -" \ ${test_dir}/logfile_openam.0 check_output "write-json-to isn't working?" <http://openam.vagrant.dev/openam\\\\n\\\\n\\\\n\\\\nhttp://openam.vagrant.dev/openam\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n4uSmVzjovUdQd3px/RcnoxQBsqE=\\\\n\\\\n\\\\n\\\\nhm/grge36uA6j1OWif2bTcvVTwESjmuJa27NxepW0AiV5YlcsHDl7RAIk6k/CjsSero3bxGbm56m\\\\nYncOEi9F1Tu7dS0bfx+vhm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dc=openam", "hostname": "192.168.33.1\t", "ipaddr": "Not Available", "loggedby": "cn=dsameuser,ou=DSAME Users,dc=openam", "loginid": "id=openamuser,ou=user,dc=openam", "messageid": "SAML2-37", "modulename": "SAML2.access", "nameid": "user@example.com" }, { "log_line": 1, "log_part": null, "log_time": "2014-06-15 01:04:52.000", "log_idle_msecs": 0, "log_level": "trace", "log_mark": 0, "log_comment": null, "log_tags": null, "log_filters": null, "contextid": "ec5708a7f199678a01", "data": "vagrant|/", "domain": "dc=openam", "hostname": "127.0.1.1\t", "ipaddr": "Not Available", "loggedby": "cn=dsameuser,ou=DSAME Users,dc=openam", "loginid": "cn=dsameuser,ou=DSAME Users,dc=openam", "messageid": "COT-22", "modulename": "COT.access", "nameid": "Not Available" } ] EOF run_cap_test ${lnav_test} -d "/tmp/lnav.err" -n \ -c ";select log_line, col_0 from logline" \ ${test_dir}/logfile_for_join.0 run_cap_test ${lnav_test} -d "/tmp/lnav.err" -n \ -c ";select col_0 from logline where log_line > 4" \ ${test_dir}/logfile_for_join.0 run_test ${lnav_test} -d "/tmp/lnav.err" -n \ -c ":goto 1" \ -c ":create-logline-table join_group" \ -c ":goto 2" \ -c ";select logline.log_line as llline, join_group.log_line as jgline from logline, join_group where logline.col_0 = join_group.col_2" \ -c ':write-csv-to -' \ ${test_dir}/logfile_for_join.0 check_output "create-logline-table is not working" <,2015-03-24 14:02:50.000,6927348000,info,0,,,,127.0.0.1,GET,,,/includes/js/combined-javascript.js,,-,HTTP/1.1,65508,200, 2,,2015-03-24 14:02:50.000,0,error,0,,,,127.0.0.1,GET,,,/bad.foo,,-,HTTP/1.1,65508,404, EOF run_test ${lnav_test} -n \ -c ";select log_text from generic_log" \ -c ":write-json-to -" \ ${test_dir}/logfile_multiline.0 check_output "multiline data is not right?" < 0" \ -c ":write-csv-to -" \ ${test_dir}/logfile_multiline.0 check_output "create-search-table is not working with where clause?" <\w+), World!" \ -c ";select word, typeof(word) from search_test1" \ -c ":write-csv-to -" \ ${test_dir}/logfile_multiline.0 check_output "create-search-table is not working?" <\d+)" \ -c ";select typeof(ethnum) from search_test1" \ -c ":write-csv-to -" \ ${test_dir}/logfile_syslog.2 check_output "regex type guessing is not working?" < EOF run_test ${lnav_test} -n \ -c ";SELECT regexp_capture.content FROM access_log, regexp_capture(access_log.cs_version, 'HTTP/(\d+\.\d+)') WHERE regexp_capture.capture_index = 1" \ -c ':write-csv-to -' \ ${test_dir}/logfile_access_log.0 check_output "joining log table with regexp_capture is not working?" <