summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bgp-model.lua33
-rw-r--r--zebra-model.lua32
2 files changed, 33 insertions, 32 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
diff --git a/zebra-model.lua b/zebra-model.lua
index 89bfc26..1b9b8b9 100644
--- a/zebra-model.lua
+++ b/zebra-model.lua
@@ -34,26 +34,26 @@ end
local function telnetshowip()
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 route\nquit\n' | nc localhost zebra 2>/dev/null"
local f = io.popen( cmd )
- local line = f:read("*l")
+ local result = f:read("*a") or ""
local validoutput
- while line do
- if (string.find(line, "^Codes")) then
- validoutput = true
- end
- if (string.find(line, "> quit")) then
- validoutput = false
- end
- if (validoutput) then
- table.insert(output,line)
+ 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, "^Codes:")) then
+ startout = #output
+ elseif (string.find(line, "> quit")) then
+ stopout = #output-1
end
- line = f:read("*l")
end
- return table.concat(output,"\n"),cmd_output_error
--- return configfile.password
+ return table.concat(output,"\n",startout,stopout)
end
-- ################################################################################
@@ -79,7 +79,7 @@ end
function getdetails()
local status = {}
status.showip = cfe({ label="Zebra routes" })
- status.showip.value,status.showip.errtxt = telnetshowip()
+ status.showip.value = telnetshowip()
return cfe({ type="group", value=status, label="Zebra Details" })
end