Skip to main content

Configure the Kafka LAM

Apache Kafka builds real-time data pipelines and streaming apps, and runs as a cluster of one or more servers. The Kafka cluster stores streams of records in categories called topics. Each record consists of a key, a value, and a time-stamp.

You can install a basic Kafka integration in the UI. See Apache Kafka for integration steps.

Before you begin

The Kafka integration has been validated with Kafka v0.9 and 1.1. Before you start to set up the LAM, ensure you have met the following requirements:

  • You have the host and ports for all the Kafka brokers you want to connect to.

  • The ports for your Kafka brokers are open and accessible from Moogsoft Onprem .

  • You know the name of the topics for the system to subscribe to.

  • You have the group ID of the consumer group.

Configure the LAM

Edit the configuration file to control the behavior of the Kafka LAM. You can find the file at $MOOGSOFT_HOME/config/kafka_lam.conf.

The configuration file contains a JSON object. At the first layer of the object, the LAM has a parameter called config, and the object that follows config has all the necessary information to control the LAM.

See Kafka Reference and LAM and Integration Reference for a full description of all properties. Some properties in the file are commented out by default; remove the '#' character to enable them.LAM and Integration Reference

  1. Configure the connection properties:

    • kafka_listener: The hostname along with the port of the Kafka broker.

    • topic_name: The name of the topic(s) in the Kafka broker you are consuming events from.

    • groupid: The name of the consumer group.

  2. Configure SSL if you want to encrypt communications between Kafka and Moogsoft Onprem :

    • ssl_connection: Set to true to enable SSL communication.

    • ssl_truststore_filename: The path of the truststore certificate.

    • ssl_truststore_password: The password for the truststore certificate.

    • ssl_keystore_filename: The path of the keystore certificate.

    • ssl_keystore_password: The password for the keystore certificate.

    • ssl_key_password: The password for the client certificate required in client authentication. It is the password entered in the ssl.key.password of the Kafka server.properties file.

  3. To avoid storing SSL passwords in plaintext, set the appropriate encrypted password parameters in the monitor section:

    • encrypted_ssl_truststore_password: Specifies the encrypted truststore password.

    • encrypted_ssl_keystore_password: Specifies the encrypted keystore password.

    • encrypted_ssl_key_password: Specifies the encrypted private-key password.

    Moogsoft Onprem reads these parameters only when ssl_connection is true.

    The following example configures encrypted passwords for the SSL truststore, keystore, and private key:

    monitor:
    {
        ssl_connection: true,
    
        ssl_truststore_filename:
            "/path/to/kafka.client.truststore.jks",
    
        encrypted_ssl_truststore_password:
            "<encrypted-truststore-password>",
    
        ssl_keystore_filename:
            "/path/to/kafka.client.keystore.jks",
    
        encrypted_ssl_keystore_password:
            "<encrypted-keystore-password>",
    
        encrypted_ssl_key_password:
            "<encrypted-key-password>"
    }

    Important

    Do not include real passwords or decrypted values in configuration examples, support bundles, capture logs, or product logs.

  4. Configure the kafka_properties section, which allows you to use Kafka consumer properties. Note that these take priority over the aforementioned SSL properties:

    • ssl.endpoint.identification.algorithm: The endpoint identification algorithm used by clients to validate server host name.

    • sasl.mechanism: The SASL mechanism method for the Kafka broker to use.

    • security.protocol: The security protocol to use.

    • sasl.jaas.config: The type of JAAS authentication configuration to use for the Kafka broker.

    • sasl.jaas.config: Specifies the JAAS login module and its authentication options. For SASL PLAIN or SCRAM authentication, the password option can contain an encrypted password. Set is_password_encrypted to true when the password in sasl.jaas.config is encrypted.

    • sasl.login.refresh.window.factor: If using OAUTHBEARER, the login refresh thread will sleep until the specified window factor relative to the credential's lifetime has been reached, at which time it will attempt to refresh the credential.

    • sasl.login.refresh.window.jitter: The maximum amount of random jitter relative to the credential's lifetime that is added to the login refresh thread's sleep time.

    • sasl.login.refresh.min.period.seconds: The desired minimum time (in seconds) for the login refresh thread to wait before refreshing a credential.

    • sasl.login.refresh.min.buffer.seconds: The amount of buffer time (in seconds) to maintain before credential expiration when refreshing a credential.

    • sasl.kerberos.service.name: The Kerberos service name.

    • is_password_encrypted: Specifies whether the password in sasl.jaas.config is encrypted. The default is false.

      Note

      Set is_password_encrypted to true only when the password value in sasl.jaas.config is encrypted. If you omit this parameter or set it to false, the Kafka LAM treats the password as plaintext.

      Warning

      Do not set is_password_encrypted to true for a plaintext password. The Kafka LAM cannot authenticate if the password format and this setting do not match.

    See the Apache Kafka documentation for more information on these properties.

  5. Configure parsing and tokenisation. See the "Parsing and Tokenisation" section below for more information.

  6. Optionally configure the LAM identification and capture logging details:

    • name: Maps to $Laminstancename, so that the agent field indicates events Moogsoft Onprem ingests from this LAM.

    • capture_log: Name and location of the LAM's capture log file, which it writes to for debugging purposes.

  7. Optionally configure severity conversions. See Severity Reference for further information and "Conversion Rules" in Tokenize Source Event Data for details on conversions in general.Data Parsing

  8. Optionally configure the process logging details:

    • configuration_file: Name and location of the LAM's process log configuration file. See Configure Logging for more information.Configure Logging

