| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #!/usr/bin/lua
- -- event-forwarder ubus RPC plugin
- -- Provides remote control via ubus
- local json = require "cbi.json"
- local ubus = require "ubus"
- local uci = require "luci.model.uci".cursor()
- module("luci.rpcd.event-forwarder", package.seeall)
- function getStatus()
- local conn = ubus.connect()
- local status = {
- running = (tonumber(luci.sys.exec("pgrep -f event-forwarder")) > 0),
- router_id = uci:get("event-forwarder", "router", "id") or "unknown",
- server_url = uci:get("event-forwarder", "server", "url") or "",
- events_sent = 0, -- Could track this in a file
- }
- conn:close()
- return status
- end
- function getEvents(count)
- count = tonumber(count) or 10
- local events = {}
- local f = io.popen("tail -n " .. count .. " /var/log/event-forwarder.log 2>/dev/null")
- if f then
- for line in f:lines() do
- table.insert(events, line)
- end
- f:close()
- end
- return events
- end
- function testConnection()
- local conn = ubus.connect()
- local res = conn:call("network", "getStatus", {})
- conn:close()
- return { success = true, network = res }
- end
- function _init()
- local lp = require "luci.http"
- local cb = require "luci.rpcd".callback
-
- local rv = {
- ["getStatus"] = { cb=getStatus, desc="Get event forwarder status" },
- ["getEvents"] = { cb=getEvents, desc="Get recent events" },
- ["test"] = { cb=testConnection, desc="Test connection" },
- }
-
- return rv
- end
- return _init()
|