summaryrefslogtreecommitdiffstats
path: root/bgp-model.lua
blob: 07c5b2490ee616c59be5524d433f587166709dd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
module(..., package.seeall)

-- Load libraries
require("modelfunctions")

-- Set variables
local path="PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin "

local configfile = "/etc/quagga/bgpd.conf"
local processname = "bgpd"
local packagename = "quagga"

-- ################################################################################
-- LOCAL FUNCTIONS

local function telnetshowipbgp()
	local output = {}
	local cmd_output_result, cmd_output_error
	local cmd = path .. "echo -e 'zebpasswd\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
		end
		line = f:read("*l")
	end
	return table.concat(output,"\n"),cmd_output_error
end

-- ################################################################################
-- PUBLIC FUNCTIONS

function getstatus()
	return modelfunctions.getstatus(processname, packagename, "BGP Status")
end

function getconfigfile()
	return modelfunctions.getfiledetails(configfile)
end

function setconfigfile(filedetails)
	filedetails.value.filename.value = configfile
	return modelfunctions.setfiledetails(filedetails)
end

function startstop_service(action)
	return modelfunctions.startstop_service(processname, action)
end

function getdetails()
	local status = {}
	status.showipbgp = cfe({ label="BGP routes" })
	status.showipbgp.value,status.showipbgp.errtxt = telnetshowipbgp()
	return cfe({ type="group", value=status, label="BGP Details" })
end