This section describes the syslog-ng Open Source Edition (syslog-ng OSE) application's Python HTTP header plugin.
For more information about modules in syslog-ng OSE, see Modules in syslog-ng Open Source Edition (syslog-ng OSE).
The syslog-ng OSE application supports adding custom headers to HTTP requests using the Python programming language.
NOTE: Before you use the python-http-header plugin, make sure that your syslog-ng OSE appliance was compiled with Python support. If you installed syslog-ng OSE from a package, make sure that the subpackage containing Python support is also installed.
destination d_http { http( python_http_header( class("<class-name>") options("options-key1", "option-value1") options("options-key2", "option-value2") mark-errors-as-critical(no)) url("http://127.0.0.1:8888") ); };
Options used in the configuration
NOTE: If you put the class implementation into its own module, it should be put into a standard location, or made available with the PYTHONPATH environment variable.
You can define the Python interface with the following:
class TestCounter(): def __init__(self, options): self.key = options["value"] def get_headers(self, body, headers): return ["header1: value1", "header2: value2"] def on_http_response_received(self, http_code): print("HTTP response code received: {}".format(http_code))
By default, when the signal_http_header_request is emitted by the HTTP module, the connected slot automatically executes the Python code.
NOTE: If the plugin fails, the HTTP module does not send the HTTP request without the header items by default. If you want the HTTP module to try sending the request without the header items, disable the mark-errors-as-critical function.
Methods used in the configuration
The following example can be copy-pasted and used as a template for using the Python HTTP header plugin in your configuration.
python { from syslogng import Logger logger = Logger() class TestCounter(): def __init__(self, options): self.header = options["header"] self.counter = int(options["counter"]) logger.debug(f"TestCounter class instantiated; options={options}") def get_headers(self, body, headers): logger.debug(f"get_headers() called, received body={body}, headers={headers}") response = ["{}: {}".format(self.header, self.counter)] self.counter += 1 return response def on_http_response_received(self, http_code): self.counter += http_code logger.debug("HTTP response code received: {}".format(http_code)) def __del__(self): logger.debug("Deleting TestCounter class instance") }; source s_network { network(port(5555)); }; destination d_http { http( python_http_header( class("TestCounter") options("header", "X-Test-Python-Counter") options("counter", 11) # this means that syslog-ng will keep trying to send the http request even when this module fails mark-errors-as-critical(no) ) url("http://127.0.0.1:8888") ); }; log { source(s_network); destination(d_http); flags(flow-control); };
|
Caution:
Although it is possible to configure multiple HTTP workers for syslog-ng OSE, the syslog-ng OSE application can only embed a single Python interpreter at the same time. As a result, if you configure more than one HTTP workers on your syslog-ng OSE application, the Python code will run in concurrent mode. To protect the state of the object, you may need to use locks. For more information about using locks, see Introduction to the Python HTTP header. |
Starting with version
This destination is only supported on the Linux platform.
Since syslog-ng OSE uses the official Java Kafka producer, the kafka destination has significant memory usage.
The log messages of the underlying client libraries are available in the internal() source of syslog-ng OSE.
@include "scl.conf" kafka( client-lib-dir("/opt/syslog-ng/lib/syslog-ng/java-modules/:<path-to-preinstalled-kafka-libraries>") kafka-bootstrap-servers("1.2.3.4:9092,192.168.0.2:9092") topic("${HOST}") );
The following example defines a kafka destination, using only the required parameters.
@include "scl.conf" destination d_kafka { kafka( client-lib-dir("/opt/syslog-ng/lib/syslog-ng/java-modules/KafkaDestination.jar:/usr/share/kafka/lib/") kafka-bootstrap-servers("1.2.3.4:9092,192.168.0.2:9092") topic("${HOST}") ); };
To install the software required for the kafka destination, see Prerequisites.
For details on how the kafka destination works, see How syslog-ng OSE interacts with Apache Kafka.
For the list of options, see Kafka destination options.
The kafka() driver is actually a reusable configuration snippet configured to receive log messages using the Java language-binding of syslog-ng OSE. For details on using or writing such configuration snippets, see Reusing configuration blocks. You can find the source of the kafka configuration snippet on GitHub. For details on extending syslog-ng OSE in Java, see the Getting started with syslog-ng development guide.
NOTE: If you delete all Java destinations from your configuration and reload syslog-ng, the JVM is not used anymore, but it is still running. If you want to stop JVM, stop syslog-ng and then start syslog-ng again.
To publish messages from syslog-ng OSE to Apache Kafka, complete the following steps.
If you want to use the Java-based modules of syslog-ng OSE (for example, the Elasticsearch, HDFS, or Kafka destinations), you must compile syslog-ng OSE with Java support.
Download and install the Java Runtime Environment (JRE), 1.7 (or newer).
Install gradle version 2.2.1 or newer.
Set LD_LIBRARY_PATH to include the libjvm.so file, for example:LD_LIBRARY_PATH=/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server:$LD_LIBRARY_PATH
Note that many platforms have a simplified links for Java libraries. Use the simplified path if available. If you use a startup script to start syslog-ng OSE set LD_LIBRARY_PATH in the script as well.
If you are behind an HTTP proxy, create a gradle.properties under the modules/java-modules/ directory. Set the proxy parameters in the file. For details, see The Gradle User Guide.
Download the latest stable binary release of the Apache Kafka libraries (version 0.9 or newer) from http://kafka.apache.org/downloads.html.
Extract the Apache Kafka libraries into a single directory. If needed, collect the various .jar files into a single directory (for example, /opt/kafka/lib/) where syslog-ng OSE can access them. You must specify this directory in the syslog-ng OSE configuration file.
Check if the following files in the Kafka libraries have the same version number: slf4j-api-<version-number>.jar, slf4j-log4j12-<version-number>.jar. If the version number of these files is different, complete the following steps:
Delete one of the files (for example, slf4j-log4j12-<version-number>.jar).
Download a version that matches the version number of the other file (for example, 1.7.6) from the official SLF4J distribution.
Copy the downloaded file into the directory of your Kafka library files (for example, /opt/kafka/lib/).
When stopping the syslog-ng OSE application, syslog-ng OSE will not stop until all Java threads are finished, including the threads started by the Kafka Producer. There is no way (except for the kill -9 command) to stop syslog-ng OSE before the Kafka Producer stops. To change this behavior set the properties of the Kafka Producer in its properties file, and reference the file in the properties-file option.
The syslog-ng OSE kafka destination tries to reconnect to the brokers in a tight loop. This can look as spinning, because of a lot of similar debug messages. To decrease the amount of such messages, set a bigger timeout using the following properties:
retry.backoff.ms=1000 reconnect.backoff.ms=1000
For details on using property files, see properties-file(). For details on the properties that you can set in the property file, see the Apache Kafka documentation.
© 2024 One Identity LLC. ALL RIGHTS RESERVED. 이용 약관 개인정보 보호정책 Cookie Preference Center