HTTP(s) (im_http)
This module can be configured to accept HTTP or HTTPS connections.
It listens on the address and port defined by the ListenAddr directive and accepts HTTP POST requests.
The event message must be included in the request body as raw data and will be available in the $raw_event
field.
The POST request must include the Content-Length header indicating the size of the event message and the module will read the number of bytes specified by this header.
Connections are not closed by the module while valid requests are still being received to operate in Keep-Alive mode.
It sends an HTTP/1.1 201 Created response to each valid POST request.
This acknowledgment ensures reliable message delivery.
im_http contains a partial HTTP/1.1 implementation and is designed to work with the om_http module. It has received limited interoperability testing and thus using it with other third-party clients may not have the expected results. |
Configuration
The im_http module accepts the following directives in addition to the common module directives.
TLS/SSL directives
The following directives are for configuring secure data transfer via TLS/SSL.
This boolean directive specifies whether the connection should be allowed with an expired certificate.
If set to |
|||
This boolean directive specifies that the connection should be allowed without certificate verification.
If set to |
|||
This directive specifies a path to a directory containing certificate authority (CA) certificates. These certificates will be used to verify the certificate presented by the remote client. The certificate files must be named using the OpenSSL hashed format, i.e. the hash of the certificate followed by .0, .1 etc. To find the hash of a certificate using OpenSSL:
For example, if the certificate hash is A remote client’s self-signed certificate (which is not signed by a CA) can also be trusted by including a copy of the certificate in this directory. The default operating system root certificate store will be used if this directive is not specified.
Unix-like operating systems commonly store root certificates in |
|||
This specifies the path of the certificate authority (CA) certificate that will be used to verify the certificate presented by the remote client. A remote client’s self-signed certificate (which is not signed by a CA) can be trusted by specifying the remote client certificate itself. In the case of certificates signed by an intermediate CA, the certificate specified must contain the complete certificate chain (certificate bundle). |
|||
This optional directive specifies the thumbprint of the certificate authority (CA) certificate that will be used to verify the certificate presented by the remote client. The hexadecimal fingerprint string can be copied from Windows Certificate Manager (certmgr.msc). Whitespaces are automatically removed. The certificate must be added to a Windows certificate store that is accessible by NXLog Agent. This directive is only supported on Windows and is mutually exclusive with the HTTPSCADir and HTTPSCAFile directives. |
|||
This specifies the path of the certificate file that will be presented to the remote client during the HTTPS handshake. |
|||
This specifies the path of the private key file that was used to generate the certificate specified by the HTTPSCertFile directive. This is used for the HTTPS handshake. |
|||
This optional directive specifies the thumbprint of the certificate that will be presented to the remote client during the HTTPS handshake.
The hexadecimal fingerprint string can be copied from Windows Certificate Manager (certmgr.msc).
Whitespaces are automatically removed.
The certificate must be imported to the
This directive is only supported on Windows and is mutually exclusive with the HTTPSCertFile and HTTPSCertKeyFile directives.
|
|||
This directive specifies a path to a directory containing certificate revocation list (CRL) files. These CRL files will be used to check for certificates that were revoked and should no longer be accepted. The files must be named using the OpenSSL hashed format, i.e. the hash of the issuer followed by .r0, .r1 etc. To find the hash of the issuer of a CRL file using OpenSSL:
For example if the hash is |
|||
This specifies the path of the certificate revocation list (CRL) which will be used to check for certificates that have been revoked and should no longer be accepted. Example to generate a CRL file using OpenSSL:
|
|||
This optional directive specifies a file with dh-parameters for Diffie-Hellman key exchange. These parameters can be generated with dhparam(1ssl). If no directive is specified, default parameters will be used. See OpenSSL Wiki for further details. |
|||
This directive specifies the passphrase of the private key specified by the HTTPSCertKeyFile directive. A passphrase is required when the private key is encrypted. Example to generate a private key with Triple DES encryption using OpenSSL:
This directive is not needed for passwordless private keys. |
|||
This boolean directive specifies that the remote HTTPS client must present a certificate.
If set to |
|||
This optional boolean directive, when set to |
|||
This optional directive can be used to set the permitted SSL cipher list, overriding the default.
Use the format described in the ciphers(1ssl) man page.
For example specify
|
|||
This optional directive can be used to set the permitted cipher list for TLSv1.3. Use the same format as in the HTTPSSSLCipher directive. Refer to the OpenSSL documentation for a list of valid TLS v1.3 cipher suites. The default value is:
|
|||
This boolean directive allows you to enable data compression when sending data over the network.
The compression mechanism is based on the zlib compression library.
If the directive is not specified, it defaults to
|
|||
This directive can be used to set the allowed SSL/TLS protocol(s).
It takes a comma-separated list of values which can be any of the following: |
Optional directives
The module accepts connections on the IP address or hostname and port defined by this directive.
The default address is To listen on multiple addresses or ports in a single module instance, this directive can be repeated multiple times. Both IPv4 and IPv6 addresses are supported. If a DNS name is used, the number of addresses or cnames should be kept below 16 to avoid potential issues caused by DNS response size limits.
|
|||
This optional directive can be used to allow IP addresses and/or networks to connect. The directive can be set multiple times to add different IPs or networks to allow. This directive is only active when the ListenAddr directive is present. In the absence of this directive, the BlockIP directive is considered. If both AllowIP and BlockIP are absent, then hosts are not restricted from connecting to a listening module. The following formats may be used for the AllowIP directive:
|
|||
This optional directive can be used to deny IP addresses and/or networks to connect. The directive can be set multiple times to add different IPs or networks to deny. This directive is only active when the ListenAddr directive is present. In the absence of this directive, the AllowIP directive is considered. If both AllowIP and BlockIP are absent, then hosts are not restricted from connecting to a listening module. The following formats may be used for the BlockIP directive:
|
|||
This optional boolean directive specifies whether the module instance should exclusively bind to the specified port.
The default value is
|
|||
This optional boolean directive determines whether the module instance should forcibly bind to a port already in use.
The default value is |
|||
This optional boolean directive specifies whether multiple im_http module instances can listen on the same port.
When you enable this directive, multiple instances run in a separate thread, allowing NXLog Agent to process incoming logs simultaneously.
See the examples below.
The default value is
|
Functions
The following functions are exported by im_http.
- string
get_abs_path()
-
Returns the absolute path of the URL.
- string
get_rel_path()
-
Returns the relative path of the URL.
- string
get_url()
-
Returns the full URL.
- hash
parse_header()
-
Returns the HTTP headers for the current record (last parsed http request) as a hash value.
Procedures
The following procedures are exported by im_http.
parse_url_params();
-
Generates fields from URL query parameters.
Examples
This configuration listens for HTTPS connections from localhost. Received log messages are written to a file.
<Input http>
Module im_http
ListenAddr 0.0.0.0:8888
HTTPSCertFile %CERTDIR%/server-cert.pem
HTTPSCertKeyFile %CERTDIR%/server-key.pem
HTTPSCAFile %CERTDIR%/ca.pem
HTTPSRequireCert TRUE
HTTPSAllowUntrusted FALSE
</Input>
This configuration uses the HTTPSCAThumbprint and HTTPSCertThumbprint directives for the verification of the Certificate Authority and the SSL handshake respectively.
<Input in_https>
Module im_http
ListenAddr 0.0.0.0:443
HTTPSCAThumbprint c2c902f736d39d37fd65c458afe0180ea799e443
HTTPSCertThumbprint 7c2cc5a5fb59d4f46082a510e74df17da95e2152
HTTPSSSLProtocol TLSv1.2
</Input>
This script uses the curl utility to send data to an im_http instance. The log data is passed as an argument when executing the script.
The URL
value needs to be replaced with a valid hostname according to the value specified by the ListenAddr directive.
The PORT
value needs to be replaced with the actual port that im_http has been configured to listen on.
The USESSL
value needs to be updated with the path to the client certificate, client certificate key, and certification authority files respectively.
In this example, the files are located in a folder named keys located in the same path as the script.
URL=https://<hostname>
PORT=<port>
USESSL="--cert keys/client-cert.pem --key keys/client-key.pem --cacert keys/ca.pem"
BYTELEN=`printf "%s" "$1" | wc -c`
curl -v $USESSL -H "Content-Type:plain/text" -H "Content-Length:${BYTELEN}" -d "$1" $URL:$PORT
The script is executed by running the following command and passing the log data to it as an argument:
# path/to/im-http-curl-request.sh "My log line"
This bash script and other examples can be found in the NXLog public repository on GitLab.
This configuration waits for HTTP packets and parses the incoming headers, then logs the requested information. It extracts the header values, such as the User-Agent and the Content-Length, first by requesting the specific field directly, then by parsing the entire header and extracting the value from the hash. Both calls use compound values, but they can be used with simple values, depending on the scope of the implementation.
<Input ihttp>
Module im_http
ListenAddr 0.0.0.0:6060
<Exec>
$$agent = parse_header("User-Agent");
log_info("User Agent:" + $$agent);
# retrieving a hash with the entire header
$$entire_header = parse_header();
log_info("Data segment size in Bytes:" + $$entire_header('Content-Length'));
log_info("Entire header parsed:" + $$entire_header);
</Exec>
</Input>