Rsyslog » История » Версия 5
Константин Пильник, 2022-12-01 17:10
1 | 5 | Константин Пильник | h1. nginx -> rsyslog -> rsyslog-elasticsearch -> elasticsearch |
---|---|---|---|
2 | |||
3 | <pre><code class="perl"> |
||
4 | module(load="omelasticsearch") |
||
5 | module(load="mmjsonparse") |
||
6 | |||
7 | template(name="template_nginx_yyyy_mm_dd" type="list") { |
||
8 | constant(value="nginx-") |
||
9 | property(name="timereported" dateformat="year") |
||
10 | constant(value=".") |
||
11 | property(name="timereported" dateformat="month") |
||
12 | constant(value=".") |
||
13 | property(name="timereported" dateformat="day") |
||
14 | } |
||
15 | |||
16 | template(name="template_msg_to_json" type="list") { |
||
17 | property(name="$!msg") |
||
18 | } |
||
19 | |||
20 | if ($programname == "nginx") then { |
||
21 | action(type="mmjsonparse") |
||
22 | action(type="omelasticsearch" |
||
23 | server=["https://es1.domain.tld:443", "https://es2.domain.tld:443", "https://es3.domain.tld:443"] |
||
24 | uid="elastic" |
||
25 | pwd="secret" |
||
26 | template="template_msg_to_json" |
||
27 | dynSearchIndex="on" |
||
28 | searchIndex="template_nginx_yyyy_mm_dd" |
||
29 | searchType="nginx" |
||
30 | bulkmode="on" |
||
31 | maxbytes="100m" |
||
32 | queue.type="linkedlist" |
||
33 | queue.size="5000" |
||
34 | queue.dequeuebatchsize="300" |
||
35 | action.resumeretrycount="-1" |
||
36 | ) |
||
37 | } |
||
38 | </code></pre> |
||
39 | |||
40 | h4. nginx/conf.d/log_format.conf |
||
41 | |||
42 | <pre><code class="perl"> |
||
43 | # json for elastic |
||
44 | # access_log syslog:server=unix:/dev/log,tag=nginx,nohostname default_json; |
||
45 | log_format default_json escape=json |
||
46 | '{' |
||
47 | '"args":"$args",' |
||
48 | '"bytes_sent":"$bytes_sent",' |
||
49 | '"connection": "$connection",' |
||
50 | '"connection_requests": "$connection_requests",' |
||
51 | '"hostname": "$hostname",' |
||
52 | '"http_referrer":"$http_referer",' |
||
53 | '"http_user_agent":"$http_user_agent",' |
||
54 | '"remote_addr":"$remote_addr",' |
||
55 | '"remote_port":"$remote_port",' |
||
56 | '"remote_user":"$remote_user",' |
||
57 | '"request":"$request",' |
||
58 | '"request_length":"$request_length",' |
||
59 | '"request_method":"$request_method",' |
||
60 | '"request_time":"$request_time",' |
||
61 | '"scheme": "$scheme",' |
||
62 | '"server_name": "$server_name",' |
||
63 | '"server_protocol": "$server_protocol",' |
||
64 | '"status": "$status",' |
||
65 | '"time_local":"$time_iso8601",' |
||
66 | '"upstream_addr": "$upstream_addr",' |
||
67 | '"upstream_response_time": "$upstream_response_time",' |
||
68 | '"upstream_status": "$upstream_status",' |
||
69 | '"uri": "$uri"' |
||
70 | '}'; |
||
71 | </code></pre> |
||
72 | |||
73 | 1 | Константин Пильник | h1. rsyslog -> elasticsearch |
74 | |||
75 | <pre><code class="perl"> |
||
76 | # elasticsearch |
||
77 | module(load="omelasticsearch") |
||
78 | template(name="elastic_date_template" type="list") { |
||
79 | constant(value="rsyslog-") |
||
80 | property(name="timereported" dateformat="year") |
||
81 | constant(value=".") |
||
82 | property(name="timereported" dateformat="month") |
||
83 | constant(value=".") |
||
84 | property(name="timereported" dateformat="day") |
||
85 | } |
||
86 | |||
87 | template(name="elastic_msg_template" type="list" option.json="on") { |
||
88 | constant(value="{") |
||
89 | constant(value="\"timestamp\":\"") property(name="timereported" dateFormat="rfc3339") |
||
90 | constant(value="\",\"message\":\"") property(name="msg") |
||
91 | constant(value="\",\"host\":\"") property(name="hostname") |
||
92 | constant(value="\",\"severity\":\"") property(name="syslogseverity-text") |
||
93 | constant(value="\",\"facility\":\"") property(name="syslogfacility-text") |
||
94 | constant(value="\",\"syslogtag\":\"") property(name="syslogtag") |
||
95 | constant(value="\",\"programname\":\"") property(name="programname") |
||
96 | constant(value="\",\"procid\":\"") property(name="procid") |
||
97 | constant(value="\"}") |
||
98 | } |
||
99 | |||
100 | action( |
||
101 | type="omelasticsearch" |
||
102 | server="127.0.0.1" |
||
103 | serverport="9200" |
||
104 | 4 | Константин Пильник | usehttps="off" |
105 | 1 | Константин Пильник | uid="elastic" |
106 | pwd="mypass1" |
||
107 | template="elastic_msg_template" |
||
108 | dynSearchIndex="on" |
||
109 | searchIndex="elastic_date_template" |
||
110 | 2 | Константин Пильник | searchType="rsyslog" |
111 | 1 | Константин Пильник | bulkmode="on" |
112 | maxbytes="100m" |
||
113 | queue.type="linkedlist" |
||
114 | queue.size="5000" |
||
115 | queue.dequeuebatchsize="300" |
||
116 | action.resumeretrycount="-1" |
||
117 | ) |
||
118 | </code></pre> |