全部產品
Search
文件中心

Elasticsearch:CreateCollector

更新時間:Jan 16, 2025

調用CreateCollector,建立採集器。

調試

您可以在OpenAPI Explorer中直接運行該介面,免去您計算簽名的困擾。運行成功後,OpenAPI Explorer可以自動產生SDK程式碼範例。

要求標頭

該介面使用公用要求標頭,無特殊要求標頭。請參見公用請求參數文檔。

請求文法

POST /openapi/collectors HTTP/1.1

請求參數

名稱 類型 位置 是否必選 樣本值 描述
clientToken String Query 5A2CFF0E-5718-45B5-9D4D-70B3FF****

用於保證請求的等冪性。由用戶端產生該參數值,要保證在不同請求間唯一,最大不超過64個ASCII字元。

Object Body

請求體參數。用來指定待建立採集器的配置資訊。

dryRun Boolean Body true

是否校正並建立採集器,只有在建立或更新採集器時使用此參數。可選值:

  • true:只校正不更新
  • false:校正並更新
name String Body ct-test

採集器名稱。長度為1~30個字元,以大小寫字母開頭,可以包含字母、數字、底線(_)或連字號(-)。

resType String Body fileBeat

採集器類型。可選值:fileBeat、metricBeat、heartBeat和auditBeat。

vpcId String Body vpc-bp12nu14urf0upaf*****

採集器所在的專用網路ID。

resVersion String Body 6.8.5_with_community

採集器版本。可選值:

  • 基於ECS部署:6.8.5_with_community
  • 基於ACK部署:6.8.13_with_community
collectorPaths Array of String Body ["/var/log"]

fileBeat採集路徑。僅當採集器的安裝機器為ECS時,需要配置。

configs Array Body

採集器的設定檔資訊。

fileName String Body filebeat.yml

檔案名稱。

content String Body "filebeat.inputs:xxx"

檔案內容。

extendConfigs Array of Object Body { "instanceId": "es-cn-nif201ihd0012****", "instanceType": "elasticsearch", "configType": "collectorTargetInstance", "hosts": [ "es-cn-nif201ihd0012****.elasticsearch.aliyuncs.com:9200" ], "userName": "elastic", "password": "*****", "protocol": "HTTP" }, { "type": "ECSInstanceId", "configType": "collectorDeployMachine", "machines": [ { "instanceId": "i-bp11u91xgubypcuz****" } ] } ]

採集器擴充配置,詳情請參見下文的extendConfigs參數說明章節。

extendConfigs參數說明

extendConfigs中的參數含義如下。

名稱

類型

是否必選

樣本值

描述

extendConfigs

Array

採集器擴充配置。

└configType

String

collectorElasticsearchForKibana

配置類型。可選值:collectorTargetInstance(採集器Output)、collectorDeployMachine(採集器的部署機器)、collectorElasticsearchForKibana(支援Kibana儀錶盤的Elasticsearch執行個體資訊)。

└type

String

ECSInstanceId

採集器部署的機器類型。可選值:ECSInstanceId(ECS)、ACKCluster(容器Kubernetes)。當configTypecollectorDeployMachine時必填。

└instanceType

String

elasticsearch

採集器Output指定的執行個體類型。可選值:elasticsearch、logstash。當configTypecollectorTargetInstance時必填。

└instanceId

String

es-cn-nif201ihd0012****

採集器關聯的執行個體ID。當configTypecollectorTargetInstance時,為採集器Output的執行個體ID;當configTypecollectorDeployMachines,且typeACKCluster時,為ACK叢集ID。

└machines

Array

採集器所部署的ECS機器列表資訊。當configTypecollectorDeployMachines,且typeECSInstanceId時,必填。

└└instanceId

String

i-bp11u91xgubypcuz****

ECS機器ID列表。

└groupId

String

default_ct-cn-5i2l75bz4776****

機器組ID。當configTypecollectorDeployMachine時,必填。

└protocol

String

HTTP

