Mercurial > hg > nginx-tests
annotate syslog.t @ 811:dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 17 Dec 2015 17:18:07 +0300 |
parents | 1f48ed26b49a |
children | bc9e519ab3bc |
rev | line source |
---|---|
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Nginx, Inc. |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 # Tests for syslog. |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Various log levels emitted with limit_req_log_level. |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
408
82b15c81978e
Tests: skipped tests on win32 that use shared memory.
Sergey Kandaurov <pluknet@nginx.com>
parents:
404
diff
changeset
|
25 plan(skip_all => 'win32') if $^O eq 'MSWin32'; |
82b15c81978e
Tests: skipped tests on win32 that use shared memory.
Sergey Kandaurov <pluknet@nginx.com>
parents:
404
diff
changeset
|
26 |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 my $t = Test::Nginx->new()->has(qw/http limit_req/); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
771
abe795720deb
Tests: added test for syslog nohostname parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
29 $t->write_file_expand('nginx.conf', <<'EOF'); |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 %%TEST_GLOBALS%% |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 error_log syslog:server=127.0.0.1:8083 info; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 error_log %%TESTDIR%%/f_glob.log info; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 daemon off; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 events { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 http { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 %%TEST_GLOBALS_HTTP%% |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 |
503
071e8941e3bf
Tests: reduce shared memory zone sizes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
467
diff
changeset
|
44 limit_req_zone $binary_remote_addr zone=one:1m rate=1r/m; |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 log_format empty ""; |
445
62d1f96c5ff4
Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
408
diff
changeset
|
47 log_format logf "$uri:$status"; |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 error_log syslog:server=127.0.0.1:8084 info; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 error_log %%TESTDIR%%/f_http.log info; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 server { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 listen 127.0.0.1:8080; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 server_name localhost; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 location /e { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 error_log syslog:server=127.0.0.1:8080; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 location /a { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 access_log syslog:server=127.0.0.1:8080; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 location /ef { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 error_log syslog:server=127.0.0.1:8080,facility=user; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 location /es { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 error_log syslog:server=127.0.0.1:8080,severity=alert; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 location /et { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 error_log syslog:server=127.0.0.1:8080,tag=SEETHIS; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 location /af { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 access_log syslog:server=127.0.0.1:8080,facility=user; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 location /as { |
788
1f48ed26b49a
Tests: interchanged syslog parameters for better coverage.
Sergey Kandaurov <pluknet@nginx.com>
parents:
771
diff
changeset
|
75 # put severity inside to catch possible parsing programming errors |
1f48ed26b49a
Tests: interchanged syslog parameters for better coverage.
Sergey Kandaurov <pluknet@nginx.com>
parents:
771
diff
changeset
|
76 access_log syslog:severity=alert,server=127.0.0.1:8080; |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 location /at { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 access_log syslog:server=127.0.0.1:8080,tag=SEETHIS; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 location /e2 { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 error_log syslog:server=127.0.0.1:8080; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 error_log syslog:server=127.0.0.1:8080; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 location /a2 { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 access_log syslog:server=127.0.0.1:8080; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 access_log syslog:server=127.0.0.1:8080; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 location /a_logf { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 access_log syslog:server=127.0.0.1:8080 logf; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 } |
445
62d1f96c5ff4
Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
408
diff
changeset
|
92 location /if { |
62d1f96c5ff4
Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
408
diff
changeset
|
93 access_log syslog:server=127.0.0.1:8085 logf if=$arg_logme; |
62d1f96c5ff4
Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
408
diff
changeset
|
94 } |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 |
771
abe795720deb
Tests: added test for syslog nohostname parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
96 location /nohostname { |
abe795720deb
Tests: added test for syslog nohostname parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
97 access_log syslog:server=127.0.0.1:8080,nohostname; |
abe795720deb
Tests: added test for syslog nohostname parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
98 } |
abe795720deb
Tests: added test for syslog nohostname parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
99 |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 location /debug { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 limit_req zone=one; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 error_log syslog:server=127.0.0.1:8080 debug; |
507 | 103 } |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 location /info { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 limit_req zone=one; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 limit_req_log_level info; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 error_log syslog:server=127.0.0.1:8080 info; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 location /notice { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 limit_req zone=one; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 limit_req_log_level notice; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 error_log syslog:server=127.0.0.1:8080 notice; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 location /warn { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 limit_req zone=one; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 limit_req_log_level warn; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 error_log syslog:server=127.0.0.1:8080 warn; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
118 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
119 location /error { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 limit_req zone=one; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
121 limit_req_log_level error; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
122 error_log syslog:server=127.0.0.1:8080; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
123 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
124 location /low { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
125 error_log syslog:server=127.0.0.1:8080 warn; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
126 error_log syslog:server=127.0.0.1:8080; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 location /dup { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
129 error_log syslog:server=127.0.0.1:8080; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
130 error_log syslog:server=127.0.0.1:8080; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
131 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
132 location /high { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
133 error_log syslog:server=127.0.0.1:8080 emerg; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
134 error_log syslog:server=127.0.0.1:8080; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
135 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
136 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
137 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
138 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
139 EOF |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
140 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
141 $t->run_daemon(\&syslog_daemon, 8083, $t, 's_glob.log'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
142 $t->run_daemon(\&syslog_daemon, 8084, $t, 's_http.log'); |
445
62d1f96c5ff4
Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
408
diff
changeset
|
143 $t->run_daemon(\&syslog_daemon, 8085, $t, 's_if.log'); |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
144 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
145 $t->waitforfile($t->testdir . '/s_glob.log'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
146 $t->waitforfile($t->testdir . '/s_http.log'); |
445
62d1f96c5ff4
Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
408
diff
changeset
|
147 $t->waitforfile($t->testdir . '/s_if.log'); |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
148 |
771
abe795720deb
Tests: added test for syslog nohostname parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
149 $t->try_run('no syslog nohostname')->plan(59); |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
150 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
151 ############################################################################### |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
152 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
153 parse_syslog_message('error_log', get_syslog('/e')); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
154 parse_syslog_message('access_log', get_syslog('/a')); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
155 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
156 like(get_syslog('/ef'), qr/^<11>/, 'error_log facility'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
157 like(get_syslog('/es'), qr/^<187>/, 'error_log severity'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
158 like(get_syslog('/et'), qr/SEETHIS:/, 'error_log tag'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
159 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
160 like(get_syslog('/af'), qr/^<14>/, 'access_log facility'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
161 like(get_syslog('/as'), qr/^<185>/, 'access_log severity'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
162 like(get_syslog('/at'), qr/SEETHIS:/, 'access_log tag'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
163 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
164 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
165 like(get_syslog('/e'), |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
166 qr/nginx: \d{4}\/\d{2}\/\d{2} \d{2}:\d{2}:\d{2} \[error\]/, |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
167 'error_log format'); |
445
62d1f96c5ff4
Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
408
diff
changeset
|
168 like(get_syslog('/a_logf'), qr/nginx: \/a_logf:404$/, 'access_log log_format'); |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
169 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
170 my @lines = split /<\d+>/, get_syslog('/a2'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
171 is($lines[1], $lines[2], 'access_log many'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
172 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
173 @lines = split /<\d+>/, get_syslog('/e2'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
174 is($lines[1], $lines[2], 'error_log many'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
175 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
176 # error_log log levels |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
177 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
178 SKIP: { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
179 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
180 skip "no --with-debug", 1 unless $t->has_module('--with-debug'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
181 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
182 isnt(syslog_lines('/debug', '[debug]'), 0, 'debug'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
183 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
184 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
185 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
186 # charge limit_req |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
187 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
188 get_syslog('/info'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
189 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
190 is(syslog_lines('/info', '[info]'), 1, 'info'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
191 is(syslog_lines('/notice', '[notice]'), 1, 'notice'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
192 is(syslog_lines('/warn', '[warn]'), 1, 'warn'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
193 is(syslog_lines('/error', '[error]'), 1, 'error'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
194 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
195 # count log messages emitted with various error_log levels |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
196 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
197 is(syslog_lines('/low', '[error]'), 2, 'low'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
198 is(syslog_lines('/dup', '[error]'), 2, 'dup'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
199 is(syslog_lines('/high', '[error'), 1, 'high'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
200 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
201 # check for the presence of the syslog messages in the global and http contexts |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
202 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
203 is_deeply(levels($t, 's_glob.log'), levels($t, 'f_glob.log'), 'master syslog'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
204 is_deeply(levels($t, 's_http.log'), levels($t, 'f_http.log'), 'http syslog'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
205 |
445
62d1f96c5ff4
Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
408
diff
changeset
|
206 http_get('/if'); |
62d1f96c5ff4
Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
408
diff
changeset
|
207 http_get('/if/empty?logme='); |
62d1f96c5ff4
Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
408
diff
changeset
|
208 http_get('/if/zero?logme=0'); |
62d1f96c5ff4
Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
408
diff
changeset
|
209 http_get('/if/good?logme=1'); |
62d1f96c5ff4
Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
408
diff
changeset
|
210 http_get('/if/work?logme=yes'); |
62d1f96c5ff4
Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
408
diff
changeset
|
211 |
62d1f96c5ff4
Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
408
diff
changeset
|
212 get_syslog('/a'); |
62d1f96c5ff4
Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
408
diff
changeset
|
213 |
467
43e05ac6c23c
Tests: the read_file function added in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents:
466
diff
changeset
|
214 like($t->read_file('s_if.log'), qr/good:404.*work:404/s, 'syslog if success'); |
43e05ac6c23c
Tests: the read_file function added in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents:
466
diff
changeset
|
215 unlike($t->read_file('s_if.log'), qr/(if:|empty:|zero:)404/, 'syslog if fail'); |
445
62d1f96c5ff4
Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
408
diff
changeset
|
216 |
771
abe795720deb
Tests: added test for syslog nohostname parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
217 like(get_syslog('/nohostname'), |
abe795720deb
Tests: added test for syslog nohostname parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
218 qr/^<(\d{1,3})> # PRI |
abe795720deb
Tests: added test for syslog nohostname parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
219 ([A-Z][a-z]{2})\s # mon |
abe795720deb
Tests: added test for syslog nohostname parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
220 ([ \d]\d)\s(\d{2}):(\d{2}):(\d{2})\s # date |
abe795720deb
Tests: added test for syslog nohostname parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
221 (\w{1,32}):\s # tag |
abe795720deb
Tests: added test for syslog nohostname parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
222 (.*)/x, # MSG |
abe795720deb
Tests: added test for syslog nohostname parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
223 'nohostname'); |
abe795720deb
Tests: added test for syslog nohostname parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
224 |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
225 ############################################################################### |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
226 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
227 sub syslog_lines { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
228 my ($uri, $pattern, $port) = @_; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
229 return map { $_ =~ /\Q$pattern\E/g } (get_syslog($uri, $port)); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
230 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
231 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
232 sub levels { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
233 my ($t, $file) = @_; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
234 my %levels_hash; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
235 |
467
43e05ac6c23c
Tests: the read_file function added in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents:
466
diff
changeset
|
236 map { $levels_hash{$_}++; } ($t->read_file($file) =~ /(\[\w+\])/g); |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
237 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
238 return \%levels_hash; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
239 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
240 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
241 sub get_syslog { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
242 my ($uri, $port) = @_; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
243 my ($s); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
244 my $rfd = ''; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
245 my $data = ''; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
246 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
247 $port = 8080 unless defined $port; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
248 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
249 eval { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
250 local $SIG{ALRM} = sub { die "timeout\n" }; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
251 local $SIG{PIPE} = sub { die "sigpipe\n" }; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
252 alarm(1); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
253 $s = IO::Socket::INET->new( |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
254 Proto => 'udp', |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
255 LocalAddr => "127.0.0.1:$port" |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
256 ); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
257 alarm(0); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
258 }; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
259 alarm(0); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
260 if ($@) { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
261 log_in("died: $@"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
262 return undef; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
263 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
264 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
265 http_get($uri); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
266 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
267 vec($rfd, fileno($s), 1) = 1; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
268 select $rfd, undef, undef, 1; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
269 while (select($rfd, undef, undef, 0.1) > 0 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
270 && vec($rfd, fileno($s), 1)) |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
271 { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
272 my $buffer; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
273 sysread($s, $buffer, 4096); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
274 $data .= $buffer; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
275 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
276 $s->close(); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
277 return $data; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
278 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
279 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
280 sub parse_syslog_message { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
281 my ($desc, $line) = @_; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
282 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
283 unless ($line) { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
284 fail("$desc timeout in receiving syslog"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
285 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
286 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
287 my @months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
288 'Sep', 'Oct', 'Nov', 'Dec'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
289 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
290 my ($pri, $mon, $mday, $hour, $minute, $sec, $host, $tag, $msg) = |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
291 $line =~ /^<(\d{1,3})> # PRI |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
292 ([A-Z][a-z]{2})\s # mon |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
293 ([ \d]\d)\s(\d{2}):(\d{2}):(\d{2})\s # date |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
294 ([\S]*)\s # host |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
295 (\w{1,32}):\s # tag |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
296 (.*)/x; # MSG |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
297 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
298 my $sev = $pri & 0x07; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
299 my $fac = ($pri & 0x03f8) >> 3; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
300 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
301 ok(defined($pri), "$desc has PRI"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
302 ok($sev >= 0 && $sev <= 7, "$desc valid severity"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
303 ok($fac >= 0 && $fac < 24, "$desc valid facility"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
304 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
305 ok(defined($mon), "$desc has month"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
306 ok((grep $mon, @months), "$desc valid month"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
307 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
308 ok(defined($mday), "$desc has day"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
309 ok($mday <= 31, "$desc valid day"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
310 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
311 ok(defined($hour), "$desc has hour"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
312 ok($hour < 24, "$desc valid hour"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
313 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
314 ok(defined($minute), "$desc has minutes"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
315 ok($minute < 60, "$desc valid minutes"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
316 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
317 ok(defined($sec), "$desc has seconds"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
318 ok($sec < 60, "$desc valid seconds"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
319 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
320 ok(defined($host), "$desc has host"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
321 chomp(my $hostname = lc `hostname`); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
322 is($host , $hostname, "$desc valid host"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
323 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
324 ok(defined($tag), "$desc has tag"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
325 like($tag, qr'\w+', "$desc valid tag"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
326 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
327 ok(length($msg) > 0, "$desc valid CONTENT"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
328 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
329 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
330 ############################################################################### |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
331 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
332 sub syslog_daemon { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
333 my ($port, $t, $file) = @_; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
334 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
335 my $s = IO::Socket::INET->new( |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
336 Proto => 'udp', |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
337 LocalAddr => "127.0.0.1:$port" |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
338 ); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
339 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
340 open my $fh, '>', $t->testdir() . '/' . $file; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
341 select $fh; $| = 1; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
342 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
343 while (1) { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
344 my $buffer; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
345 $s->recv($buffer, 4096); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
346 print $fh $buffer . "\n"; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
347 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
348 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
349 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
350 ############################################################################### |