summaryrefslogtreecommitdiffstats
path: root/bgp-model.lua
diff options
context:
space:
mode:
Diffstat (limited to 'bgp-model.lua')
-rw-r--r--bgp-model.lua33
1 files changed, 17 insertions, 16 deletions
diff --git a/bgp-model.lua b/bgp-model.lua
index 1166837..1afe0e9 100644
--- a/bgp-model.lua
+++ b/bgp-model.lua
@@ -34,25 +34,26 @@ end
local function telnetshowipbgp()
local output = {}
- local configfile = parseconfigfile()
- local cmd_output_result, cmd_output_error
+ local configfile = parseconfigfile() or {}
local cmd = path .. "echo -e '" .. (configfile.password or "") .. "\nshow ip bgp\nquit\n' | nc localhost bgpd 2>/dev/null"
local f = io.popen( cmd )
- local line = f:read("*l")
- local validoutput
- while line do
- if (string.find(line, "^BGP")) then
- validoutput = true
- end
- if (validoutput) then
- table.insert(output,line)
- end
- if (line) and (string.find(line, "^Total number")) then
- validoutput = false
+ local result = f:read("*a") or ""
+ f:close()
+ if result == "" then
+ result = "Failed to find routes"
+ end
+ local startout, stopout
+ for line in string.gmatch(result, "([^\n]*)\n?") do
+ table.insert(output,line)
+ if (string.find(line, "^Password:")) then
+ startout = #output+1
+ elseif (string.find(line, "^BGP")) then
+ startout = #output
+ elseif (string.find(line, "^Total number")) then
+ stopout = #output
end
- line = f:read("*l")
end
- return table.concat(output,"\n"),cmd_output_error
+ return table.concat(output,"\n",startout,stopout)
end
-- ################################################################################
@@ -78,7 +79,7 @@ end
function getdetails()
local status = {}
status.showipbgp = cfe({ label="BGP routes" })
- status.showipbgp.value,status.showipbgp.errtxt = telnetshowipbgp()
+ status.showipbgp.value = telnetshowipbgp()
return cfe({ type="group", value=status, label="BGP Details" })
end