Salesforce (im_salesforce)

This module can be used to collect event monitoring data from Salesforce applications. It uses Salesforce Lightning Platform SOAP API and REST API v54 with username-password authorization to retrieve log data.

For the module to connect to the API and access Salesforce logs, you must first set up a Connected App and retrieve its Consumer Key and Consumer Secret.

To examine the supported platforms, see the list of installation packages.

Configuration

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

Required directives

The following directives are required to authenticate with the REST API.

ConsumerKey

This mandatory directive specifies the consumer key of your Salesforce Connected App.

ConsumerSecret

This mandatory directive specifies the consumer secret of your Salesforce Connected App.

LoginDomain

An optional directive to specify a different domain for OAuth application authorization. By default, login.salesforce.com is used. For sandbox environment, specify test.salesforce.com.

Login

This mandatory directive specifies the username of your Salesforce org account, e.g., mylogin@domain.com.

Password

This mandatory directive specifies the password of your Salesforce org account.

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 authentication password.

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

HTTPBasicAuthUser

HTTP basic authentication username.

HTTP authentication 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 Certification Authority (CA) certificates in the NXLog Platform 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.

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 Agent to use unusually high system resources or cause NXLog Agent 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

ApiVersion

This optional directive specifies the used Salesforce REST API version. It can be in v57.0 or 57 form.

EventFilter

This is an optional group directive to include or exclude event types from being collected. If this directive is not specified, the module will collect all events. It has the following sub-directives that can be defined multiple times:

Accept

Specifies a list of comma-separated event types to collect.

Exclude

Specifies a list of comma-separated event types to exclude from being collected.

The Accept and Exclude directives are mutually exclusive. If Accept is specified, the module downloads only events matching the listed event types. If Exclude is specified, the module downloads all events except the listed event types.

PollInterval

This optional directive specifies how frequently the module will check for new events in seconds. If this directive is not specified, it defaults to 60 seconds.

ReadFromLast

This optional boolean directive instructs the module on where to start reading events from the log source. Reading all events can result in a lot of messages and is usually not the expected behavior.

When TRUE, NXLog Agent will only read events logged after NXLog Agent started, unless SavePos is TRUE and a saved position for this log source is found in the cache file.
When FALSE, NXLog Agent will read all events in the log source from the start, unless SavePos is TRUE and a saved position for this log source is found in the cache file.
If the ReadFromLast directive is not specified, it defaults to TRUE.

The following matrix shows the outcome of this directive in conjunction with the SavePos directive:

ReadFromLast SavePos Saved position Outcome

TRUE

TRUE

Yes

Reads events from the saved position.

TRUE

TRUE

No

Reads events that are logged after NXLog Agent is started.

TRUE

FALSE

Yes

Reads events that are logged after NXLog Agent is started.

TRUE

FALSE

No

Reads events that are logged after NXLog Agent is started.

FALSE

TRUE

Yes

Reads events from the saved position.

FALSE

TRUE

No

Reads all events.

FALSE

FALSE

Yes

Reads all events.

FALSE

FALSE

No

Reads all events.

NOTE

The SavePos directive can be overridden by the global NoCache directive. If NoCache is TRUE, the SavePos directive is considered to be FALSE.

SavePos

This optional boolean directive instructs the module whether to save the position of the last read event before NXLog Agent exits. On the next startup, NXLog Agent will try to read the saved position from the cache file. This directive in conjunction with the ReadFromLast directive allows for resuming reading events directly from the saved position.

When TRUE, the position of the last read event are saved and will be read from the cache file upon startup.
If this directive is not specified, it defaults to TRUE.

This directive can be overridden by the global NoCache directive. If NoCache is TRUE, the SavePos directive is considered to be FALSE.

StartFrom

This optional directive specifies the time in RFC 3339 format of the first event to pull. If this directive is not set, the module reads events according to the ReadFromLast directive.

Sandbox environment

If a sandbox environment is used, the following configuration changes should be applied:

  • LoginDomain should be test.salesforce.com.

  • Login should be appended with .sandbox_name: for example, user1@acme.com becomes user1@acme.com.test.

Examples

Example 1. Collecting Salesforce logs

This configuration collects event monitoring logs from a Salesforce organization. im_salesforce receives records from the Salesforce API in CSV format, which it then parses into structured data and writes each record as a list of key-value pairs.

nxlog.conf
<Input salesforce>
    Module            im_salesforce
    LoginDomain       login.salesforce.com
    Login             USER@email.com
    Password          USERPASSWORD
    ConsumerKey       APP_KEY
    ConsumerSecret    APP_SECRET

    <EventFilter>
        Accept      Login,Logout (1)
        Accept      OneCommerceUsage

        # Exclude   Search,SearchClick (2)
        # Exclude   Sandbox
    </EventFilter>

    StartFrom         2022-07-19T16:39:57-08:00 (3)
    PollInterval      120 (4)
</Input>
1 The event filter specifies the list of event types to collect in the Accept sub-directives.
2 The filter can also be configured to collect all log types except those specified by the Exclude sub-directives.
3 The StartFrom directive specifies to start collecting events from the specified date onward.
4 The PollInterval directive specifies to check for new events every 120 seconds. The default is 60 seconds.
Output sample

The following is a Salesforce event monitoring record after it was processed by NXLog Agent.

2022-07-15 12:03:11 nxlog-server INFO EVENT_TYPE="OneCommerceUsage" TIMESTAMP="20220602110049.842" REQUEST_ID="4jHvZvFIY-2Rl-l1cKNLKV" ORGANIZATION_ID="00D5f000003Hhp1" USER_ID="0055f0000030qMF" RUN_TIME="14443623" CPU_TIME="6876485" SERVICE_NAME="CommerceLicenseUsageMetrics" OPERATION="B2BMetricsCombinationJob" OPERATION_STAGE="combineNumberOfStores" COUNT="0" OPERATION_STATUS="Success" CONTEXT_MAP="{\"cc\":0,\"lb2b\":0}" B2B_EDITION="LB2B" TIMESTAMP_DERIVED="2022-06-02T11:00:49.842Z" USER_ID_DERIVED="0055f0000030qMFAAY"