SLS component

更新时间:
复制 MD 格式

The SLS component integrates Simple Log Service (SLS) into SOAR playbooks, letting you query logs and write log entries as part of automated security response workflows.

Actions

ActionDescription
run_queryQueries logs from an SLS Logstore.
putLogsWrites log entries to an SLS Logstore.

Prerequisites

Before you begin, ensure that you have:

  • An SLS project and Logstore

  • An AccessKey ID and AccessKey secret with permission to operate Simple Log Service APIs

  • (For RAM users) The required Simple Log Service API permissions granted to the RAM user

Configure an instance

Configure the SLS connection before adding the component to a playbook.

  1. Click the component node, then open the Basic Information Configuration tab and click Resource Instance Configuration.

  2. On the Resource Instance Configuration page, click Add and fill in the following parameters.

ParameterDescriptionRequired
assetnameA name for this resource instance. Choose a name that identifies the SLS connection in your playbooks.Yes
end_pointThe SLS service endpoint for your region. For a list of endpoints, see Service endpoints.Yes
sub_idThe AccessKey ID. To create an AccessKey, see Create an AccessKey.Yes
access_keyThe AccessKey secret corresponding to the AccessKey ID.Yes

run_query

Queries logs from an SLS Logstore using SQL syntax.

Parameters

ParameterDescriptionRequired
projectThe name of the SLS project to query.Yes
logstoreThe name of the Logstore to query.Yes
endpointThe SLS service endpoint. For a list of endpoints, see Service endpoints.Yes
queryThe SQL query to run. For SQL syntax reference, see SQL syntax and functions.Yes
fromThe query start time, in Unix epoch milliseconds. For example, <%=currentTimeToMs()- 100 * 60 * 1000L%> sets the start time to 100 minutes before the current time.Yes
toThe query end time, in Unix epoch milliseconds. For example, <%=currentTimeToMs()%> sets the end time to the current time.Yes
limitThe maximum number of log entries to return. Maximum value: 10,000.No
Important

If you use an analysis statement and limit exceeds 100, include an ORDER BY clause in your query. Without it, some results may be missing.

Example configuration

{
  "actionName": "run_query",
  "valueData": {
    "project": "test_project",
    "logstore": "test_logstore",
    "endpoint": "cn-shangzhou.log.aliyuncs.com",
    "query": "*",
    "from": "<%=currentTimeToMs()- 100 * 60 * 1000L%>",
    "to": "<%=currentTimeToMs()%>",
    "limit": "10"
  }
}

putLogs

Writes log entries to an SLS Logstore.

Parameters

ParameterDescriptionRequired
projectThe name of the SLS project to write to.Yes
logstoreThe name of the Logstore to write to.Yes
endpointThe SLS service endpoint.Yes
topicA user-defined label for the batch of log entries. Use this field to group or filter logs.No
logItemsThe log data to write, as a JSON string. Supports JSON objects and JSON arrays—for example, {"test":"test"}. A _logUuid field is automatically added to each entry as a unique identifier, which you can use to query recently written logs.Yes

Example configuration

{
  "actionName": "putLogs",
  "valueData": {
    "project": "test_project",
    "logstore": "test_logstore",
    "endpoint": "cn-shangzhou.log.aliyuncs.com",
    "topic": "test",
    "logItems": "{\"test\":\"test\"}"
  }
}

Import as a test playbook

You can import the example configurations as a test playbook to explore and validate the component in the visual flow editor.

  1. Save the full playbook JSON (see below) as a .json file.

  2. Import the file following the steps in Playbook import.

The following JSON contains both actions in sequence: run_query first, then putLogs using the query results.

Full playbook JSON

