summaryrefslogtreecommitdiffstats
path: root/rrdtool-model.lua
diff options
context:
space:
mode:
Diffstat (limited to 'rrdtool-model.lua')
-rw-r--r--rrdtool-model.lua42
1 files changed, 42 insertions, 0 deletions
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