# 新建 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: node_offline
}
# 请求示例
# 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 扩展插件

# 简介

删除 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 扩展插件

# 简介

修改 Lua 扩展插件

# Uri
PUT /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: node_offline
}
# 请求示例
# Shell
curl -X PUT\
  -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}

# 获取 Lua 扩展插件

# 简介

获取 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 扩展插件执行历史

# 简介

获取 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
            }
        ]
    }
}