# Global Lua Extensions

# Create Lua extensions

# Description

Create Lua extensions

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

# Example Request

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

# Example Response

Status: 200 OK

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

# Delete Lua extensions

# Description

Delete Lua extensions

# URI

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

# Example Request

# Shell

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

# Example Response

Status: 200 OK

{"status":0}

# Modify Lua extensions

# Description

Modify Lua extensions

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

# Example Request

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

# Example Response

Status: 200 OK

{"status":0}

# Get Lua extensions

# Description

Get Lua extensions

# URI

GET /admin-api/global/1/lua_extensions

# URI parameter

  • 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)

# Example Request

# Shell

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

# Example Response

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

# Get Lua extensions histories

# Description

Get Lua extensions histories

# URI

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

# URI parameter

  • 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)

# Example Request

# Shell

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

# Example Response

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

# Get all Lua extensions histories

# Description

Get all Lua extensions histories

# URI

GET /admin-api/lua_extension/histories

# URI parameter

  • 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)

# Example Request

# Shell

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

# Example Response

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