New sysinfo json changes (#405)

* sysinfo.json additions
lua library additions

Dependent on #389 and #391
Replaces #387

* additional check for nil needed
tested on a node with several very marginal RF links (IP, no host name) and it is working, so far.
also removed the decimal point on the n/lq values, we didn't need 10 places of accuracy. :)

* a couple more small changes

* changed neighborLinkInfo() function in aredn.info to show *all* links, not just RF.
Adds additional info for each RF link (tx/rx_rate, noise, signal)

* Removed redundant function.
Removed functions no longer needed.
Reworked getCurrentNeighbor function to add in the additional RF link info if requested.
This commit is contained in:
Eric 2019-04-29 20:43:37 -07:00 committed by dman776
parent 94816c45c7
commit 0300874d99
4 changed files with 179 additions and 97 deletions

View File

@ -37,10 +37,12 @@
require("uci")
local aredn_uci = require("aredn.uci")
require("aredn.utils")
local olsr=require("aredn.olsr")
-- require("aredn.http")
local lip=require("luci.ip")
require("nixio")
require("ubus")
require("iwinfo")
-------------------------------------
-- Public API is attached to table
@ -171,10 +173,114 @@ function model.getBand(radio)
end
-------------------------------------
-- TODO: Return Frequency
-- Return Frequency
-------------------------------------
function model.getFrequency(radio)
return ""
function model.getFreq()
local wlanInf=get_ifname('wifi')
local freq=""
freq=os.capture("iwinfo " .. wlanInf .. " info | egrep 'Mode:'")
freq=freq:gsub("^%s*(.-)%s*$", "%1")
freq=string.match(freq, "%((.-)%)")
return freq
end
-------------------------------------
-- Return locally hosted services (for sysinfo.json)
-------------------------------------
function model.local_services()
local filelines={}
local lclsrvs={}
local lclsrvfile=io.open("/etc/config/services", "r")
if lclsrvfile~=nil then
for line in lclsrvfile:lines() do
table.insert(filelines, line)
end
lclsrvfile:close()
for pos,val in pairs(filelines) do
local service={}
local link,protocol,name = string.match(val,"^([^|]*)|(.+)|([^\t]*).*")
if link and protocol and name then
service['name']=name
service['protocol']=protocol
service['link']=link
table.insert(lclsrvs, service)
end
end
else
service['error']="Cannot read local services file"
table.insert(lclsrvs, service)
end
return lclsrvs
end
-------------------------------------
-- Return *All* Network Services
-------------------------------------
function model.all_services()
local services={}
local lines={}
local pos, val
local hfile=io.open("/var/run/services_olsr","r")
if hfile~=nil then
for line in hfile:lines() do
table.insert(lines,line)
end
hfile:close()
for pos,val in pairs(lines) do
local service={}
local link,protocol,name = string.match(val,"^([^|]*)|(.+)|([^\t]*)\t#.*")
if link and protocol and name then
service['link']=link
service['protocol']=protocol
service['name']=name
table.insert(services,service)
end
end
else
service['error']="Cannot read services file"
table.insert(services,service)
end
return services
end
-------------------------------------
-- Return *All* Hosts
-------------------------------------
function model.all_hosts()
local hosts={}
local lines={}
local pos, val
local hfile=io.open("/var/run/hosts_olsr","r")
if hfile~=nil then
for line in hfile:lines() do
table.insert(lines,line)
end
hfile:close()
for pos,val in pairs(lines) do
local host={}
-- local data,comment = string.match(val,"^([^#;]+)[#;]*(.*)$")
local data,comment = string.match(val,"^([^#;]+)[#;]*(.*)$")
if data then
--local ip, name=string.match(data,"^%s*([%x%.%:]+)%s+(%S.*)\t%s*$")
local ip, name=string.match(data,"^([%x%.%:]+)%s+(%S.*)\t%s*$")
if ip and name then
if not string.match(name,"^(dtdlink[.]).*") then
if not string.match(name,"^(mid[0-9][.]).*") then
host['name']=name
host['ip']=ip
table.insert(hosts,host)
end
end
end
end
end
else
host['error']="Cannot read hosts file"
table.insert(hosts,host)
end
return hosts
end
-------------------------------------

View File

@ -57,7 +57,8 @@ function model.getOLSRInterfaceType(iface)
return it
end
function model.getCurrentNeighbors()
function model.getCurrentNeighbors(RFinfo)
local RFinfo = RFinfo or false
local info={}
local links=model.getOLSRLinks()
for k,v in pairs(links) do
@ -69,13 +70,41 @@ function model.getCurrentNeighbors()
info[remip]['linkType']= model.getOLSRInterfaceType(v['olsrInterface']) -- RF or DTD or TUN
info[remip]['linkQuality']=v['linkQuality']
info[remip]['neighborLinkQuality']=v['neighborLinkQuality']
host = string.gsub(remhost,"dtdlink%.", "")
host = string.gsub(host,"mid%d.", "")
info[remip]['hostname']=host
if remhost ~= nil then
host = string.gsub(remhost,"dtdlink%.", "")
end
if host ~= nil then
host = string.gsub(host,"mid%d.", "")
info[remip]['hostname']=host
else
info[remip]['hostname']=remip
end
-- services
-- info[remip]['services']={}
-- get TxMBPS
-- info[remip]['rate']="0"
if info[remip]['linkType'] == "RF" and RFinfo then
-- get additional info for RF link
require("aredn.utils")
require("iwinfo")
local wlan=get_ifname('wifi')
local RFneighbors=iwinfo['nl80211'].assoclist(wlan)
local mac2node=mac2host()
for i, mac_host in pairs(mac2node) do
local mac=string.match(mac_host, "^(.-)\-")
mac=mac:upper()
local node=string.match(mac_host, "\-(.*)")
if host == node or remip == node then
for stn in pairs(RFneighbors) do
stnInfo=iwinfo['nl80211'].assoclist(wlan)[mac]
if stnInfo ~= nil then
info[remip]["signal"]=tonumber(stnInfo.signal)
info[remip]["noise"]=tonumber(stnInfo.noise)
info[remip]["tx_rate"]=adjust_rate(stnInfo.tx_rate/1000,bandwidth)
info[remip]["rx_rate"]=adjust_rate(stnInfo.rx_rate/1000,bandwidth)
end
end
end
end
end
end
return info
end

View File

@ -198,13 +198,12 @@ function nslookup(ip)
rip = o4.."."..o3.."."..o2.."."..o1
nso = capture("nslookup "..ip)
hostname = nso:match(rip.."%.in%-addr%.arpa[%s]+name[%s]+=[%s]+(.*)")
hostname=hostname:chomp()
hostname=hostname:chomp()
if hostname=="" then
hostname=nil
if hostname ~= nil then
hostname=hostname:chomp()
hostname=hostname:chomp()
return hostname
end
end
return hostname
end
function file_trim(filename, maxl)
@ -285,6 +284,19 @@ function capture(cmd)
return(result)
end
-- Return list of MAC to Hostname files
function mac2host(dir)
dir = dir or "/tmp/snrlog"
local i, list, popen = 0, {}, io.popen
local pfile = popen("ls -A " .. dir)
for filename in pfile:lines() do
i = i + 1
list[i] = filename
end
pfile:close()
return list
end
--[[
LuCI - System library

View File

@ -37,6 +37,7 @@
require("uci")
require("aredn.utils")
local aredn_info = require("aredn.info")
local aredn_olsr = require("aredn.olsr")
require("aredn.http")
require("nixio")
local ipc = require("luci.ip")
@ -45,7 +46,6 @@ local json = require ("luci.jsonc")
-- Function extensions
os.capture = capture
-- ==== MAIN =====
ctx = uci.cursor()
if not ctx then
@ -55,7 +55,7 @@ end
info={}
-- API version
info['api_version']="1.6"
info['api_version']="1.7"
-- NODE name
@ -84,11 +84,13 @@ info['node_details']['firmware_version']=aredn_info.getFirmwareVersion()
-- Mesh RF info
info['meshrf']={}
local radio=aredn_info.getMeshRadioDevice()
if ( radio ~= nill and radio ~= "" ) then
info['meshrf']['status']="on"
info['meshrf']['ssid']=aredn_info.getSSID()
info['meshrf']['channel']=aredn_info.getChannel(radio)
info['meshrf']['chanbw']=aredn_info.getChannelBW(radio)
info['meshrf']['freq']=aredn_info.getFreq()
else
info['meshrf']['status']="off"
end
@ -147,95 +149,28 @@ info['interfaces']=tif
-- HOSTS
if string.find(nixio.getenv("QUERY_STRING"):lower(),"hosts=1") then
local hosts={}
local lines={}
local pos, val
local hfile=io.open("/var/run/hosts_olsr","r")
if hfile~=nil then
for line in hfile:lines() do
table.insert(lines,line)
end
hfile:close()
for pos,val in pairs(lines) do
local host={}
-- local data,comment = string.match(val,"^([^#;]+)[#;]*(.*)$")
local data,comment = string.match(val,"^([^#;]+)[#;]*(.*)$")
if data then
--local ip, name=string.match(data,"^%s*([%x%.%:]+)%s+(%S.*)\t%s*$")
local ip, name=string.match(data,"^([%x%.%:]+)%s+(%S.*)\t%s*$")
if ip and name then
if not string.match(name,"^(dtdlink[.]).*") then
if not string.match(name,"^(mid[0-9][.]).*") then
host['name']=name
host['ip']=ip
table.insert(hosts,host)
end
end
end
end
end
else
host['error']="Cannot read hosts file"
table.insert(hosts,host)
end
info['hosts']=hosts
info['hosts']=aredn_info.all_hosts()
end
-- SERVICES
if string.find(nixio.getenv("QUERY_STRING"):lower(),"services=1") then
local services={}
local lines={}
local pos, val
local hfile=io.open("/var/run/services_olsr","r")
if hfile~=nil then
for line in hfile:lines() do
table.insert(lines,line)
end
hfile:close()
for pos,val in pairs(lines) do
local service={}
local link,protocol,name = string.match(val,"^([^|]*)|(.+)|([^\t]*)\t#.*")
if link and protocol and name then
service['link']=link
service['protocol']=protocol
service['name']=name
table.insert(services,service)
end
end
else
service['error']="Cannot read services file"
table.insert(services,service)
end
info['services']=services
info['services']=aredn_info.all_services()
end
-- LOCALLY HOSTED SERVICES ONLY
if string.find(nixio.getenv("QUERY_STRING"):lower(),"services_local=1") then
local filelines={}
local lclsrvs={}
local lclsrvfile=io.open("/etc/config/services", "r")
if lclsrvfile~=nil then
for line in lclsrvfile:lines() do
table.insert(filelines, line)
end
lclsrvfile:close()
for pos,val in pairs(filelines) do
local service={}
local link,protocol,name = string.match(val,"^([^|]*)|(.+)|([^\t]*).*")
if link and protocol and name then
service['name']=name
service['protocol']=protocol
service['link']=link
table.insert(lclsrvs, service)
end
end
else
service['error']="Cannot read local services file"
table.insert(lclsrvs, service)
end
info['services_local']=lclsrvs
info['services_local']=aredn_info.local_services()
end
-- LOCAL NEIGHBORS LINK INFO
if string.find(nixio.getenv("QUERY_STRING"):lower(),"link_info=1") then
info['link_info']=aredn_olsr.getCurrentNeighbors(true)
end
-- MESHMAP INFO
if string.find(nixio.getenv("QUERY_STRING"):lower(),"meshmap=1") then
info['services_local']=aredn_info.local_services()
info['link_info']=aredn_olsr.getCurrentNeighbors(true)
end
-- Output the HTTP header for JSON