Summary
A table whose contents are persisted between plugin executions.
Syntax
Datastore[key] = valuelocal value = Datastore[key]
Parameters
key : key with which the specified value is associated. Can be of type boolean, number, string or table.
value : value associated with the specified key. Can be of type boolean, number, string or table.
Description
The Datastore table is a special Lua table (or associative array) that is persisted between plugin executions.
As opposed to the local variables of a plugin, the Datastore keys and values are maintained from one plugin execution to the next one.
The Datastore table allows using constructs like counters, history or data aggregation that involve the executions of the plugin over time.
Note that there is a Datastore table for every monitor of type plugin, e.g. the Datastore belongs to the monitor that calls the plugin, not to the plugin itself.
Cycles in the table are not allowed and when detected cause a runtime error on the plugin.
Examples
-- Check monitor only every 5 executions. Return previous value between checks.
function plugin(options)
-- get execution counter
local executionNumber = Datastore["execution"] or 0
local success, responseText, responseCode
if executionNumber == 0 then
-- do the checking
success, responseText, responseCode = executeMonitor("http://www.wikipedia.org#method=head")
else
-- return previous result
success, responseText, responseCode = Monitor.getLastResult()
end
-- increment execution counter
Datastore["execution"] = (executionNumber + 1) % 5
return success, responseText, responseCode
end