Skip to content

Instantly share code, notes, and snippets.

@hydra35
Created January 20, 2012 10:46
Show Gist options
  • Save hydra35/1646664 to your computer and use it in GitHub Desktop.
Save hydra35/1646664 to your computer and use it in GitHub Desktop.
retrieve wireless status from OpenWRT then send to tsdb
function main(cmd)
local f = assert(io.popen(cmd, 'r'))
--local f = assert(io.open('a', 'r'))
local cur_station = ''
local result = {}
for line in f:lines() do
fst_char = string.sub(line, 0, 1)
if fst_char == "S" then
captured = string.match(line, "Station%s(%x%x:%x%x:%x%x:%x%x:%x%x:%x%x)")
if captured then cur_station = captured end
else
key, value = string.match(line, "%s+([%w ]+):%s+([%w.]+)")
if key then
point = string.format("put wireless.%s %s %s mac=%s",
string.gsub(key, "%s", '_'), os.time(), value, cur_station)
print(point)
end
end
end
end
main('iw dev wlan0 station dump')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment