1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
|
<!DOCTYPE html>
<html>
<head>
<title>ProFTPD module mod_kafka</title>
</head>
<body bgcolor=white>
<hr>
<center>
<h2><b>ProFTPD module <code>mod_kafka</code></b></h2>
</center>
<hr><br>
<p>
The <code>mod_kafka</code> module enables ProFTPD support for sending log
messages, as JSON, to Kafka brokers using the
<a href="https://github.com/edenhill/librdkafka">librdkafka</a> client library.
<p>
This module is contained in the <code>mod_kafka</code> files for
ProFTPD 1.3.<i>x</i>, and is not compiled by default. Installation
instructions are discussed <a href="#Installation">here</a>. More examples
of <code>mod_kafka</code> usage can be found <a href="#Usage">here</a>.
<p>
The most current version of <code>mod_kafka</code> can be found at:
<pre>
<a href="https://github.com/Castaglia/proftpd-mod_kafka">https://github.com/Castaglia/proftpd-mod_kafka</a>
</pre>
<h2>Author</h2>
<p>
Please contact TJ Saunders <tj <i>at</i> castaglia.org> with any
questions, concerns, or suggestions regarding this module.
<h2>Directives</h2>
<ul>
<li><a href="#KafkaBroker">KafkaBroker</a>
<li><a href="#KafkaEngine">KafkaEngine</a>
<li><a href="#KafkaLog">KafkaLog</a>
<li><a href="#KafkaLogOnEvent">KafkaLogOnEvent</a>
<li><a href="#KafkaProperty">KafkaProperty</a>
</ul>
<p>
<hr>
<h3><a name="KafkaBroker">KafkaBroker</a></h3>
<strong>Syntax:</strong> Kafka <em>host[:port] ...</em><br>
<strong>Default:</strong> None<br>
<strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code><br>
<strong>Module:</strong> mod_kafka<br>
<strong>Compatibility:</strong> 1.3.6rc5 and later
<p>
The <code>KafkaServer</code> directive is used to configure the addresses/ports
of the initial Kafka brokers contacted by <code>mod_kafka</code>. For example:
<pre>
KafkaBroker 1.2.3.4 5.6.7.8:19092
</pre>
or, for an IPv6 address, make sure the IPv6 address is enclosed in square
brackets:
<pre>
KafkaBroker [::ffff:1.2.3.4]:9092
KafkaProperty broker.address.family any
</pre>
<p>
<hr>
<h3><a name="KafkaEngine">KafkaEngine</a></h3>
<strong>Syntax:</strong> KafkaEngine <em>on|off</em><br>
<strong>Default:</strong> KafkaEngine off<br>
<strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code><br>
<strong>Module:</strong> mod_kafka<br>
<strong>Compatibility:</strong> 1.3.6rc5 and later
<p>
The <code>KafkaEngine</code> directive enables or disables the
<code>mod_kafka</code> module, and thus the configuration of Kafka support for
the <code>proftpd</code> daemon.
<p>
<hr>
<h3><a name="KafkaLog">KafkaLog</a></h3>
<strong>Syntax:</strong> KafkaLog <em>path|"none"</em><br>
<strong>Default:</strong> None<br>
<strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code><br>
<strong>Module:</strong> mod_kafka<br>
<strong>Compatibility:</strong> 1.3.6rc5 and later
<p>
The <code>KafkaLog</code> directive is used to specify a log file for
<code>mod_kafka</code>'s reporting on a per-server basis. The
<em>file</em> parameter given must be the full path to the file to use for
logging.
<p>
Note that this path must <b>not</b> be to a world-writable directory and,
unless <code>AllowLogSymlinks</code> is explicitly set to <em>on</em>
(generally a bad idea), the path must <b>not</b> be a symbolic link.
<p>
<hr>
<h3><a name="KafkaLogOnEvent">KafkaLogOnEvent</a></h3>
<strong>Syntax:</strong> KafkaLogOnEvent <em>"none"|events format-name [topic ...]</em><br>
<strong>Default:</strong> None<br>
<strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code>, <code><Anonymous></code>, <code><Directory></code><br>
<strong>Module:</strong> mod_kafka<br>
<strong>Compatibility:</strong> 1.3.7rc1 and later
<p>
The <code>KafkaLogOnEvent</code> directive configures the use of Kafka for
<em>logging</em>. Whenever one of the comma-separated list of <em>events</em>
occurs, <code>mod_kafka</code> will compose a JSON object, using the
<a href="http://www.proftpd.org/docs/modules/mod_log.html#LogFormat"><code>LogFormat</code></a> named by
<em>format-name</em> as a <i>template</i> for the fields to include in the
JSON object. The JSON object of that event will then be published to a
Kafka <em>topic</em>. Multiple <code>KafkaLogOnEvent</code> directives can be
used, for different log formats for different events and different topics.
<p>
The optional <em>topic</em> parameter, if present, specifies the value to use
as the topic name. If the topic name is not provided explicitly, the configured
<em>format-name</em> is used as the topic name.
<p>
More on the use of Kafka logging, including a table showing how
<code>LogFormat</code> variables are mapped to JSON object keys can be found
<a href="#Logging">here</a>.
<p>
Example:
<pre>
LogFormat sessions "%{iso8601} %a"
KafkaLogOnEvent CONNECT,DISCONNECT sessions
</pre>
<p>
In addition to specific FTP commands, the <em>events</em> list can specify
"ALL", for logging on <b>all</b> commands. Or it can <i>include</i> the
"CONNECT" and "DISCONNECT" <i>events</i>, which can be useful for logging the
start and end times of a session. <b>Note</b> that
<code>KafkaLogOnEvent</code> <i>does</i> support the logging <i>classes</i>
that the <code>ExtendedLog</code> directive supports.
<p>
<hr>
<h3><a name="KafkaProperty">KafkaProperty</a></h3>
<strong>Syntax:</strong> KafkaProperty <em>name value</em><br>
<strong>Default:</strong> None<br>
<strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code><br>
<strong>Module:</strong> mod_kafka<br>
<strong>Compatibility:</strong> 1.3.7rc1 and later
<p>
The <code>KafkaProperty</code> directive is used to configure the property
<em>name</em> and <em>value</em> of the common Kafka properties; see
<a href="https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md">here</a>.
<p>
Example:
<pre>
KafkaProperty socket.timeout.ms 30000
KafkaProperty socket.keepalive.enable true
KafkaProperty socket.nagle.disable true
</pre>
<p>
<hr>
<h2><a name="Installation">Installation</a></h2>
To install <code>mod_kafka</code>, copy the <code>mod_kafka</code> files into:
<pre>
<i>proftpd-dir</i>/contrib/
</pre>
after unpacking the latest proftpd-1.3.<i>x</i> source code. For including
<code>mod_kafka</code> as a staticly linked module:
<pre>
$ ./configure --with-modules=mod_kafka
</pre>
To build <code>mod_kafka</code> as a DSO module:
<pre>
$ ./configure --enable-dso --with-shared=mod_kafka
</pre>
Then follow the usual steps:
<pre>
$ make
$ make install
</pre>
<p>
You may also need to tell <code>configure</code> how to find the
<code>librdkafka</code> header and library files:
<pre>
$ ./configure --with-modules=mod_kafka \
--with-includes=<i>/path/to/librdkafka/include</i> \
--with-libraries=<i>/path/to/librdkafka/lib</i>
</pre>
<p>
<hr>
<h2><a name="Usage">Usage</a></h2>
<p>
This example shows the use of Kafka logging for <em>all</em> commands:
<pre>
<IfModule mod_kafka.c>
KafkaEngine on
KafkaLog /var/log/ftpd/kafka.log
KafkaBroker kafka:9092
LogFormat kafka "%h %l %u %t \"%r\" %s %b"
KafkaLogOnEvent ALL kafka
</IfModule>
</pre>
<p>
For cases where you need to use TLS when talking to your Kafka brokers, you
configure the necessary TLS files via the <code>KafkaProperty</code> directive:
<pre>
<IfModule mod_kafka.c>
KafkaEngine on
KafkaLog /var/log/ftpd/kafka.log
KafkaProperty ssl.ca.location /usr/local/etc/kafka/ca.pem
KafkaProperty ssl.certificate.location /usr/local/etc/kafka/client.pem
KafkaProperty ssl.key.location /usr/local/etc/kafka/client.pem
# Set this to false if necessary
KafkaProperty enable.ssl.certificate.verification true
# Necessary for telling librdkafka to use TLS for the broker
KafkaProperty security.protocol ssl
# Kafka uses TLS on port 9093
KafkaBroker ssl://kafka:9093
LogFormat kafka "%h %l %u %t \"%r\" %s %b"
KafkaLogOnEvent ALL kafka
</IfModule>
</pre>
<p><a name="Logging"></a>
<b>Kafka Logging</b><br>
When using Kafka logging, the following table shows how <code>mod_kafka</code>
converts a <code>LogFormat</code> variable into the key names in the JSON
logging objects:
<table border=1 summary="Kafka LogFormat Variables">
<tr>
<td><b><code>LogFormat</code> Variable</b></td>
<td><b>Key</b></td>
</tr>
<tr>
<td> <code>%A</code> </td>
<td>anon_password</td>
</tr>
<tr>
<td> <code>%a</code> </td>
<td>remote_ip</td>
</tr>
<tr>
<td> <code>%b</code> </td>
<td>bytes_sent</td>
</tr>
<tr>
<td> <code>%c</code> </td>
<td>connection_class</td>
</tr>
<tr>
<td> <code>%D</code> </td>
<td>dir_path</td>
</tr>
<tr>
<td> <code>%d</code> </td>
<td>dir_name</td>
</tr>
<tr>
<td> <code>%E</code> </td>
<td>session_end_reason</td>
</tr>
<tr>
<td> <code>%{epoch}</code> </td>
<td>Unix timestamp, in seconds since Jan 1 1970.</td>
</tr>
<tr>
<td> <code>%{<em>name</em>}e</code> </td>
<td>ENV:<em>name</em></td>
</tr>
<tr>
<td> <code>%F</code> </td>
<td>transfer_path</td>
</tr>
<tr>
<td> <code>%f</code> </td>
<td>file</td>
</tr>
<tr>
<td> <code>%{file-modified}</code> </td>
<td>file_modified</td>
</tr>
<tr>
<td> <code>%g</code> </td>
<td>group</td>
</tr>
<tr>
<td> <code>%{gid}</code> </td>
<td>gid</td>
</tr>
<tr>
<td> <code>%H</code> </td>
<td>server_ip</td>
</tr>
<tr>
<td> <code>%h</code> </td>
<td>remote_dns</td>
</tr>
<tr>
<td> <code>%I</code> </td>
<td>session_bytes_rcvd</td>
</tr>
<tr>
<td> <code>%{iso8601}</code> </td>
<td>timestamp</td>
</tr>
<tr>
<td> <code>%J</code> </td>
<td>command_params</td>
</tr>
<tr>
<td> <code>%L</code> </td>
<td>local_ip</td>
</tr>
<tr>
<td> <code>%l</code> </td>
<td>identd_user</td>
</tr>
<tr>
<td> <code>%m</code> </td>
<td>command</td>
</tr>
<tr>
<td> <code>%{microsecs}</code> </td>
<td>microsecs</td>
</tr>
<tr>
<td> <code>%{millisecs}</code> </td>
<td>millisecs</td>
</tr>
<tr>
<td> <code>%{note:<em>name</em>}</code> </td>
<td>NOTE:<em>name</em></td>
</tr>
<tr>
<td> <code>%O</code> </td>
<td>session_bytes_sent</td>
</tr>
<tr>
<td> <code>%P</code> </td>
<td>pid</td>
</tr>
<tr>
<td> <code>%p</code> </td>
<td>local_port</td>
</tr>
<tr>
<td> <code>%{protocol}</code> </td>
<td>protocol</td>
</tr>
<tr>
<td> <code>%r</code> </td>
<td>raw_command</td>
</tr>
<tr>
<td> <code>%S</code> </td>
<td>response_msg</td>
</tr>
<tr>
<td> <code>%s</code> </td>
<td>response_code</td>
</tr>
<tr>
<td> <code>%T</code> </td>
<td>transfer_secs</td>
</tr>
<tr>
<td> <code>%t</code> </td>
<td>local_time</td>
</tr>
<tr>
<td> <code>%{transfer-failure}</code> </td>
<td>transfer_failure</td>
</tr>
<tr>
<td> <code>%{transfer-status}</code> </td>
<td>transfer_status</td>
</tr>
<tr>
<td> <code>%U</code> </td>
<td>original_user</td>
</tr>
<tr>
<td> <code>%u</code> </td>
<td>user</td>
</tr>
<tr>
<td> <code>%{uid}</code> </td>
<td>uid</td>
</tr>
<tr>
<td> <code>%V</code> </td>
<td>server_dns</td>
</tr>
<tr>
<td> <code>%v</code> </td>
<td>server_name</td>
</tr>
<tr>
<td> <code>%{version}</code> </td>
<td>server_version</td>
</tr>
<tr>
<td> <code>%w</code> </td>
<td>rename_from</td>
</tr>
</table>
<p>
In addition to the standard <code>LogFormat</code> variables, the
<code>mod_kafka</code> module also adds a "connecting" key for events
generated when a client first connects, and a "disconnecting" key for events
generated when a client disconnects. These keys can be used for determining
the start/finish events for a given session.
<p>
Here is an example of the JSON-formatted records generated, using the above
example configuration:
<pre>
{"connecting":true,"timestamp":"2013-08-21 23:08:22,171"}
{"command":"USER","timestamp":"2013-08-21 23:08:22,278"}
{"user":"proftpd","command":"PASS","timestamp":"2013-08-21 23:08:22,305"}
{"user":"proftpd","command":"PASV","timestamp":"2013-08-21 23:08:22,317"}
{"user":"proftpd","command":"LIST","bytes_sent":432,"transfer_secs":4.211,"timestamp":"2013-08-21 23:08:22,329"}
{"user":"proftpd","command":"QUIT","timestamp":"2013-08-21 23:08:22,336"}
{"disconnecting":true,"user":"proftpd","timestamp":"2013-08-21 23:08:22,348"}
</pre>
Notice that for a given event, not <i>all</i> of the <code>LogFormat</code>
variables are filled in. If <code>mod_kafka</code> determines that a given
<code>LogFormat</code> variable has no value for the logged event, it will
simply omit that variable from the JSON object.
<p>
Another thing to notice is that the generated JSON object ignores the textual
delimiters configured by the <code>LogFormat</code> directive; all that
matters are the <code>LogFormat</code> variables which appear in the directive.
<p>
<hr>
<font size=2><b><i>
© Copyright 2017-2022 TJ Saunders<br>
All Rights Reserved<br>
</i></b></font>
<hr>
</body>
</html>
|