Configure the response to a SASL authentication failure

Set on_auth_failure in the monitor section to control how the Kafka LAM responds when Kafka rejects SASL authentication:

  • stop: Stops the Kafka LAM with the KAFKA_AUTHENTICATION_ERROR exit code. This is the default.

  • passive: Requests the passive high-availability state and stops consuming Kafka messages.

The value is not case-sensitive. If you omit the setting or specify an unsupported value, the Kafka LAM uses stop.

The following example configures the Kafka LAM to request the passive high-availability state after a SASL authentication failure:

monitor:
{
    kafka_listener: "kafka.example.com:9093",
    topic_name: [ "events" ],
    groupid: "moogsoft-consumer",
    on_auth_failure: "passive"
}

Note

Use passive only in a correctly configured high-availability deployment. Verify that the peer Kafka LAM can authenticate and consume the assigned topics before you enable this option.

Tip

  • If on_auth_failure is stop, the log contains:

    Shutting down due to Kafka SASL authentication failure.

  • If on_auth_failure is passive, the Kafka LAM sends a passive-state request with the reason:

    Kafka SASL authentication failure.

Parsing and tokenization

Note

The parsing section is used when the event format is a text message; if you have an event with JSON format then comment the parsing and the variables sections and uncomment builtInMapper: "CJsonDecoder" in the Mapping section of kafka_lam.conf.

The Kafka LAM sends incoming messages to the extractor before mapping them. For JSON input, use builtInMapper: "CJsonDecoder" and configure how the extractor handles JSON values and lists.

  • Set accept_all_json to true to accept any valid JSON input. This is the default.

  • Set accept_all_json to false to require the Moog REST LAM protocol.

  • Set lists_contain_multiple_events to true to create one event for each item in a top-level JSON list. This is the default.

  • Set lists_contain_multiple_events to false to process the complete list as one event.

Comment out the parsing and variables sections when you use CJsonDecoder.

The parsing section is used for parsing the received event and tokenizing it.

The Kafka LAM receives data in two formats:

  • Text: The data is received in text format which can be parsed and tokenized in the Parsing section and then mapped to Moogsoft Onprem fields in the Variables and the Mapping section.

  • JSON: The data is received in a JSON format, which can be mapped directly using CJsonDecoder. The parsing and the variable section are not required for JSON format.

Parsing

The following two methods are available for parsing:

  • Text Message: The parsing will start when it gets NEW_MSG and end when it gets new line. The extracted string is then delimited as per the defined delimiters.

    To enable this method set type to start_and_end and then configure the start and end fields.

  • Regular Expression: The parser searches a regular expression for the strings you define in the pattern field and delimits them in accordance with your configuration of delimiters.

    To enable this method set type to regexp.

Only use one parsing method at a time, commenting out the ones you are not using. See Tokenize Source Event Data for more information.Data Parsing

Tokenization

The parsed events are tokenized using either delimiters or the regexp_subgroups. See the Kafka Reference for more information.

Process JSON lists

The following configuration creates one event for each item in a top-level JSON list: monitor:

