From 36dd1f7ff194ce85b338e4428708860511a0dfef Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Wed, 1 Jun 2011 11:06:57 +0200 Subject: Add notes into the graph image. Save a script next to the DB so the DB can be recreated if needed (might be used in further improvements of this acf) Display example config when creating a new graph. --- rrdtool-editgraphcfg-html.lsp | 38 ++++++++++++++++++++++- rrdtool-model.lua | 70 ++++++++++++++++++++++++++++++++----------- rrdtool-viewgraph-popup.lsp | 1 - 3 files changed, 90 insertions(+), 19 deletions(-) mode change 120000 => 100644 rrdtool-editgraphcfg-html.lsp diff --git a/rrdtool-editgraphcfg-html.lsp b/rrdtool-editgraphcfg-html.lsp deleted file mode 120000 index 15b1930..0000000 --- a/rrdtool-editgraphcfg-html.lsp +++ /dev/null @@ -1 +0,0 @@ -../filedetails-html.lsp \ No newline at end of file diff --git a/rrdtool-editgraphcfg-html.lsp b/rrdtool-editgraphcfg-html.lsp new file mode 100644 index 0000000..6b5a2f3 --- /dev/null +++ b/rrdtool-editgraphcfg-html.lsp @@ -0,0 +1,37 @@ +<% local form, viewlibrary, page_info = ... %> +<% require("viewfunctions") %> + +<% if form.type == "form" then %> +

Configuration

+

Expert Configuration

+<% else %> +

View File

+<% end %> +

File Details

+
+<% +displayitem(form.value.filename) +displayitem(form.value.filesize) +displayitem(form.value.mtime) +%> +
+ +

File Content

+<% if form.type == "form" then %> +<% form.action = page_info.script .. page_info.prefix .. page_info.controller .. "/" .. page_info.action %> +<% displayformstart(form) %> + +<% else %> +
+<% end %> + +<% if form.value.filecontent.errtxt then %>

