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 responds with HTTP/1.1 200 OK 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. |
To examine the supported platforms, see the list of installation packages. |
Configuration
The im_http module accepts the following directives in addition to the common module directives.
HTTPS directives
The following directives configure secure data transfer via HTTPS.
Specifies if the connection should be allowed with an expired certificate.
If set to |
|||
Specifies if the certificate FQDN should be validated against the server hostname or not.
If set to |
|||
Specifies if the connection should be allowed without certificate verification.
If set to |
|||
The path to a directory containing certificate authority (CA) certificates. These certificates will be used to verify the certificate presented by the remote host. 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 host’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 In addition, Microsoft’s PKI repository contains root certificates for Microsoft services. |
|||
The path of the certificate authority (CA) certificate that will be used to verify the certificate presented by the remote host. A remote host’s self-signed certificate (which is not signed by a CA) can be trusted by specifying the remote host certificate itself. In case of certificates signed by an intermediate CA, the certificate specified must contain the complete certificate chain (certificate bundle). |
|||
This optional directive, supported only on Windows, defines a pattern for locating a suitable CA (Certificate Authority) certificate and its thumbprint in the native Windows Certificate Storage.
The pattern must follow PCRE2 rules and use the format Configuration examples:
or
A normal log output example would look like as follows:
|
|||
This optional directive, supported only on Windows, specifies the thumbprint of the certificate authority (CA) certificate that will be used to verify the certificate presented by the remote host. 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 mutually exclusive with the HTTPSCADir and HTTPSCAFile directives. |
|||
The path of the certificate file that will be presented to the remote host during the HTTPS handshake. |
|||
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, supported only on Windows, defines a pattern for identifying a corresponding certificate and its thumbprint within the native Windows Certificate Storage.
The pattern must follow PCRE2 rules and use the format Configuration examples:
or
A normal log output example would look like as follows:
|
|||
This optional directive, supported only on Windows, specifies the thumbprint of the certificate that will be presented to the remote host 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
When the global directive UseCNGCertificates is set to
On the contrary, when the global directive UseCNGCertificates is set to The usage of the directive is the same in all cases:
|
|||
The 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 |
|||
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. |
|||
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. |
|||
If set to This directive is only supported on Windows. |
|||
Specifies if the remote HTTPS host must present a certificate.
If set to |
|||
This optional directive, if set to This directive is only supported on Windows. |
|||
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:
|
|||
If set 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: |
|||
The signature algorithm parameter that is being sent to the Windows SSL library. Allowed values depend on the available encryption providers. This directive is only supported on Windows. |
|||
This optional directive specifies the hostname used for Server Name Indication (SNI) in HTTPS mode. |
|||
If set to TRUE, the module uses the Windows Cryptography API: Next Generation (CNG) to access the private keys associated with certificates identified by a thumbprint. This directive is only supported on Windows. |
Optional directives
The module accepts connections on this IP address or DNS hostname.
For security, the default listen address is The port number can be defined by appending it to the hostname or IP address using a colon as a separator ( Using the any address You can define this directive multiple times to listen on multiple addresses or ports in a single module instance. Specify IPv4 and IPv6 addresses separately as needed. If you use a DNS name, you should keep the addresses or CNAMEs below 16 to avoid 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:
|
|||
With this optional directive it is possible to set the maximum number of allowed concurrent/active connections for a listening TCP socket.
If not specified, the default value is 2024-03-01 22:29:16 ERROR [im_tcp|in_tcp] Number of allowed active connections(10) reached: 10. Refusing connection from 127.0.0.1 |
|||
This optional directive defines the maximum time in seconds before NXLog Agent closes TCP connections without traffic. The minimum timeout value is 15 seconds. If this directive is not specified, NXLog Agent does not close idle TCP connections. |
|||
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>