NXLog Legacy Documentation

Google Chronicle (om_chronicle)

Google Chronicle is a cloud service built as a specialized layer on top of the core Google infrastructure. It is designed for enterprises to privately retain, analyze, and search the massive amounts of security and network telemetry they generate. Chronicle normalizes, indexes, correlates, and analyzes the data to provide instant analysis and context on risky activity.

The Chronicle Ingestion API enables you to forward logs directly to Chronicle. This module supports forwarding logs to the udmevents and unstructuredlogentries endpoints. Event data is sent in batches, thus reducing HTTP response latency and improving data throughput.

om_chronicle can send logs to Chronicle Ingestion API v1 and v2. API v1 requires a Chronicle Ingestion API access key. Although this method is deprecated, it still works when writing this documentation. API v2 requires a Google Developer Service Account for OAuth 2.0 authentication.

To examine the supported platforms, see the list of installer packages in the Available Modules chapter.

Output log format

Unstructured logs

om_chronicle forwards unstructured log records over HTTP(S) as JSON payload in the following format:

{
    "log_type": "<log_type>",
    "customer_id": "<customer_id>",
    "entries": [
        {
            "log_text": "<json_escaped_raw_event>",
            "ts_rfc3339": "<event_time>"
        }
    ]
}

For example:

{
    "log_type": "BIND_DNS",
    "customer_id": "c8c65bfa-5f2c-42d4-9189-64bb7b939f2c",
    "entries": [
        {
            "log_text": "<13>Oct  9 17:33:15 SERVER-1 09-Oct-2023 17:33:15.187 queries: info: client 10.120.20.20#4238:  query: example.com IN A + (100.90.80.102)",
            "ts_rfc3339": "2023-10-09T17:51:27.122616+02:00"
        }
    ]
}

Required fields:

  • log_type is the value specified by the LogType directive.

  • log_text is the JSON escaped value of the $raw_event field.

Optional fields:

  • customer_id is present if the API v1 CustomerId or API v2 CustomerIddirective is specified.

  • ts_rfc3339 is present if the $EventReceivedTime core field is present. If this field is not required, use the delete() procedure to remove $EventReceivedTime. This can be useful if the log text already contains a received date and time.

Additional metadata, including the NXLog-specific fields $SourceModuleName and $SourceModuleType, will not be included in the output unless these values have been written to the $raw_event field. The processing required to achieve this depends on the format of the input data. For example, if the input data is in JSON format, you need to:

  1. Use parse_json() to parse $raw_event into fields.

  2. Create and populate any additional custom fields.

  3. Use to_json() to convert the fields to JSON format and update the value of $raw_event.

Structured logs

om_chronicle forwards structured log records over HTTP(S) as JSON payload in the following format:

{
    "metadata": {
        "event_type": "NETWORK_CONNECTION",
        "event_timestamp": "<event_time>",
        "description": "<json_escaped_raw_event>",
        "ingestion_labels": [
            {
                "key": "source_module_name",
                "value": "<source_module_name>"
            },
            {
                "key": "source_module_type",
                "value": "<source_module_type>"
            }
        ]
    },
    "network": {
        "ip_protocol": "TCP"
    },
    "principal": {
        "ip": "<message_source_address>"
    },
    "target": {
        "application": "nxlog",
        "ip": "127.0.0.1"
    }
}

For example:

{
    "metadata": {
        "description": "16-May-2023 20:11:15.187 client 10.120.20.20#4238:  query: example.com IN A + (100.90.80.102)",
        "event_timestamp": "2023-05-16T20:11:27.421707+05:45",
        "event_type": "NETWORK_CONNECTION",
        "ingestion_labels": [
            {
                "key": "source_module_name",
                "value": "tcp"
            },
            {
                "key": "source_module_type",
                "value": "im_tcp"
            }
        ]
    },
    "network": {
        "ip_protocol": "TCP"
    },
    "principal": {
        "ip": "127.0.0.1"
    },
    "target": {
        "application": "nxlog",
        "ip": "127.0.0.1"
    }
}