{
    "cells": [
        {
            "shape": "custom-edge",
            "zIndex": 1,
            "id": "SequenceFlow_0yvd0ew",
            "data": {
                "nodeType": "sequenceFlow",
                "appType": "basic",
                "icon": "icon-upper-right-arrow",
                "isRequired": false
            },
            "labels": [],
            "isNode": false,
            "source": {
                "cell": "Action_15qsqhz"
            },
            "target": {
                "cell": "32124b94-ecd0-4370-9878-c08676bacde4"
            },
            "vertices": []
        },
        {
            "position": {
                "x": -560,
                "y": 0
            },
            "size": {
                "width": 137,
                "height": 66
            },
            "view": "react-shape-view",
            "shape": "activity",
            "id": "Action_15qsqhz",
            "zIndex": 1,
            "data": {
                "nodeType": "action",
                "appType": "component",
                "nodeName": "SLS_1",
                "valueData": {
                    "query": "*",
                    "limit": "10",
                    "project": "test_project",
                    "from": "<%=currentTimeToMs()- 100 * 60 * 1000L%>",
                    "to": "<%=currentTimeToMs()%>",
                    "logstore": "test_logstore",
                    "endpoint": "cn-shangzhou.log.aliyuncs.com"
                },
                "advance": {
                    "inputParamMode": false,
                    "onError": "stop_cur_flow",
                    "rspStatusType": "3",
                    "rspStatusThreshold": "0",
                    "description": "Query logs from SLS"
                },
                "componentName": "SLS",
                "actionName": "run_query",
                "assetUuid": "54c20873-deb3-4474-bdc2-12aba357acb4",
                "cascaderValue": []
            },
            "isNode": true
        },
        {
            "position": {
                "x": -788,
                "y": 15
            },
            "size": {
                "width": 36,
                "height": 36
            },
            "attrs": {
                "body": {
                    "fill": "white",
                    "strokeOpacity": 0.95,
                    "stroke": "black",
                    "strokeWidth": 2
                },
                "label": {
                    "text": "",
                    "fontSize": 12,
                    "refX": 0.5,
                    "refY": "100%",
                    "refY2": 4,
                    "textAnchor": "middle",
                    "textVerticalAnchor": "top"
                }
            },
            "visible": true,
            "shape": "circle",
            "id": "StartEvent_1",
            "zIndex": 1,
            "data": {
                "nodeType": "startEvent",
                "appType": "basic",
                "valueData": {},
                "icon": "icon-circle"
            },
            "markup": [
                {
                    "tagName": "circle",
                    "selector": "body"
                },
                {
                    "tagName": "text",
                    "selector": "label"
                }
            ],
            "isNode": true
        },
        {
            "position": {
                "x": -21,
                "y": 25
            },
            "size": {
                "width": 36,
                "height": 36
            },
            "attrs": {
                "body": {
                    "fill": "white",
                    "strokeOpacity": 0.95,
                    "stroke": "black",
                    "strokeWidth": 2
                },
                "path": {
                    "r": 12,
                    "refX": "50%",
                    "refY": "50%",
                    "fill": "black",
                    "strokeOpacity": 0.95,
                    "stroke": "black",
                    "strokeWidth": 4
                },
                "label": {
                    "text": "",
                    "fontSize": 12,
                    "refX": 0.5,
                    "refY": "100%",
                    "refY2": 4,
                    "textAnchor": "middle",
                    "textVerticalAnchor": "top"
                }
            },
            "visible": true,
            "shape": "circle",
            "id": "EndEvent_1bi7n65",
            "zIndex": 1,
            "data": {
                "nodeType": "endEvent",
                "appType": "basic",
                "valueData": {},
                "icon": "icon-radio-off-full"
            },
            "markup": [
                {
                    "tagName": "circle",
                    "selector": "body"
                },
                {
                    "tagName": "circle",
                    "selector": "path"
                },
                {
                    "tagName": "text",
                    "selector": "label"
                }
            ],
            "isNode": true
        },
        {
            "shape": "custom-edge",
            "zIndex": 1,
            "id": "SequenceFlow_0d1fm8e",
            "data": {
                "nodeType": "sequenceFlow",
                "appType": "basic",
                "icon": "icon-upper-right-arrow",
                "isRequired": false
            },
            "labels": [],
            "isNode": false,
            "source": {
                "cell": "StartEvent_1"
            },
            "target": {
                "cell": "Action_15qsqhz"
            },
            "vertices": [],
            "visible": true,
            "router": {
                "name": "manhattan",
                "args": {
                    "padding": 5,
                    "excludeHiddenNodes": true,
                    "excludeNodes": [
                        "clone_node_id"
                    ]
                }
            }
        },
        {
            "position": {
                "x": -304,
                "y": 0
            },
            "size": {
                "width": 137,
                "height": 66
            },
            "view": "react-shape-view",
            "shape": "activity",
            "id": "32124b94-ecd0-4370-9878-c08676bacde4",
            "zIndex": 1,
            "data": {
                "nodeType": "action",
                "appType": "component",
                "nodeName": "SLS_2",
                "valueData": {
                    "logItems": "{\"test\":\"test\"}",
                    "project": "test_project",
                    "logstore": "test_logstore",
                    "endpoint": "cn-shangzhou.log.aliyuncs.com",
                    "topic": "test"
                },
                "description": "Write data to SLS",
                "advance": {
                    "inputParamMode": false,
                    "onError": "stop_cur_flow",
                    "rspStatusType": 3,
                    "rspStatusThreshold": 0
                },
                "componentName": "SLS",
                "actionName": "putLogs",
                "assetUuid": "54c20873-deb3-4474-bdc2-12aba357acb4",
                "cascaderValue": [
                    {
                        "label": "SLS_1",
                        "value": "${SLS_1}",
                        "children": []
                    }
                ]
            },
            "isNode": true
        },
        {
            "shape": "custom-edge",
            "zIndex": 1,
            "id": "0823a20d-6441-4cef-83e0-0d04dc14fc3b",
            "data": {
                "nodeType": "sequenceFlow",
                "appType": "basic",
                "icon": "icon-upper-right-arrow",
                "isRequired": false
            },
            "labels": [],
            "isNode": false,
            "source": {
                "cell": "32124b94-ecd0-4370-9878-c08676bacde4"
            },
            "target": {
                "cell": "EndEvent_1bi7n65"
            },
            "vertices": []
        }
    ]
}