Debian Codegraph @

doc/schemas/logstash/logstash-radius.conf

raw
1 # logstash configuration to process RADIUS detail files
2 #
3 # Matthew Newton
4 # April 2019
5 #
6 # This config has been tested with logstash version 6.7.0
7 #
8 # RADIUS "detail" files are textual representations of the RADIUS
9 # packets, and are written to disk by e.g. FreeRADIUS. They look
10 # something like the following, with the timestamp on the first
11 # line then all attributes/values tab-indented.
12 #
13 # Tue Mar 10 15:32:24 2015
14 # Packet-Type = Access-Request
15 # User-Name = "[email protected]"
16 # Calling-Station-Id = "01-02-03-04-05-06"
17 # Called-Station-Id = "aa-bb-cc-dd-ee-ff:myssid"
18 # NAS-Port = 10
19 # NAS-IP-Address = 10.9.0.4
20 # NAS-Identifier = "Wireless-Controller-1"
21 # Service-Type = Framed-User
22 # NAS-Port-Type = Wireless-802.11
23 #
24
25
26
27 # Example input - read data from a file. For example, to read in a
28 # detail file with this input you could use:
29 #
30 # # /usr/share/logstash/bin/logstash --path.settings=/etc/logstash -f logstash-radius.conf --log.level=debug
31 #
32
33 input {
34 file {
35 path => "/var/log/radius/radacct/*/detail-*"
36 exclude => "*.gz"
37
38 # Note when testing that logstash will remember where
39 # it got to and continue from there.
40 start_position => "beginning"
41
42 # Set the type, for below.
43 type => radiusdetail
44
45 # It is preferable to use a log feeder that can join
46 # multiple lines together, rather than using multiline
47 # here. For an example, see the log-courier
48 # configuration in this directory.
49
50 # If you didn't read the above, go back and read it again.
51
52 # If that is not possible you may be able to use the
53 # following section. Note that if you are using the
54 # "stdin" input, the file is chunked into 16k blobs,
55 # so every 16k a detail record is likely to be chopped
56 # in half. If you are using the "file" input (as in this
57 # example), the blank links between records are not
58 # passed through so the regex here has to be aware of
59 # that. Basically, do multiline as early as possible
60 # in your log feeder client not here and you'll avoid
61 # most issues that are likely to come up.
62
63 codec => multiline {
64 pattern => "^\t"
65 negate => false
66 what => "previous"
67 }
68
69 # If you really want to use the "stdin" input, this
70 # will work better, but be aware of the comments
71 # above.
72
73 #codec => multiline {
74 # pattern => "^[A-Z\t]"
75 # negate => false
76 # what => "next"
77 #}
78 }
79 }
80
81 # Moving into production will likely need something more reliable.
82 # There are many input methods, an example here using log-courier
83 # (which supports client-site multiline processing and does not
84 # lose log events if logstash is restarted). You could also
85 # investigate e.g. filebeat from Elastic.
86
87 # input {
88 # courier {
89 # port => 5140
90 # transport => "tcp"
91 #
92 # # Don't set the type here, as it's set in the
93 # # log-courier config instead.
94 # #type => radiusdetail
95 # }
96 # }
97
98
99
100 # Filter stage. Here we take the raw logs and process them into
101 # something structured ready to index. Each attribute is stored as
102 # a separate field in the output document.
103
104 filter {
105
106 if [type] == "radiusdetail" {
107
108 # Pull off the timestamp at the start of the
109 # detail record. Note there may be additional data
110 # after it that has been added by the local admin,
111 # so stop at a newline OR a tab.
112
113 grok {
114 match => [ "message", "^(?<timestamp>[^\n\t]+)[\n\t]" ]
115 }
116
117 # Create the @timestamp field.
118
119 date {
120 match => [ "timestamp", "EEE MMM dd HH:mm:ss yyyy",
121 "EEE MMM d HH:mm:ss yyyy" ]
122 }
123
124 # Split the attributes and values into fields.
125 # This is the bulk of processing that adds all of
126 # the RADIUS attributes as elasticsearch fields.
127
128 # Note issue https://github.com/logstash-plugins/logstash-filter-kv/issues/10
129 # currently means that all spaces will be stripped
130 # from all fields. If this is a problem, adjust the
131 # trim setting.
132
133 kv {
134 field_split => "\n"
135 source => "message"
136 trim_value => "\" "
137 trim_key => "\t "
138 }
139
140 # Now we try and add some useful additional
141 # information. If certain fields can be broken
142 # down into components then do that here and add
143 # the data as sub-fields. For example,
144 # Called-Station-Id might be able to be broken
145 # down to Called-Station-Id_mac and Called-Station-Id_ssid
146 # on some wireless systems, or to _ip and _port
147 # with a VPN.
148
149 # Multiple calls to grok otherwise it can stop
150 # processing once it has matched one field, but
151 # e.g. you want to pull both IP and port out of
152 # the same field in two different regex's.
153
154 # Pull out some IP addresses as field_ip:
155
156 grok {
157 break_on_match => false
158 tag_on_failure => []
159 match => [
160 "Framed-IP-Address", "^(?<Framed-IP-Address_ip>\d+\.\d+\.\d+\.\d+$)",
161 "NAS-IP-Address", "^(?<NAS-IP-Address_ip>\d+\.\d+\.\d+\.\d+$)",
162 "Calling-Station-Id", "^(?<Calling-Station-Id_ip>\d+\.\d+\.\d+\.\d+)",
163 "Called-Station-Id", "^(?<Called-Station-Id_ip>\d+\.\d+\.\d+\.\d+)"
164 ]
165 }
166
167 # Split User-Name, Operator-Name, and pull out
168 # some IP ports if they are there:
169
170 grok {
171 break_on_match => false
172 tag_on_failure => []
173 match => [
174 "User-Name", "^(?<User-Name_username>[^@]+)?(?:@(?<User-Name_realm>[^@]+))$",
175 "Operator-Name", "^(?<Operator-Name_id>.)(?<Operator-Name_value>.+)$",
176
177 "Calling-Station-Id", "\[(?<Calling-Station-Id_port>\d+)\]$",
178 "Called-Station-Id", "\[(?<Called-Station-Id_port>\d+)\]$"
179 ]
180 }
181
182 # Extract MAC addresses (and SSIDs if there).
183 # MAC address matching here is lazy, but should be
184 # good enough.
185
186 grok {
187 break_on_match => false
188 tag_on_failure => []
189 match => [
190 "Calling-Station-Id", "^(?<Calling-Station-Id_mac>[a-fA-F0-9:-]{17})$",
191 "Calling-Station-Id", "^(?<Calling-Station-Id_mac>[a-fA-F0-9\.]{14})$",
192 "Calling-Station-Id", "^(?<Calling-Station-Id_mac>[a-fA-F0-9]{12})$",
193
194 "Called-Station-Id", "^(?<Called-Station-Id_mac>[a-fA-F0-9:-]{17})(?::(?<Called-Station-Id_ssid>.*))?$",
195 "Called-Station-Id", "^(?<Called-Station-Id_mac>[a-fA-F0-9\.]{14})(?::(?<Called-Station-Id_ssid>.*))?$",
196 "Called-Station-Id", "^(?<Called-Station-Id_mac>[a-fA-F0-9]{12})(?::(?<Called-Station-Id_ssid>.*))?$"
197 ]
198 }
199
200 # With the optional sanitize_mac plugin, it's
201 # possible to make sure all MAC addresses look the
202 # same, which has obvious benefits.
203 #
204 # https://github.com/mcnewton/logstash-filter-sanitize_mac
205
206 # sanitize_mac {
207 # match => {
208 # "Called-Station-Id_mac" => "Called-Station-Id_mac"
209 # "Calling-Station-Id_mac" => "Calling-Station-Id_mac"
210 # }
211 # separator => "-"
212 # fixcase => "lower"
213 # }
214
215
216 # Gigawords presents an issue because the 64-bit
217 # value is split across two attributes. Combine
218 # them both back into a single attribute so that
219 # the full value is available to use.
220
221 if ([Acct-Input-Octets]) {
222 ruby {
223 code => "event.set('Acct-Input-Octets_long', event.get('Acct-Input-Octets').to_i +
224 (event.get('Acct-Input-Gigawords') ? (event.get('Acct-Input-Gigawords').to_i * (2**32)) : 0))"
225 }
226 }
227
228 if ([Acct-Output-Octets]) {
229 ruby {
230 code => "event.set('Acct-Output-Octets_long', event.get('Acct-Output-Octets').to_i +
231 (event.get('Acct-Output-Gigawords') ? (event.get('Acct-Output-Gigawords').to_i * (2**32)) : 0))"
232 }
233 }
234
235
236 # Remove the original "message" field.
237
238 mutate {
239 remove_field => ["message"]
240 }
241
242 }
243 }
244
245
246
247 # Output data to the local elasticsearch cluster
248 # using type "detail" in index "radius-DATE".
249
250 output {
251 if [type] == "radiusdetail" {
252 elasticsearch {
253 index => "radius-%{+YYYY.MM.dd}"
254 }
255 }
256 }