diff options
Diffstat (limited to 'rrdtool-model.lua')
-rw-r--r-- | rrdtool-model.lua | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/rrdtool-model.lua b/rrdtool-model.lua index 7b3895a..8f97738 100644 --- a/rrdtool-model.lua +++ b/rrdtool-model.lua @@ -1,4 +1,4 @@ -module(..., package.seeall) +local mymodule = {} -- Load libraries modelfunctions = require("modelfunctions") @@ -65,23 +65,23 @@ end -- ################################################################################ -- PUBLIC FUNCTIONS -function getstatus() +function mymodule.getstatus() return modelfunctions.getstatus(nil, packagename, header .. " status") end -function getconfigfile() +function mymodule.getconfigfile() return modelfunctions.getfiledetails(configfile) end -function setconfigfile(self, filedetails) +function mymodule.setconfigfile(self, filedetails) return modelfunctions.setfiledetails(self, filedetails, {configfile}) end -function getrrdlist() +function mymodule.getrrdlist() return list_files(databases,".*rrd") end -function createnewrrd() +function mymodule.createnewrrd() local newdb = {} newdb.filename = cfe({label="Name",value="mydb.rrd",descr="The name of the RRD you want to create. RRD files should end with the extension .rrd. However, RRDtool will accept any filename."}) newdb.start = cfe({label="Start",value="",descr="Specifies the time in seconds since 1970-01-01 UTC when the first value should be added to the RRD. RRDtool will not accept any data timed before or at the time specified.\ @@ -95,7 +95,7 @@ DS:ds-name:COMPUTE:rpn-expression",type="longtext"}) return {value=newdb} end -function remove_file(self, path, userid) +function mymodule.remove_file(self, path, userid) local success = "Failed to delete file" local errtxt if not (fs.is_file(path)) then @@ -109,7 +109,7 @@ function remove_file(self, path, userid) return cfe({ value=success, label="Delete config file result", errtxt=errtxt }) end -function rrd_info(self, path, userid) +function mymodule.rrd_info(self, path, userid) local success, errtxt if (validfilename(path)) then success, errtxt = modelfunctions.run_executable({"rrdtool", "info", path}, true) @@ -119,7 +119,7 @@ function rrd_info(self, path, userid) return cfe({ value=success, label="rrdtool info ".. tostring(path) , errtxt=errtxt }) end -function savenewrrd(self, configfile, userid) +function mymodule.savenewrrd(self, configfile, userid) path=tostring(databases).."/"..configfile.value.filename.value configfile.errtxt = "Failed to create file" local path = configfile.value.filename.value @@ -170,7 +170,7 @@ If you specify path, it should be " .. tostring(databases) .."/" if not fs.is_dir(tostring(db_scripts)) then fs.create_directory(tostring(db_scripts)) end - filedetails = modelfunctions.setfiledetails(self, filedetails, getgraphlist) + filedetails = modelfunctions.setfiledetails(self, filedetails, mymodule.getgraphlist) filedetails = nil local f = io.popen( cmd .. " 2>&1") @@ -182,7 +182,7 @@ If you specify path, it should be " .. tostring(databases) .."/" return configfile end -function list_graphs() +function mymodule.list_graphs() local graphs = {} local files = fs.find_files_as_array(".*graph", graphpath) @@ -217,13 +217,13 @@ function list_graphs() return graphs end -function view_graph(self, graph_grp, graph_id) +function mymodule.view_graph(self, graph_grp, graph_id) local general_settings = { filenameextention=".png", graph_width="800", } - local graphs = list_graphs() + local graphs = mymodule.list_graphs() local settings = graphs[tostring(graph_grp)][tonumber(self.clientdata.id)] local filename = "/".. string.lower(tostring(graph_grp)).."_"..tostring(graph_id) .. (settings.filenameextention or ".png") @@ -248,11 +248,11 @@ function view_graph(self, graph_grp, graph_id) return settings end -function getgraphlist() +function mymodule.getgraphlist() return list_files(graphpath,".*graph") end -function getgraphfile(path) +function mymodule.getgraphfile(path) if (path) and not (validfilename(path)) then path = nil end @@ -278,7 +278,7 @@ AREA:eth0tx#99000099: return output end -function set_filedetails (self, filedetails, userid) +function mymodule.set_filedetails (self, filedetails, userid) if filedetails.value.filename.value and (#filedetails.value.filename.value > 0) and not (string.match(filedetails.value.filename.value, ".*/$")) then if not (string.match(filedetails.value.filename.value, "^" .. graphpath)) then filedetails.value.filename.value = graphpath .. "/" .. string.gsub(filedetails.value.filename.value,"^.*/", "") @@ -287,7 +287,7 @@ function set_filedetails (self, filedetails, userid) filedetails.value.filename.value = filedetails.value.filename.value .. ".graph" end - filedetails = modelfunctions.setfiledetails(self, filedetails, getgraphlist) + filedetails = modelfunctions.setfiledetails(self, filedetails, mymodule.getgraphlist) else filedetails.errtxt = "Failed to set file" filedetails.value.filename.errtxt = "You need to specify a valid filename!" @@ -297,6 +297,8 @@ function set_filedetails (self, filedetails, userid) return filedetails end -function setgraphfile(self, filedetails, file) +function mymodule.setgraphfile(self, filedetails, file) return modelfunctions.setfiledetails(self, filedetails, {file}) end + +return mymodule |