summaryrefslogtreecommitdiffstats
path: root/rrdtool-model.lua
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2009-07-03 09:05:10 +0000
committerMika Havela <mika.havela@gmail.com>2009-07-03 09:05:10 +0000
commitd2a7cb6b8761a7dc83e208ab7094f52e03ebed89 (patch)
tree0888503df63e5824aecafab74c0eddd127d7c185 /rrdtool-model.lua
parent59e7cf26ffd4f20174714736eb6987f0a5af336d (diff)
downloadacf-rrdtool-d2a7cb6b8761a7dc83e208ab7094f52e03ebed89.tar.bz2
acf-rrdtool-d2a7cb6b8761a7dc83e208ab7094f52e03ebed89.tar.xz
Functionallity to create new DB.
Still missing validation on userinput.
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