monitor:
{
    accept_all_json: true,
    lists_contain_multiple_events: true
},
mapping:
{
    builtInMapper: "CJsonDecoder",
    catchAll: "overflow",
    rules:
    [
        { name: "signature", rule: "$signature" },
        { name: "source", rule: "$source" },
        { name: "severity", rule: "$severity" },
        { name: "description", rule: "$description" }
    ]
}

For example, a Kafka message containing the following list creates two candidate events:

[
  {
    "signature": "host-01:disk",
    "source": "host-01",
    "severity": 4,
    "description": "Disk usage is high"
  },
  {
    "signature": "host-02:cpu",
    "source": "host-02",
    "severity": 3,
    "description": "CPU usage is high"
  }
]

To pass the complete list to mapping as one event, set:

lists_contain_multiple_events: false

Variables

Note

The variable section is used when the received event message type is TextMessage; a JSON event can be mapped directly to the Moog field in the Mapping section.

A received event is a positioned collection of tokens. The variables section enables you to name these positions. The naming of the positions helps you to identify the tokens.

Positions start at 1 and increase. In the example below, the token in position number 6 is a Manager name, so the user names the token as "Manager". The naming helps in mapping the tokens to the Moogsoft Onprem fields in the mapping section.

variables:
        [
            { name: "signature",   position: 1 },
            { name: "source_id",   position: 4 },
            { name: "external_id", position: 3 },
            { name: "Manager",     position: 6 },
            { name: "AlertGroup",  position: 7 },
            { name: "Class",       position: 8 },
            { name: "Agent",       position: 9 },
            { name: "severity",    position: 5 },
            { name: "description", position: 10 },
            { name: "agent_time",  position: 2 }
        ],

Map LAM properties

For events received in JSON format, you can directly map the event fields of Kafka. In the case of an event received in text format, the event is first tokenized in the Variable section, and the tokenized event is then mapped here. The parameters of the received events are displayed in Moogsoft Onprem accordingly.

Kafka Event Property

Kafka LAM Event Property

Agent

$LamInstanceName

Agent Location

$agent_location

Agent Time

$agent_time

Class

$class

Description

$description

External ID

$external_id

Manager

Kafka

Severity

$severity

Signature

$signature

Source ID

$source_id

Type

$type

The above example specifies the mapping of the Kafka alarm fields with the Moogsoft Onprem fields.

Example

An example Kafka LAM configuration is as follows:

monitor:
{
        name: "Kafka Lam Monitor",
        class: "CKafkaMonitor",
        kafka_listener: "localhost:9092",
        topic_name: [
                     "topic1",
                     "topic2"
                    ],                       
        groupid: "consumer-group",
        ssl_connection: false
}