Required fields:

  • description is the JSON escaped value of the $raw_event field.

  • event_timestamp is the value of $EventReceivedTime.

  • ingestion_labels.source_module_name is the value of $SourceModuleName, i.e., the name of the NXLog input module instance.

  • ingestion_labels.source_module_type is the value of $SourceModuleType, i.e., the NXLog input module.

If you remove any of these fields from the log record, for example, with the delete() procedure, the field value will be set to an empty string.

Configuration

Log data sent to the destination with this module must be UTF-8 encoded, otherwise, the target will refuse and drop the events.

If the source does not guarantee that events are UTF-8 encoded, use the xm_charconv extension module to convert the log data to UTF-8:

  1. Set the AutodetectCharsets directive in your xm_charconv module block with as many character set names as required to automatically detect all possible source log data encodings. For example:

    <Extension converter>
        Module                xm_charconv
        AutodetectCharsets    utf-8, utf-16, utf-32, iso8859-2, iso8859-7, iso-8859-1, euc-jp
    </Extension>
  2. Add the convert_fields procedure call to each input module that routes events to this output module:

    Exec    convert_fields("auto", "utf-8");

The om_chronicle module accepts the following directives in addition to the common module directives.

The module can use Chronicle Ingestion API v1 or API v2 and works in either unstructured or structured mode.

Chronicle Ingestion API v1 directives

ChronicleVersion

Specifies the Google Chronicle Ingestion API version. The supported values for API v1 are v1 or 1. The default is v1.

ChronicleKey

This directive specifies a Chronicle Ingestion API access key required for API v1. Chronicle responds with HTTP error 403 if this key is not valid.

CustomerId

This directive specifies the unique identifier (UUID) corresponding to your Chronicle instance. The ID is provided by your Chronicle representative. The Ingestion API responds with HTTP error 400 or 403 if the UUID is not valid.

This directive is optional for API v1.

Chronicle Ingestion API v2 directives

ChronicleVersion

Specifies the Google Chronicle Ingestion API version. The supported values for API v2 are v2 or 2.

CredentialsFile

This directive specifies the path to the private key file of the Google Developer Service Account required for authenticating with Google Chronicle Ingestion API v2. Chronicle responds with HTTP error 403 if this key is not valid.

See Configuring a Google Cloud service account for more information.

CustomerId

This directive specifies the unique identifier (UUID) corresponding to your Chronicle instance. The ID is provided by your Chronicle representative. The Ingestion API responds with HTTP error 400 or 403 if the UUID is not valid.

This directive is required for API v2.

Unstructured output format directives

The following directives define how the module formats the log records it sends to Google Chronicle in unstructured mode.

ChronicleMode

This directive specifies the Google Chronicle API endpoint. The accepted value for unstructured mode is unstructured. This is the default value.

This mode supports forwarding unstructured logs to the unstructuredlogentries endpoint. Log data normalization is then handled by Google Chronicle.

LogType

Must correspond to a valid log type. To retrieve the list of possible log types, visit https://malachiteingestion-pa.googleapis.com/v1/logtypes?key=YOUR_API_KEY.

This directive is required in unstructured mode.

Structured output format directives

The following directives define how the module formats the log records it sends to Google Chronicle in structured mode.

ChronicleMode

This directive specifies the Google Chronicle API endpoint. The accepted value for structured mode is structured.

This mode supports forwarding logs to the udmevents endpoint. Log data must be in the UDM format supported by Google Chronicle.

ChronicleSchema

The output data from each NXLog module is mapped to the Chronicle UDM format using a custom schema mapping. Use this directive to specify the name of a different schema file and override the default mapping.

SchemaMap

Use this directive to map the data schema dynamically.

