summaryrefslogtreecommitdiffstats
path: root/rrdtool-model.lua
diff options
context:
space:
mode:
Diffstat (limited to 'rrdtool-model.lua')
-rw-r--r--rrdtool-model.lua37
1 files changed, 36 insertions, 1 deletions
diff --git a/rrdtool-model.lua b/rrdtool-model.lua
index dfa4475..2163ec0 100644
--- a/rrdtool-model.lua
+++ b/rrdtool-model.lua
@@ -104,7 +104,7 @@ end
function createnewrrd()
local newdb = {}
- newdb.name = 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.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.\
(Your system saids that your current time is '" .. tostring(os.time(os.date("*t"))) .. "' in the format you should specify above. The startvalue should be smaller than your current time.)\
(Default: now - 10s)"})
@@ -139,3 +139,38 @@ function rrd_info(self, path, userid)
end
return cfe({ value=success, label="rrdtool info ".. tostring(path) , errtxt=errtxt })
end
+
+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 string.find(path, "/") then
+ path = databases .. "/" .. path
+ end
+ if (posix.stat(path)) then
+ configfile.value.filename.errtxt = "File already exists"
+ else
+ local start,step
+ if (#configfile.value.start.value > 0) then
+ start = "--start " .. tostring(configfile.value.start.value) .. " "
+ else
+ start = ""
+ end
+ if (#configfile.value.step.value > 0) then
+ step = "--step " .. tostring(configfile.value.step.value) .. " "
+ else
+ step = ""
+ end
+ local f = io.popen( "/usr/bin/rrdtool create "..
+ tostring(path) .. " " ..
+ tostring(start) ..
+ tostring(step) ..
+ tostring(configfile.value.ds.value) .. " " ..
+ tostring(configfile.value.rra.value) .. " 2>&1")
+ success = f:read("*a") or ""
+ f:close()
+ configfile.errtxt = tostring(success)
+ end
+
+ return configfile
+end