Mercurial > hg > nginx-tests
annotate syslog.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | b61e820caa83 |
children |
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 |
1127
6620cd57a96a
Tests: replaced all occurrences of vec/select API with IO::Select.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
15 use IO::Select; |
1600
b61e820caa83
Tests: using Sys::Hostname to get hostname in a portable way.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1580
diff
changeset
|
16 use Sys::Hostname; |
1127
6620cd57a96a
Tests: replaced all occurrences of vec/select API with IO::Select.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
17 |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 BEGIN { use FindBin; chdir($FindBin::Bin); } |
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 use lib 'lib'; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 use Test::Nginx; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 ############################################################################### |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 select STDERR; $| = 1; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 select STDOUT; $| = 1; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
408
82b15c81978e
Tests: skipped tests on win32 that use shared memory.
Sergey Kandaurov <pluknet@nginx.com>
parents:
404
diff
changeset
|
28 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
|
29 |
1580
9e142c0e34b2
Tests: allowed syslog messages arrival out-of-order.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1329
diff
changeset
|
30 my $t = Test::Nginx->new()->has(qw/http limit_req/)->plan(62); |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
771
abe795720deb
Tests: added test for syslog nohostname parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
32 $t->write_file_expand('nginx.conf', <<'EOF'); |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 %%TEST_GLOBALS%% |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1128
diff
changeset
|
36 error_log syslog:server=127.0.0.1:%%PORT_8981_UDP%% info; |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 error_log %%TESTDIR%%/f_glob.log info; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 daemon off; |
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 events { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 http { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 %%TEST_GLOBALS_HTTP%% |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 |
503
071e8941e3bf
Tests: reduce shared memory zone sizes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
467
diff
changeset
|
47 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
|
48 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 log_format empty ""; |
445
62d1f96c5ff4
Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
408
diff
changeset
|
50 log_format logf "$uri:$status"; |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1128
diff
changeset
|
52 error_log syslog:server=127.0.0.1:%%PORT_8982_UDP%% info; |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 error_log %%TESTDIR%%/f_http.log info; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
56 listen 127.0.0.1:8080; |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 server_name localhost; |
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 /e { |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1128
diff
changeset
|
60 error_log syslog:server=127.0.0.1:%%PORT_8984_UDP%%; |
404
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 /a { |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1128
diff
changeset
|
63 access_log syslog:server=127.0.0.1:%%PORT_8984_UDP%%; |
404
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 /ef { |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1128
diff
changeset
|
66 error_log syslog:server=127.0.0.1:%%PORT_8984_UDP%%,facility=user; |
404
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 /es { |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1128
diff
changeset
|
69 error_log syslog:server=127.0.0.1:%%PORT_8984_UDP%%,severity=alert; |
404
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 /et { |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1128
diff
changeset
|
72 error_log syslog:server=127.0.0.1:%%PORT_8984_UDP%%,tag=SEETHIS; |
404
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 /af { |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1128
diff
changeset
|
75 access_log syslog:server=127.0.0.1:%%PORT_8984_UDP%%,facility=user; |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 location /as { |
788
1f48ed26b49a
Tests: interchanged syslog parameters for better coverage.
Sergey Kandaurov <pluknet@nginx.com>
parents:
771
diff
changeset
|
78 # put severity inside to catch possible parsing programming errors |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1128
diff
changeset
|
79 access_log syslog:severity=alert,server=127.0.0.1:%%PORT_8984_UDP%%; |
404
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 /at { |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1128
diff
changeset
|
82 access_log syslog:server=127.0.0.1:%%PORT_8984_UDP%%,tag=SEETHIS; |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 location /e2 { |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1128
diff
changeset
|
85 error_log syslog:server=127.0.0.1:%%PORT_8984_UDP%%; |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1128
diff
changeset
|
86 error_log syslog:server=127.0.0.1:%%PORT_8984_UDP%%; |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 location /a2 { |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1128
diff
changeset
|
89 access_log syslog:server=127.0.0.1:%%PORT_8984_UDP%%; |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1128
diff
changeset
|
90 access_log syslog:server=127.0.0.1:%%PORT_8984_UDP%%; |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 location /a_logf { |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1128
diff
changeset
|
93 access_log syslog:server=127.0.0.1:%%PORT_8984_UDP%% logf; |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 } |
445
62d1f96c5ff4
Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
408
diff
changeset
|
95 location /if { |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1128
diff
changeset
|
96 access_log syslog:server=127.0.0.1:%%PORT_8983_UDP%% logf |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
921
diff
changeset
|
97 if=$arg_logme; |
445
62d1f96c5ff4
Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
408
diff
changeset
|
98 } |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 |
771
abe795720deb
Tests: added test for syslog nohostname parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
100 location /nohostname { |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1128
diff
changeset
|
101 access_log syslog:server=127.0.0.1:%%PORT_8984_UDP%%,nohostname; |
771
abe795720deb
Tests: added test for syslog nohostname parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
102 } |
abe795720deb
Tests: added test for syslog nohostname parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
103 |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 location /debug { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 limit_req zone=one; |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1128
diff
changeset
|
106 error_log syslog:server=127.0.0.1:%%PORT_8984_UDP%% debug; |
507 | 107 } |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 location /info { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 limit_req zone=one; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 limit_req_log_level info; |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1128
diff
changeset
|
111 error_log syslog:server=127.0.0.1:%%PORT_8984_UDP%% info; |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 location /notice { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 limit_req zone=one; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 limit_req_log_level notice; |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1128
diff
changeset
|
116 error_log syslog:server=127.0.0.1:%%PORT_8984_UDP%% notice; |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
118 location /warn { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
119 limit_req zone=one; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 limit_req_log_level warn; |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1128
diff
changeset
|
121 error_log syslog:server=127.0.0.1:%%PORT_8984_UDP%% warn; |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
122 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
123 location /error { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
124 limit_req zone=one; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
125 limit_req_log_level error; |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1128
diff
changeset
|
126 error_log syslog:server=127.0.0.1:%%PORT_8984_UDP%%; |
404
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 /low { |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1128
diff
changeset
|
129 error_log syslog:server=127.0.0.1:%%PORT_8984_UDP%% warn; |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1128
diff
changeset
|
130 error_log syslog:server=127.0.0.1:%%PORT_8984_UDP%%; |
404
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 /dup { |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1128
diff
changeset
|
133 error_log syslog:server=127.0.0.1:%%PORT_8984_UDP%%; |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1128
diff
changeset
|
134 error_log syslog:server=127.0.0.1:%%PORT_8984_UDP%%; |
404
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 location /high { |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1128
diff
changeset
|
137 error_log syslog:server=127.0.0.1:%%PORT_8984_UDP%% emerg; |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1128
diff
changeset
|
138 error_log syslog:server=127.0.0.1:%%PORT_8984_UDP%%; |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
139 } |
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 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
142 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
143 EOF |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
144 |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1128
diff
changeset
|
145 $t->run_daemon(\&syslog_daemon, port(8981), $t, 's_glob.log'); |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1128
diff
changeset
|
146 $t->run_daemon(\&syslog_daemon, port(8982), $t, 's_http.log'); |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1128
diff
changeset
|
147 $t->run_daemon(\&syslog_daemon, port(8983), $t, 's_if.log'); |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
148 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
149 $t->waitforfile($t->testdir . '/s_glob.log'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
150 $t->waitforfile($t->testdir . '/s_http.log'); |
445
62d1f96c5ff4
Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
408
diff
changeset
|
151 $t->waitforfile($t->testdir . '/s_if.log'); |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
152 |
1020
196d33c2bb45
Tests: removed TODO and try_run() checks for legacy versions.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
153 $t->run(); |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
154 |
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 |
1128
bef8be8a6224
Tests: avoid reopening a receiving UDP socket in syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1127
diff
changeset
|
157 my $s = IO::Socket::INET->new( |
bef8be8a6224
Tests: avoid reopening a receiving UDP socket in syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1127
diff
changeset
|
158 Proto => 'udp', |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1128
diff
changeset
|
159 LocalAddr => '127.0.0.1:' . port(8984) |
1128
bef8be8a6224
Tests: avoid reopening a receiving UDP socket in syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1127
diff
changeset
|
160 ) |
bef8be8a6224
Tests: avoid reopening a receiving UDP socket in syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1127
diff
changeset
|
161 or die "Can't open syslog socket: $!"; |
bef8be8a6224
Tests: avoid reopening a receiving UDP socket in syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1127
diff
changeset
|
162 |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
163 parse_syslog_message('error_log', get_syslog('/e')); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
164 parse_syslog_message('access_log', get_syslog('/a')); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
165 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
166 like(get_syslog('/ef'), qr/^<11>/, 'error_log facility'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
167 like(get_syslog('/es'), qr/^<187>/, 'error_log severity'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
168 like(get_syslog('/et'), qr/SEETHIS:/, 'error_log tag'); |
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 like(get_syslog('/af'), qr/^<14>/, 'access_log facility'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
171 like(get_syslog('/as'), qr/^<185>/, 'access_log severity'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
172 like(get_syslog('/at'), qr/SEETHIS:/, 'access_log tag'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
173 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
174 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
175 like(get_syslog('/e'), |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
176 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
|
177 'error_log format'); |
445
62d1f96c5ff4
Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
408
diff
changeset
|
178 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
|
179 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
180 my @lines = split /<\d+>/, get_syslog('/a2'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
181 is($lines[1], $lines[2], 'access_log many'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
182 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
183 @lines = split /<\d+>/, get_syslog('/e2'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
184 is($lines[1], $lines[2], 'error_log many'); |
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 # error_log log levels |
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 SKIP: { |
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 skip "no --with-debug", 1 unless $t->has_module('--with-debug'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
191 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
192 isnt(syslog_lines('/debug', '[debug]'), 0, 'debug'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
193 |
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 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
196 # charge limit_req |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
197 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
198 get_syslog('/info'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
199 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
200 is(syslog_lines('/info', '[info]'), 1, 'info'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
201 is(syslog_lines('/notice', '[notice]'), 1, 'notice'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
202 is(syslog_lines('/warn', '[warn]'), 1, 'warn'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
203 is(syslog_lines('/error', '[error]'), 1, 'error'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
204 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
205 # count log messages emitted with various error_log levels |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
206 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
207 is(syslog_lines('/low', '[error]'), 2, 'low'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
208 is(syslog_lines('/dup', '[error]'), 2, 'dup'); |
921
bc9e519ab3bc
Tests: added missing character in regex in syslog.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
788
diff
changeset
|
209 is(syslog_lines('/high', '[error]'), 1, 'high'); |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
210 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
211 # 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
|
212 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
213 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
|
214 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
|
215 |
445
62d1f96c5ff4
Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
408
diff
changeset
|
216 http_get('/if'); |
62d1f96c5ff4
Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
408
diff
changeset
|
217 http_get('/if/empty?logme='); |
62d1f96c5ff4
Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
408
diff
changeset
|
218 http_get('/if/zero?logme=0'); |
62d1f96c5ff4
Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
408
diff
changeset
|
219 http_get('/if/good?logme=1'); |
62d1f96c5ff4
Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
408
diff
changeset
|
220 http_get('/if/work?logme=yes'); |
62d1f96c5ff4
Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
408
diff
changeset
|
221 |
62d1f96c5ff4
Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
408
diff
changeset
|
222 get_syslog('/a'); |
62d1f96c5ff4
Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
408
diff
changeset
|
223 |
1580
9e142c0e34b2
Tests: allowed syslog messages arrival out-of-order.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1329
diff
changeset
|
224 like($t->read_file('s_if.log'), qr/good:404/s, 'syslog if success'); |
9e142c0e34b2
Tests: allowed syslog messages arrival out-of-order.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1329
diff
changeset
|
225 like($t->read_file('s_if.log'), qr/work:404/s, 'syslog if success 2'); |
467
43e05ac6c23c
Tests: the read_file function added in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents:
466
diff
changeset
|
226 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
|
227 |
771
abe795720deb
Tests: added test for syslog nohostname parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
228 like(get_syslog('/nohostname'), |
abe795720deb
Tests: added test for syslog nohostname parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
229 qr/^<(\d{1,3})> # PRI |
abe795720deb
Tests: added test for syslog nohostname parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
230 ([A-Z][a-z]{2})\s # mon |
abe795720deb
Tests: added test for syslog nohostname parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
231 ([ \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
|
232 (\w{1,32}):\s # tag |
abe795720deb
Tests: added test for syslog nohostname parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
233 (.*)/x, # MSG |
abe795720deb
Tests: added test for syslog nohostname parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
234 'nohostname'); |
abe795720deb
Tests: added test for syslog nohostname parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
235 |
1326
fda0bf1cc601
Tests: syslog send error handling test added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
236 # send error handling |
fda0bf1cc601
Tests: syslog send error handling test added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
237 |
fda0bf1cc601
Tests: syslog send error handling test added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
238 ok(get_syslog('/a'), 'send success'); |
fda0bf1cc601
Tests: syslog send error handling test added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
239 |
fda0bf1cc601
Tests: syslog send error handling test added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
240 close $s; |
fda0bf1cc601
Tests: syslog send error handling test added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
241 |
fda0bf1cc601
Tests: syslog send error handling test added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
242 get_syslog('/a'); |
fda0bf1cc601
Tests: syslog send error handling test added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
243 get_syslog('/a'); |
fda0bf1cc601
Tests: syslog send error handling test added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
244 |
fda0bf1cc601
Tests: syslog send error handling test added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
245 $s = IO::Socket::INET->new( |
fda0bf1cc601
Tests: syslog send error handling test added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
246 Proto => 'udp', |
fda0bf1cc601
Tests: syslog send error handling test added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
247 LocalAddr => '127.0.0.1:' . port(8984) |
fda0bf1cc601
Tests: syslog send error handling test added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
248 ) |
fda0bf1cc601
Tests: syslog send error handling test added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
249 or die "Can't open syslog socket: $!"; |
fda0bf1cc601
Tests: syslog send error handling test added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
250 |
fda0bf1cc601
Tests: syslog send error handling test added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
251 ok(get_syslog('/a'), 'send error - recover'); |
fda0bf1cc601
Tests: syslog send error handling test added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
252 |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
253 ############################################################################### |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
254 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
255 sub syslog_lines { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
256 my ($uri, $pattern, $port) = @_; |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
921
diff
changeset
|
257 return map { $_ =~ /\Q$pattern\E/g } (get_syslog($uri)); |
404
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 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
260 sub levels { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
261 my ($t, $file) = @_; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
262 my %levels_hash; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
263 |
467
43e05ac6c23c
Tests: the read_file function added in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents:
466
diff
changeset
|
264 map { $levels_hash{$_}++; } ($t->read_file($file) =~ /(\[\w+\])/g); |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
265 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
266 return \%levels_hash; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
267 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
268 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
269 sub get_syslog { |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
921
diff
changeset
|
270 my ($uri) = @_; |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
271 my $data = ''; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
272 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
273 http_get($uri); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
274 |
1127
6620cd57a96a
Tests: replaced all occurrences of vec/select API with IO::Select.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
275 IO::Select->new($s)->can_read(1); |
6620cd57a96a
Tests: replaced all occurrences of vec/select API with IO::Select.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
276 while (IO::Select->new($s)->can_read(0.1)) { |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
277 my $buffer; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
278 sysread($s, $buffer, 4096); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
279 $data .= $buffer; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
280 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
281 return $data; |
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 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
284 sub parse_syslog_message { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
285 my ($desc, $line) = @_; |
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 unless ($line) { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
288 fail("$desc timeout in receiving syslog"); |
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 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
291 my @months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
292 'Sep', 'Oct', 'Nov', 'Dec'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
293 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
294 my ($pri, $mon, $mday, $hour, $minute, $sec, $host, $tag, $msg) = |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
295 $line =~ /^<(\d{1,3})> # PRI |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
296 ([A-Z][a-z]{2})\s # mon |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
297 ([ \d]\d)\s(\d{2}):(\d{2}):(\d{2})\s # date |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
298 ([\S]*)\s # host |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
299 (\w{1,32}):\s # tag |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
300 (.*)/x; # MSG |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
301 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
302 my $sev = $pri & 0x07; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
303 my $fac = ($pri & 0x03f8) >> 3; |
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($pri), "$desc has PRI"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
306 ok($sev >= 0 && $sev <= 7, "$desc valid severity"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
307 ok($fac >= 0 && $fac < 24, "$desc valid facility"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
308 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
309 ok(defined($mon), "$desc has month"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
310 ok((grep $mon, @months), "$desc valid month"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
311 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
312 ok(defined($mday), "$desc has day"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
313 ok($mday <= 31, "$desc valid day"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
314 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
315 ok(defined($hour), "$desc has hour"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
316 ok($hour < 24, "$desc valid hour"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
317 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
318 ok(defined($minute), "$desc has minutes"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
319 ok($minute < 60, "$desc valid minutes"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
320 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
321 ok(defined($sec), "$desc has seconds"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
322 ok($sec < 60, "$desc valid seconds"); |
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($host), "$desc has host"); |
1600
b61e820caa83
Tests: using Sys::Hostname to get hostname in a portable way.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1580
diff
changeset
|
325 is($host, lc(hostname()), "$desc valid host"); |
404
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(defined($tag), "$desc has tag"); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
328 like($tag, qr'\w+', "$desc valid tag"); |
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 ok(length($msg) > 0, "$desc valid CONTENT"); |
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 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
333 ############################################################################### |
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 sub syslog_daemon { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
336 my ($port, $t, $file) = @_; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
337 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
338 my $s = IO::Socket::INET->new( |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
339 Proto => 'udp', |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
340 LocalAddr => "127.0.0.1:$port" |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
341 ); |
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 open my $fh, '>', $t->testdir() . '/' . $file; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
344 select $fh; $| = 1; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
345 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
346 while (1) { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
347 my $buffer; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
348 $s->recv($buffer, 4096); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
349 print $fh $buffer . "\n"; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
350 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
351 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
352 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
353 ############################################################################### |