Lua 擴充套件外掛

新建 Lua 擴充套件外掛

URI

POST /admin-api/global/1/lua_extensions

JSON body 引數

{
    "name": "test",
    "code": "local result = sql_query(\"select count(*) from users\")\n output(result)",
    "trigger_type": "cron", // trigger_type: cron, event
    "interval": 30 // timed trigger interval
}

or

{
    "name": "test",
    "code": "local result = sql_query(\"select count(*) from users\")\n output(result)",
    "trigger_type": "event", // trigger_type: cron, event
    "event_types": [ "node_offline" ] // event_type: nodes_offline, nodes_online, release
}

請求示例

Shell

curl \
  -H "API-Token: 1df87165-3593-4eca-a910-9ac20005e6ec" \
  http://{admin-site}/admin-api/global/1/lua_extensions \
  -d $'{"name":"test2","code":"local result = sql_query(\"select count(*) from users\")\n output(result)","trigger_type":"cron","interval":30}'

響應示例

Status: 200 OK

{"status":0,"data":{"id":1}}

刪除 Lua 擴充套件外掛

URI

DELETE /admin-api/global/1/lua_extensions/{extension_id}

請求示例

Shell

curl -X delete \
  -H "API-Token: 1df87165-3593-4eca-a910-9ac20005e6ec" \
  http://{admin-site}/admin-api/global/1/lua_extensions/1

響應示例

Status: 200 OK

{"status":0}

修改 Lua 擴充套件外掛

URI

PUT /admin-api/global/1/lua_extensions/{extension_id}

JSON body 引數

{
    "name": "test",
    "code": "local result = sql_query(\"select count(*) from users\")\n output(result)",
    "trigger_type": "cron", // trigger_type: cron, event
    "interval": 30 // timed trigger interval
}

or

{
    "name": "test",
    "code": "local result = sql_query(\"select count(*) from users\")\n output(result)",
    "trigger_type": "event", // trigger_type: cron, event
    "event_types": [ "node_offline" ] // event_type: node_offline
}

請求示例

Shell

curl -X PUT\
  -H "API-Token: 1df87165-3593-4eca-a910-9ac20005e6ec" \
  http://{admin-site}/admin-api/global/1/lua_extensions/1 \
  -d $'{"name":"test2","code":"local result = sql_query(\"select count(*) from users\")\n output(result)","trigger_type":"cron","interval":30}'

響應示例

Status: 200 OK

{"status":0}

獲取 Lua 擴充套件外掛

URI

GET /admin-api/global/1/lua_extensions

URI引數

  • detail

    type: integer

    required: no

    description: Are detailed results required (default 0)

  • page

    type: integer

    required: no

    description: Results page (default 1)

  • page_size

    type: integer

    required: no

    description: Results page size (default 20)

請求示例

Shell

curl \
  -H "API-Token: 1df87165-3593-4eca-a910-9ac20005e6ec" \
  http://{admin-site}/admin-api/global/1/lua_extensions

響應示例

Status: 200 OK
{
    "status": 0,
    "data": {
        "meta": {
            "count": 5
        },
        "data": [
            {
                "code": "output(\"hello world\")",
                "name": "test1",
                "trigger_type": "cron",
                "id": 1,
                "interval": 30,
                "executed_time": 1617951397
            },
            {
                "trigger_type": "event",
                "code": "print \"hello world\"",
                "id": 5,
                "name": "custom_lua_extension",
                "event_types": [
                    "node_offline"
                ]
            }
        ]
    }
}

獲取 Lua 擴充套件外掛執行歷史

URI

GET /admin-api/global/1/lua_extensions/{extension_id}/histories

URI 引數

  • detail

    type: integer

    required: no

    description: Are detailed results required (default 0)

  • page

    type: integer

    required: no

    description: Results page (default 1)

  • page_size

    type: integer

    required: no

    description: Results page size (default 20)

請求示例

Shell

curl \
  -H "API-Token: 1df87165-3593-4eca-a910-9ac20005e6ec" \
  http://{admin-site}/admin-api/global/1/lua_extensions/1/histories

響應示例

Status: 200 OK
{
    "status": 0,
    "data": {
        "meta": {
            "count": 1
        },
        "data": [
            {
                "end_time": 1617954007, // execution end time
                "status": 0, // 0: failed; 1: completed
                "result": "test4:14: query timeout", // execution results
                "start_time": 1617954006, // execution start time
                "id": 4
            }
        ]
    }
}

獲取所有 Lua 擴充套件外掛的歷史

URI

GET /admin-api/lua_extension/histories

URI 引數

  • start_time

    type: integer

    required: no

    description: Query start time (default an hour ago)

  • end_time

    type: integer

    required: no

    description: Query end time (default now)

  • page

    type: integer

    required: no

    description: Results page (default 1)

  • page_size

    type: integer

    required: no

    description: Results page size (default 20)

請求示例

Shell

curl \
  -H "API-Token: 1df87165-3593-4eca-a910-9ac20005e6ec" \
  http://{admin-site}/admin-api/lua_extension/histories

響應示例

Status: 200 OK
{
    "time": 1619160759,
    "status": 0,
    "data": {
        "data": [
            {
                "result": "test6:14: openresty could not be resolved (3: Host not found), try: 1\nopenresty could not be resolved (3: Host not found), try: 2\nopenresty could not be resolved (3: Host not found), try: 3",
                "_global_lua_extensions_id": 6,
                "_modified_unix": "2021-04-22 23:52:34.485011",
                "name": "test6", // lua extension name
                "start_time": 1619160751,
                "end_time": 1619160754,
                "id": 46,
                "status": 0,
                "_created_unix": "2021-04-22 23:52:34.485011",
                "_global_id": 1
            }
        ],
        "meta": {
            "count": 46
        }
    }
}