parsing:
        {
            type: "start_and_end",
            start_and_end:
            {
                start: [],
                end: ["\n"],

                delimiters:
                {

                    ignoreQuotes: true,
                    stripQuotes: true,
                    ignores: "",
                    delimiter: [",","\r"]
                }
            }
        },

         #parsing:
         #{
             #type: "regexp",
             #regexp:
             #{
                 #pattern: "(?mU)^(.*)$",
                 #capture_group: 1,
                 #tokeniser_type: "delimiters",
                 #delimiters:
                 #{
                         #ignoreQuotes: true,
                         #stripQuotes: false,
                         #ignores: "",
                         #delimiter: ["\r"]
                 #}
             #}
         #},

        variables:
        [
            { name: "signature", position: 1 },
            { name: "source_id", position: 4 },
            { name: "external_id", position: 3 },
            { name: "Manager", position: 6 },
            { name: "AlertGroup", position: 7 },
            { name: "Class", position: 8 },
            { name: "Agent", position: 9 },
            { name: "severity", position: 5 },
            { name: "description", position: 10 },
            { name: "agent_time", position: 2 }
        ],

        mapping:
        {

            builtInMapper: "CJsonDecoder",
            catchAll: "overflow",
            rules:
            [
                { name: "signature", rule: "$signature" },
                { name: "source_id", rule: "$source_id" },
                { name: "external_id", rule: "$external_id" },
                { name: "manager", rule: "Kafka" },
                { name: "source", rule: "$source" },
                { name: "class", rule: "$class" },
                { name: "agent", rule: "$LamInstanceName" },
                { name: "agent_location", rule: "$agent_location" },
                { name: "type", rule: "$type" },
                { name: "severity", rule: "$severity", conversion: "sevConverter" },
                { name: "description", rule: "$description" },
                { name: "agent_time", rule: "$agent_time" }
            ]
        },

    }
    ,log_config:
    {
       configuration_file: "$MOOGSOFT_HOME/config/logging/custom.log.json"
    }
}
{
    config:
    {
        monitor:
        {
            name: "Kafka Lam Monitor",
            class: "CKafkaMonitor",

            kafka_listener: "localhost:9092",

            topic_name:
            [
                "topic1",
                "topic2"
            ],

            groupid: "consumer-group",

            ssl_connection: false,

            # Configure the following properties when
            # ssl_connection is true.
            #
            # ssl_truststore_filename:
            #     "/path/to/kafka.client.truststore.jks",
            #
            # Use either ssl_truststore_password or
            # encrypted_ssl_truststore_password.
            #
            # ssl_truststore_password:
            #     "<truststore-password>",
            #
            # encrypted_ssl_truststore_password:
            #     "<encrypted-truststore-password>",

            # ssl_keystore_filename:
            #     "/path/to/kafka.client.keystore.jks",
            #
            # Use either ssl_keystore_password or
            # encrypted_ssl_keystore_password.
            #
            # ssl_keystore_password:
            #     "<keystore-password>",
            #
            # encrypted_ssl_keystore_password:
            #     "<encrypted-keystore-password>",
            #
            # Use either ssl_key_password or
            # encrypted_ssl_key_password.
            #
            # ssl_key_password:
            #     "<key-password>",
            #
            # encrypted_ssl_key_password:
            #     "<encrypted-key-password>",

            # Specifies how the Kafka LAM responds to a Kafka SASL
            # authentication failure.
            #
            # Valid values are "stop" and "passive". The value is
            # not case-sensitive. If the property is omitted or
            # contains an unsupported value, the LAM uses "stop".
            #
            # stop:
            # Stops the LAM with the KAFKA_AUTHENTICATION_ERROR
            # exit code.
            #
            # passive:
            # Requests the passive HA state and stops consuming
            # messages.
            #
            # The default is "stop".
            #
            # on_auth_failure: "stop",

            # Specifies whether the Kafka LAM accepts any valid
            # JSON input.
            #
            # Set to false to require input that conforms to the
            # Moog REST LAM protocol.
            #
            # The default is true.
            #
            # accept_all_json: true,

            # Specifies whether each item in a top-level JSON list
            # represents a separate event.
            #
            # Set to false to process the complete list as one
            # event.
            #
            # The default is true.
            #
            # lists_contain_multiple_events: true,

            kafka_properties:
            {
                # Kafka consumer properties configured in this
                # section take priority over equivalent SSL
                # properties in the monitor section.

                # "ssl.endpoint.identification.algorithm": "HTTPS",

                # Configure the following properties for SASL
                # authentication.
                #
                # "security.protocol": "SASL_SSL",
                # "sasl.mechanism": "PLAIN",

                # For SASL PLAIN authentication, specify the login
                # module, username, and password.
                #
                # "sasl.jaas.config":
                #     "org.apache.kafka.common.security.plain.PlainLoginModule required username=alice password=<encrypted-password>;",

                # Specifies whether the password in
                # sasl.jaas.config is encrypted.
                #
                # Set to true only when sasl.jaas.config contains
                # an encrypted password. The default is false.
                #
                # "is_password_encrypted": true,

                # The following properties apply to OAuth or
                # Kerberos authentication.
                #
                # "sasl.login.refresh.window.factor": 0.8,
                # "sasl.login.refresh.window.jitter": 0.05,
                # "sasl.login.refresh.min.period.seconds": 60,
                # "sasl.login.refresh.min.buffer.seconds": 300,
                # "sasl.kerberos.service.name": "kafka"
            }
        },

        # Use the parsing and variables sections for text input.
        # Comment out both sections when you use CJsonDecoder for
        # JSON input.
        parsing:
        {
            type: "start_and_end",

            start_and_end:
            {
                start: [],
                end: ["\n"],

                delimiters:
                {
                    ignoreQuotes: true,
                    stripQuotes: true,
                    ignores: "",
                    delimiter: [",", "\r"]
                }
            }
        },

        # Alternatively, use the following regular expression
        # parser. Enable only one parsing method at a time.
        #
        # parsing:
        # {
        #     type: "regexp",
        #
        #     regexp:
        #     {
        #         pattern: "(?mU)^(.*)$",
        #         capture_group: 1,
        #         tokeniser_type: "delimiters",
        #
        #         delimiters:
        #         {
        #             ignoreQuotes: true,
        #             stripQuotes: false,
        #             ignores: "",
        #             delimiter: ["\r"]
        #         }
        #     }
        # },

        variables:
        [
            {
                name: "signature",
                position: 1
            },
            {
                name: "source_id",
                position: 4
            },
            {
                name: "external_id",
                position: 3
            },
            {
                name: "Manager",
                position: 6
            },
            {
                name: "AlertGroup",
                position: 7
            },
            {
                name: "Class",
                position: 8
            },
            {
                name: "Agent",
                position: 9
            },
            {
                name: "severity",
                position: 5
            },
            {
                name: "description",
                position: 10
            },
            {
                name: "agent_time",
                position: 2
            }
        ],

        mapping:
        {
            # Uncomment the following property for JSON input.
            # Comment out the parsing and variables sections when
            # you enable CJsonDecoder.
            #
            # builtInMapper: "CJsonDecoder",

            catchAll: "overflow",

            rules:
            [
                {
                    name: "signature",
                    rule: "$signature"
                },
                {
                    name: "source_id",
                    rule: "$source_id"
                },
                {
                    name: "external_id",
                    rule: "$external_id"
                },
                {
                    name: "manager",
                    rule: "Kafka"
                },
                {
                    name: "source",
                    rule: "$source"
                },
                {
                    name: "class",
                    rule: "$class"
                },
                {
                    name: "agent",
                    rule: "$LamInstanceName"
                },
                {
                    name: "agent_location",
                    rule: "$agent_location"
                },
                {
                    name: "type",
                    rule: "$type"
                },
                {
                    name: "severity",
                    rule: "$severity",
                    conversion: "sevConverter"
                },
                {
                    name: "description",
                    rule: "$description"
                },
                {
                    name: "agent_time",
                    rule: "$agent_time"
                }
            ]
        },

        filter:
        {
            presend: "KafkaLam.js"
        }
    },

    log_config:
    {
        configuration_file:
            "$MOOGSOFT_HOME/config/logging/custom.log.json"
    }
}

