summaryrefslogtreecommitdiffstats
path: root/rrdtool-model.lua
diff options
context:
space:
mode:
Diffstat (limited to 'rrdtool-model.lua')
-rw-r--r--rrdtool-model.lua93
1 files changed, 93 insertions, 0 deletions
diff --git a/rrdtool-model.lua b/rrdtool-model.lua
new file mode 100644
index 0000000..1cc032f
--- /dev/null
+++ b/rrdtool-model.lua
@@ -0,0 +1,93 @@
+module(..., package.seeall)
+
+-- Load libraries
+require("modelfunctions")
+require("posix")
+require("fs")
+require("format")
+
+-- Set variables
+local configfile = "/etc/rrdtool/acf-rrdtool.conf"
+local databases = "/etc/rrdtool/databases"
+local processname = "rrdtool"
+local packagename = "rrdtool"
+local header = "rrdtool"
+local path="PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin "
+
+-- ################################################################################
+-- LOCAL FUNCTIONS
+
+-- Function to recursively insert all filenames in a dir into an array
+local function recursedir(path, filearray)
+ filearray = filearray or {}
+ local k,v
+ for k,v in pairs(posix.dir(path) or {}) do
+ -- Ignore files that begins with a '.'
+ if not string.match(v, "^%.") then
+ local f = path .. "/" .. v
+ -- If subfolder exists, list files in this subfolder
+ if (posix.stat(f).type == "directory") then
+ recursedir(f, filearray)
+ else
+ table.insert(filearray, f)
+ end
+ end
+ end
+ return filearray
+end
+
+local function file_info ( path )
+ local st = fs.stat(path)
+ local size = st.size or "0"
+ local lastmod = st.mtime or "---"
+ return lastmod,size
+end
+
+local function list_files ( ... )
+ local listed_files = {}
+ local open_files = {}
+ local files = {}
+ local k,v
+ -- Generate a single table with all the files
+ for k,v in pairs{...} do
+ recursedir(v, files)
+ end
+
+ -- Loop through each file and present its info
+ for k,v in pairs(files) do
+ -- Get info on this specific file and put it in a table
+ local lastmod,size = file_info(v)
+ local filename = cfe({ value=v, label="File name" })
+ local filesize = cfe({ value=size, label="File size" })
+ local mtime = cfe({ value=lastmod, label="File date" })
+ table.insert ( listed_files , cfe({ type="group", value={filename=filename, filesize=filesize, mtime=mtime, label="File details"} }) )
+ end
+ table.sort(listed_files, function (a,b) return (a.value.filename.value < b.value.filename.value) end )
+ return cfe({ type="list", value=listed_files, label="Log files" })
+
+end
+
+
+
+-- ################################################################################
+-- PUBLIC FUNCTIONS
+
+function startstop_service(action)
+ return modelfunctions.startstop_service(processname, action)
+end
+
+function getstatus()
+ return modelfunctions.getstatus(processname, packagename, header .. " status")
+end
+
+function getconfigfile()
+ return modelfunctions.getfiledetails(configfile)
+end
+
+function setconfigfile(filedetails)
+ return modelfunctions.setfiledetails(filedetails, {configfile})
+end
+
+function getrrdlist()
+ return list_files(databases)
+end