<SchemaMap>
    "spawning"    im_file-spawning.json
    "running"     im_file-running.json
    "exited"      im_file-exited.json
</SchemaMap>

<Exec>
    if ($eventMessage =~ /service state: (\w+)/)
        set_schema($1);
    else
        log_warning("Unknown eventMessage: " + $eventMessage);
</Exec>

SchemaDir

Specify the path to the directory containing the custom schema files defined by the ChronicleSchema and SchemaMap directives. The path can be relative to the configuration directory.

HTTP(S) directives

The following directives are for configuring HTTP(S) connection settings.

AddHeader

This optional directive can be specified multiple times to add custom headers to each HTTP request.

Compression

This optional directive can be used to enable HTTP compression for outgoing HTTP messages. The possible values are none, gzip, and deflate. By default, compression is disabled. Please note that some HTTP servers may not accept compressed HTTP requests. If a server doesn’t support a specific compression method, it may return 415 Unsupported Media Type errors in response to compressed requests.

HTTPBasicAuthPassword

HTTP basic authorization password.

HTTP authorization works only when both HTTPBasicAuthUser and HTTPBasicAuthPassword parameters are set.

HTTPBasicAuthUser

HTTP basic authorization username.

HTTP authorization works only when both HTTPBasicAuthUser and HTTPBasicAuthPassword parameters are set.

HTTPSAllowExpired

Specifies if the connection should be allowed with an expired certificate. If set to TRUE, the remote host will be able to connect with an expired certificate. The default is FALSE: the certificate must not be expired.

HTTPSAllowUntrusted

Specifies if the connection should be allowed without certificate verification. If set to TRUE, the connection will be allowed even if the remote host presents an unknown or self-signed certificate. The default value is FALSE: the remote host must present a trusted certificate.

HTTPSCADir

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:

$ openssl x509 -hash -noout -in ca.crt

For example, if the certificate hash is e2f14e4a, then the certificate filename should be e2f14e4a.0. If there is another certificate with the same hash then it should be named e2f14e4a.1 and so on.

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 /etc/ssl/certs. Windows operating systems use the Windows Certificate Store, while macOS uses the Keychain Access Application as the default certificate store. See NXLog TLS/SSL configuration in the User Guide for more information on using this directive.

In addition, Microsoft’s PKI repository contains root certificates for Microsoft services.

HTTPSCAFile

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).

HTTPSCertFile

The path of the certificate file that will be presented to the remote host during the HTTPS handshake.

HTTPSCertKeyFile

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.

OutputRequestSize

Maximum size of the request in bytes. The default is 64 MB.

Proxy

This optional directive is used to specify the protocol, IP address (or hostname) and port number of the HTTP or SOCKS proxy host to be used. The format is protocol://hostname:port.

Reconnect

This optional directive sets the reconnect interval in seconds. If it is set, the module attempts to reconnect in every defined second. If it is not set, the reconnect interval will start at 1 second and double with every attempt. If the duration of the successful connection is greater than the current reconnect interval, then the reconnect interval will be reset to 1 sec.

The Reconnect directive must be used with caution. If it is used on multiple systems, it can send reconnect requests simultaneously to the same destination, potentially overloading the destination system. It may also cause NXLog to use unusually high system resources or cause NXLog to become unresponsive.

ReconnectOnData

This optional directive defines the behavior when the connection with the remote host is lost. When set to TRUE, the module only attempts to reconnect when it has data to send. The default value is FALSE; it will always keep a connection open with the remote host.

Optional directives

ChronicleRegion

This directive specifies a regional endpoint. Supported values are: US, Europe, asia-southeast1, etc. See the Locations page.

URL

Optional directive for specifying the Chronicle Ingestion API endpoint.

Alternatively, use the optional ChronicleRegion, API v1 ChronicleVersion or API v2 ChronicleVersion, unstructured ChronicleMode, structured ChronicleMode, and ChronicleKey directives to use the default endpoint: https://{ChronicleRegion}-malachiteingestion-pa.googleapis.com/{ChronicleVersion}/{ChronicleMode}/?key={ChronicleKey}

