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
}
}
}