Configure for High Availability

Configure the Kafka LAM for high availability if required. See High Availability Overview for details.

Configure LAMbot processing

The Kafka LAMbot processes and filters events before sending them to the Message Bus. You can customize or bypass this processing if required. You can also load JavaScript files into the LAMbot and execute them.

The Kafka LAMbot can process a message at two stages:

  • Use modifyResponse() to modify or discard the raw Kafka message before extraction, parsing, tokenization, and mapping.

  • Use presend() to process or discard the mapped event before the LAM sends it to the Message Bus.

You can customize or bypass this processing if required. You can also load JavaScript files into the LAMbot and execute them.

See LAMbot Configuration for more information. An example Kafka LAM filter configuration is shown below.

filter:
{
    presend: "KafkaLam.js",
}

Modify a raw Kafka message

The Kafka LAM calls modifyResponse() for every Kafka message before tokenization. The function receives an inBoundEventData object with these fields:

  • responseData: Raw Kafka message.

  • moog_target_name: Always Kafka Server.

  • moog_target_url: Value of kafka_listener.

Return true to continue processing. For example:

function modifyResponse(inBoundEventData)
{
    var response = JSON.parse(inBoundEventData.value("responseData"));

    response.manager = "Kafka";

    inBoundEventData.set(
        "responseData",
        JSON.stringify(response)
    );

    return true;
}

LamBot.modifyResponseFunction("modifyResponse");

Return false to discard the message. For example:

LamBot.modifyResponseFunction("modifyResponse");


function modifyResponse(inBoundEventData)
{
    var response = JSON.parse(inBoundEventData.value("responseData"));

    if (response.environment === "test")
    {
        return false;
    }

    return true;
}

LamBot.modifyResponseFunction("modifyResponse");

Note

If you do not register the hook, the LAM processes messages without modification.

Important

modifyResponse() runs before mapping and before presend(). Validate the modified responseData format against the configured parser or JSON mapper. Returning false discards the Kafka message and prevents later processing.

Start and stop the LAM

Restart the Kafka LAM to activate any changes you make to the configuration file or LAMbot.

The LAM service name is kafkalamd.

See Control Moogsoft Onprem Processes for the commands to start, stop and restart the LAM.