Depending on the URL provided, the module operates in plain HTTP or HTTPS mode. If you do not specify the port number in the URL, it uses port 80 for HTTP and port 443 for HTTPS.

ChronicleKey is only required for API v1.
This module does not support specifying multiple URL directives as a failover configuration.

Procedures

The following procedures are exported by om_chronicle.

set_schema(string schema_name);

Use a different schema file to override the default mapping. The schema_name specifies the schema name declared in the SchemaMap directive.

Examples

Example 1. Sending unstructured plain text logs

This configuration collects logs from a BIND 9 DNS server and forwards them to Chronicle. Since the BIND_DNS LogType requires the events to be in syslog format, log records are converted to syslog using the to_syslog_bsd() procedure of the xm_syslog module.

nxlog.conf
# Google Chronicle API key, required.
define API_KEY             <YOUR_API_KEY>

<Extension syslog>
    Module                xm_syslog
</Extension>

<Output chronicle>
    Module                om_chronicle
    ChronicleKey          %API_KEY%

    # Unstructured events
    ChronicleMode         unstructured

    # Identifies the type of logs in the batch.
    LogType               BIND_DNS

    <Exec>
        $Message = $raw_event;
        to_syslog_bsd();
    </Exec>
</Output>
Input sample
09-Oct-2023 17:33:15.187 queries: info: client 10.120.20.20#4238:  query: example.com IN A + (100.90.80.102)
09-Oct-2023 17:34:16.120 queries: info: client 10.120.20.20#4238:  query: example.com IN A + (100.90.80.102)
09-Oct-2023 17:35:17.165 queries: info: client 10.120.20.20#4238:  query: example.com IN A + (100.90.80.102)
Output sample

The following is the JSON-formatted log record that will be sent to Google Chronicle. Note that the ts_rfc3339 field is added by the module and specifies the time when the event was received and corresponds to the $EventReceivedTime core field.

{
  "log_type": "BIND_DNS",
  "entries": [
    {
      "log_text": "<13>Oct  9 17:33:15 SERVER-1 09-Oct-2023 17:33:15.187 queries: info: client 10.120.20.20#4238:  query: example.com IN A + (100.90.80.102)",
      "ts_rfc3339": "2023-10-09T17:51:27.122616+02:00"
    },
    {
      "log_text": "<13>Oct  9 17:34:16 SERVER-1 09-Oct-2023 17:34:16.120 queries: info: client 10.120.20.20#4238:  query: example.com IN A + (100.90.80.102)",
      "ts_rfc3339": "2023-10-09T17:51:27.126157+02:00"
    },
    {
      "log_text": "<13>Oct  9 17:35:17 SERVER-1 09-Oct-2023 17:35:17.165 queries: info: client 10.120.20.20#4238:  query: example.com IN A + (100.90.80.102)",
      "ts_rfc3339": "2023-10-09T17:51:27.126176+02:00"
    }
  ]
}
Example 2. Sending structured logs

This configuration collects logs from a BIND 9 DNS server and forwards them to Chronicle in UDM format. It parses log records into structured data with a regular expression and uses a custom ChronicleSchema file in the same folder as the NXLog configuration.

nxlog.conf
# Google Chronicle API key, required.
define API_KEY         <YOUR_API_KEY>

<Input dns>
    Module             im_file
    File               '/var/log/bind.log'
    <Exec>
        if $raw_event =~ /(?x)^(?<EventTime>\S+\s\S+)\s(?<category>.*):\s
                          (?<severity>.*):\s.*\s(?<source>.*)\#
                          (?<port>\d+):\s+(?<message>.+)$/
        {
            $EventTime = parsedate($EventTime);
        }
    </Exec>
</Input>