傳輸協議,需要與採集器Output指定執行個體的訪問協議保持一致。可選值:HTTP、HTTPS。當configTypecollectorTargetInstance時必填。

└userName

String

elastic

採集器Output指定執行個體的訪問使用者名稱,預設為elastic。當configTypecollectorTargetInstancecollectorElasticsearchForKibana時必填。

└password

String

*****

對應使用者名稱的密碼。

└enableMonitoring

Boolean

true

是否啟用Monitoring,當configTypecollectorTargetInstance,且instanceTypeelasticsearch時必填。可選值:true(啟用)、false(不啟用)。

└hosts

List<String>

["es-cn-nif201i*****.elasticsearch.aliyuncs.com:9200"]

採集器Output指定執行個體的訪問地址清單。當configTypecollectorTargetInstance時必填。

└host

String

es-cn-nif201ihd0012****-kibana.internal.elasticsearch.aliyuncs.com:5601

啟用Kibana Dashboard後,Kibana的私網訪問地址。當configTypecollectorElasticsearchForKibana時必填。

└kibanaHost

String

https://es-cn-nif201ihd0012****.kibana.elasticsearch.aliyuncs.com:5601

啟用Kibana Dashboard後,Kibana的公網訪問地址。當configTypecollectorElasticsearchForKibana時必填。

說明 └表示子參數。

extendConfigs中包括3種configType,分別為collectorTargetInstance、collectorElasticsearchForKibana、collectorDeployMachine,部署機器不同,需要配置的參數不同,具體組合方式如下:

  • collectorTargetInstance
    • ECS

      configType、instanceId、instanceType、hosts、userName、password、protocol、enableMonitoring

    • ACK

      configType、instanceId、instanceType、userName、password、protocol、enableMonitoring

  • collectorElasticsearchForKibana
    • ECS

      configType、instanceId、host、kibanaHost、userName、password、protocol

    • ACK

      configType

  • collectorDeployMachine
    • ECS

      configType、type、machines、groupId

    • ACK

      configType、type、instanceId

返回資料

名稱 類型 樣本值 描述
RequestId String 8466BDFB-C513-4B8D-B4E3-5AB256AB****

請求ID。

Result Object

返回結果。

resId String ct-cn-4135is2tj194p****

建立成功的採集器ID。

樣本

請求樣本

POST /openapi/collectors?clientToken=5A2CFF0E-5718-45B5-9D4D-70B3FF**** HTTP/1.1
Host:elasticsearch.aliyuncs.com
Content-Type:application/json

{
    "dryRun": false, 
    "name": "test_beats_1", 
    "resType": "fileBeat", 
    "resVersion": "6.8.5_with_community", 
    "vpcId": "vpc-bp12nu14urf0upaf*****", 
    "collectorPaths": [
        "/var/log"
    ], 
    "extendConfigs": [
        {
            "instanceId": "es-cn-nif201ihd0012****", 
            "instanceType": "elasticsearch", 
            "configType": "collectorTargetInstance", 
            "hosts": [
                "es-cn-nif201ihd0012****.elasticsearch.aliyuncs.com:9200"
            ], 
            "userName": "elastic", 
            "password": "*****", 
            "protocol": "HTTP"
        }, 
        {
            "type": "ECSInstanceId", 
            "configType": "collectorDeployMachine", 
            "machines": [
                {
                    "instanceId": "i-bp11u91xgubypcuz****"
                }
            ]
        }
    ], 
    "configs": [
        {
            "fileName": "filebeat.yml", 
            "content": "filebeat.inputs:xxx"
        }, 
        {
            "fileName": "fields.yml", 
            "content": "- key: log\n title: Log file content\n description: >\n Contains log file lines.\n ...."
        }
    ]
}

正常返回樣本

JSON格式

HTTP/1.1 200 OK
Content-Type:application/json

{
  "Result" : {
    "resId" : "ct-cn-4135is2tj194p****"
  },
  "RequestId" : "8466BDFB-C513-4B8D-B4E3-5AB256AB****"
}

錯誤碼

訪問錯誤中心查看更多錯誤碼。