<%= string.gsub(html.html_escape(form.value.filecontent.errtxt), "\n", "
") %>

<% end %> +<% if form.value.filecontent.descr then %>

<%= string.gsub(html.html_escape(form.value.filecontent.descr), "\n", "
") %>

<% end %> + +<% if form.type == "form" then %> +<% displayformend(form) %> +<% else %> +
+<% end %> diff --git a/rrdtool-model.lua b/rrdtool-model.lua index 3feb6ba..d43875c 100644 --- a/rrdtool-model.lua +++ b/rrdtool-model.lua @@ -12,6 +12,7 @@ require("validator") local configfile = "/etc/rrdtool/acf-rrdtool.conf" local graphpath = "/etc/rrdtool" local databases = "/etc/rrdtool/databases" +local db_scripts = "/etc/rrdtool/databases" local processname = "rrdtool" local packagename = "rrdtool" local header = "rrdtool" @@ -80,7 +81,7 @@ function setconfigfile(filedetails) end function getrrdlist() - return list_files(databases) + return list_files(databases,".*rrd") end function createnewrrd() @@ -125,6 +126,9 @@ function savenewrrd(self, configfile, userid) path=tostring(databases).."/"..configfile.value.filename.value configfile.errtxt = "Failed to create file" local path = configfile.value.filename.value + if not fs.is_dir(databases) then + fs.create_directory(databases) + end if not string.find(path, "/") then path = databases .. "/" .. path elseif not validator.is_valid_filename(path,databases) then @@ -155,12 +159,26 @@ If you specify path, it should be " .. tostring(databases) .."/" else step = "" end - local f = io.popen( "/usr/bin/rrdtool create ".. - format.escapespecialcharacters(path) .. " " .. - format.escapespecialcharacters(start) .. - format.escapespecialcharacters(step) .. - tostring(string.gsub(format.dostounix(format.escapespecialcharacters(configfile.value.ds.value)),"\n", " \\\n")) .. " " .. - tostring(string.gsub(format.dostounix(format.escapespecialcharacters(configfile.value.rra.value)),"\n", " \\\n")) .. " 2>&1") + + local cmd = "/usr/bin/rrdtool create ".. format.escapespecialcharacters(path) .. " " .. format.escapespecialcharacters(start) .. format.escapespecialcharacters(step) .. tostring(string.gsub(format.dostounix(format.escapespecialcharacters(configfile.value.ds.value)),"\n", " \\\n")) .. " " .. tostring(string.gsub(format.dostounix(format.escapespecialcharacters(configfile.value.rra.value)),"\n", " \\\n")) + + local f = io.popen("date") + local createdate = f:read("*l") or "" + f:close() + local cmd_descr = "#!/bin/sh\n# " .. tostring(createdate) .. "\n# This file can be used to recreate '" .. tostring(path) .. "'\n\n" .. string.gsub(string.gsub(cmd," RRA", " \\\nRRA")," DS", " \\\nDS") + + local filedetails={} + filedetails.value={} + filedetails.value.filename={value=tostring(db_scripts) .. "/" .. string.match(path,".*/(.*)") .. ".cmd"} + filedetails.value.filecontent={value=string.gsub(cmd_descr,"\\/","/")} + + if not fs.is_dir(tostring(db_scripts)) then + fs.create_directory(tostring(db_scripts)) + end + filedetails = modelfunctions.setfiledetails(filedetails, getgraphlist) + filedetails = nil + + local f = io.popen( cmd .. " 2>&1") success = f:read("*a") or "" f:close() configfile.errtxt = tostring(success) @@ -175,14 +193,24 @@ function list_graphs() for k,v in pairs(files) do local filecontent = {} + local cont=false for kk,vv in pairs(fs.read_file_as_array(v)) do - vv = string.gsub(vv,"\"", "") + vv = string.gsub(vv,"\n", "") local delim = string.find(vv, "\=") - if delim then - filecontent[string.sub(vv,1,(delim-1))]=string.sub(vv,(delim+1),#vv) - end + if cont==true then + filecontent['value']=tostring(filecontent['value']) .. " " .. tostring(vv) + filecontent['plutt']="test" + else + if delim then + filecontent[string.sub(vv,1,(delim-1))]=string.sub(vv,(delim+1),#vv) + --TODO: Remove trailing slash \ for each line + end + end + if delim and string.sub(vv,1,(delim-1))=="value" then + cont=true + end end - + if not (filecontent.group) then filecontent.group = "General" end @@ -210,7 +238,11 @@ function view_graph(self, graph_grp, graph_id) local cmd = "/usr/bin/rrdtool graph /usr/share/acf/www" .. tostring(filename) .. " " - cmd = cmd .. tostring(settings.value) + local f = io.popen("date") + local imagedate = f:read("*l") or "" + f:close() + + cmd = cmd .. tostring(settings.value) .. " --title '" .. tostring(settings.label) .. " - " .. tostring(settings.descr) .. "' -W '" .. tostring(imagedate) .. "'" settings.cmd_query = cmd local f = io.popen( tostring(cmd) .. " 2>&1" ) settings.cmd_result = f:read("*a") or "" @@ -234,10 +266,14 @@ function getgraphfile(path) local filedetails = modelfunctions.getfiledetails(path) -- If we create a new file, we want to help the user to know what variables he should use if not (path) then - filedetails.value.filecontent.value = [[label=Example name for this graph -group=General -descr=Some describing text that helps the user to know what this graph is all about -value=--start now-3600s --end now --width 680 --height 400 --step 300 DEF... + filedetails.value.filecontent.value = [[group=General +label=Example graph +descr=Testgraph to show network activity +value=--start now-3600s --end now --width 680 --height 500 --step 60 --vertical-label 'bit' +DEF:eth0rx=]] .. tostring(databases) .. [[/mydb.rrd:eth0rx:AVERAGE +DEF:eth0tx=]] .. tostring(databases) .. [[/mydb.rrd:eth0tx:AVERAGE +LINE2:eth0rx#006600: +AREA:eth0tx#99000099: ]] end local output = {value={filename=filedetails.value.filename, diff --git a/rrdtool-viewgraph-popup.lsp b/rrdtool-viewgraph-popup.lsp index 80b55c0..42194a5 100644 --- a/rrdtool-viewgraph-popup.lsp +++ b/rrdtool-viewgraph-popup.lsp @@ -3,7 +3,6 @@ require("viewfunctions") %> <% if (data.graph.width) then %> -

<%= data.descr %>

<% else %>

No valid output available!

-- cgit v1.2.3