<Output chronicle_udm>
    Module             om_chronicle
    ChronicleKey       %API_KEY%
    ChronicleMode      structured
    ChronicleSchema    'bind_dns.json'
</Output>
bind_dns.json
{
  "metadata": {
    "event_type": "NETWORK_DNS",
    "event_timestamp": "$EventTime",
    "ingested_timestamp": "$EventReceivedTime",
    "description": "$message",
    "product_name": "BIND 9",
    "vendor_name": "ISC",
    "product_event_type": "$category",
    "severity_details": "$severity",
    "ingestion_labels": [
      {
        "key": "source_module_name",
        "value": "$SourceModuleName"
      },
      {
        "key": "source_module_type",
        "value": "$SourceModuleType"
      }
    ]
  },
  "src": {
    "ip": "$source",
    "port": "$port"
  },
  "principal": {
    "hostname": "$Hostname"
  }
}
Input sample
09-Oct-2023 17:33:15.187 queries: info: client 10.120.20.20#4238:  query: example.com IN A + (100.90.80.102)
Output sample

The following is the JSON-formatted log record that will be sent to Google Chronicle.

{
  "events": [
    {
      "metadata": {
        "description": "query: example.com IN A + (100.90.80.102)",
        "event_timestamp": "2023-10-09T17:35:17.165000+02:00",
        "event_type": "NETWORK_DNS",
        "ingested_timestamp": "2023-10-09T17:39:17.901029+02:00",
        "ingestion_labels": [
          {
            "key": "source_module_name",
            "value": "dns"
          },
          {
            "key": "source_module_type",
            "value": "im_file"
          }
        ],
        "product_event_type": "queries",
        "product_name": "BIND 9",
        "severity_details": "info",
        "vendor_name": "ISC"
      },
      "principal": {
        "hostname": "SERVER-1"
      },
      "src": {
        "ip": "10.120.20.20",
        "port": "4238"
      }
    }
  ]
}
Example 3. Setting the UDM schema dynamically

This configuration sends logs to Chronicle in UDM format. The output instance implements schema-selection logic based on the $EventType field. It sets the SchemaDir to a folder relative to the NXLog configuration file and uses the SchemaMap directive and set_schema() procedure to set the UDM schema dynamically.

nxlog.conf
# Google Chronicle API key, required.
define API_KEY       <YOUR_API_KEY>

<Output chronicle_udm>
    Module           om_chronicle
    ChronicleKey     %API_KEY%
    ChronicleMode    structured

    SchemaDir        'chronicle-schemas'

    <SchemaMap>
        copy         file-copy.json
        delete       file-delete.json
        spawn        process-create.json
        default      default.json
    </SchemaMap>

    <Exec>
        if ($EventType == "File copied") {
            set_schema("copy");
        }
        else if ($EventType == "File deleted") {
            set_schema("delete");
        }
        else if ($EventType == "Process created") {
            set_schema("spawn");
        }
        else {
            set_schema("default");
        }
    </Exec>
</Output>
Example 4. Sending logs to Chronicle Ingestion API v2

This configuration collects logs from a BIND 9 DNS server and forwards them to Chronicle in unstructured format. Sending logs to Chronicle Ingestion API v2 requires the following directives:

nxlog.conf
# Chronicle UUID, required.
define CUSTOMER_ID     <YOUR_CHRONICLE_UUID>

<Extension syslog>
    Module             xm_syslog
</Extension>

<Output chronicle_v2>
    Module             om_chronicle
    ChronicleVersion   v2
    CustomerId         %CUSTOMER_ID%

    # Google Service Account credentias file, required.
    CredentialsFile    '/opt/nxlog/etc/credentials.json'

    # Unstructured events
    ChronicleMode      unstructured

    # Identifies the type of logs in the batch.
    LogType            BIND_DNS

    <Exec>
        $Message = $raw_event;
        to_syslog_bsd();
    </Exec>
</Output>