From c94678d57e8b0e52587b309b9b129805434044ad Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Wed, 8 Jul 2009 09:50:09 +0000 Subject: List available graphs and display selected graph Still missing functionallity to create the needed table that holds information on how to create the graphics. --- rrdtool-model.lua | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'rrdtool-model.lua') diff --git a/rrdtool-model.lua b/rrdtool-model.lua index fa47e02..e0143ee 100644 --- a/rrdtool-model.lua +++ b/rrdtool-model.lua @@ -191,3 +191,45 @@ If you specify path, it should be " .. tostring(databases) .."/" return configfile end + +function list_graphs() + local graphs = {} + + --TODO: Read config-files and create a table of it. + + return graphs +end + +function view_graph(self, graph_grp, graph_id) + local general_settings = { + filenameextention=".png", + graph_width="800", + } + + local graphs = list_graphs() + local settings = graphs[tostring(graph_grp)]["value"][tonumber(self.clientdata.id)] + local filename = "/"..tostring(graph_grp).."_"..tostring(graph_id) .. + (settings.filenameextention or ".png") + settings.value = tostring(filename) + + --TODO: Loop the defaultsettings and put it in the settings table if there is missing some information + + local cmd = "/usr/bin/rrdtool graph /usr/share/acf/www" .. tostring(filename) .. " " + for k,v in pairs(settings.option) do + if (v) and (#v > 0) then + cmd = cmd .. "--".. format.escapespecialcharacters(k) .. " " .. + format.escapespecialcharacters(v) .. " " + end + end + cmd = cmd .. tostring(settings.variables) + settings.cmd_query = cmd + local f = io.popen( tostring(cmd) .. " 2>&1" ) + settings.cmd_result = f:read("*a") or "" + f:close() + + -- Display the image in it's original size (if possible) + settings.graph = {} + settings.graph.width,settings.graph.height = string.match(settings.cmd_result, "^(%d+)x(%d+)") + + return settings +end -- cgit v1.2.3