SOLVED: Luci app ubus access

Struggling to find up-to-date documentation on pulling information from ubus inside of the luci app.

Is this still valid: https://wiki.openwrt.org/doc/techref/ubus#lua_module_for_ubus ? I can't make it work inside the lua shell.

I've searched the luci repo for ubus and found two ways it's being used by current code:


and

In ash I do: echo "$(ubus call service list "{\"name\": \"${packageName}\"}" | jsonfilter -l1 -e "@['${packageName}']['instances']['status']['data']['status']")", how do I do the same in lua/luci app?

Thanks!

Solution: do not use local for variable declarations in lua console.

New URL: https://openwrt.org/docs/techref/ubus#lua_module_for_ubus

1 Like

Both wiki approach and using luci.util.ubus work. I ended up doing this:

local util = require "luci.util"
local serviceName = "myService"
local status = util.ubus('service', 'list', { name = serviceName })[serviceName]['instances']['status']['data']['status'] or "Stopped"