mirror of
https://github.com/ntop/ntopng.git
synced 2026-05-01 00:19:33 +00:00
Initial rework of widget datasources and transformations
This commit is contained in:
parent
a372cd230a
commit
b670ab1d59
4 changed files with 174 additions and 0 deletions
57
scripts/lua/modules/datasources/datasource.lua
Normal file
57
scripts/lua/modules/datasources/datasource.lua
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
--
|
||||
-- (C) 2013-21 - ntop.org
|
||||
--
|
||||
|
||||
local dirs = ntop.getDirs()
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/datasources/?.lua;" .. package.path
|
||||
|
||||
local json = require "dkjson"
|
||||
local rest_utils = require "rest_utils"
|
||||
-- Import the classes library.
|
||||
local classes = require "classes"
|
||||
|
||||
-- ##############################################
|
||||
|
||||
local datasource = classes.class()
|
||||
|
||||
-- ##############################################
|
||||
|
||||
-- @brief Base class constructor
|
||||
function datasource:init()
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
||||
-- @brief Deserializes REST endpoint response into an internal datamodel
|
||||
-- @param rest_response_data Response data as obtained from the REST call
|
||||
function datasource:deserialize(rest_response_data)
|
||||
if rest_response_data and rest_response_data.RESPONSE_CODE == 200 then
|
||||
local data = json.decode(rest_response_data.CONTENT)
|
||||
local when = os.time()
|
||||
|
||||
if data and data.rc == rest_utils.consts.success.ok.rc then
|
||||
self.m = self.meta.datamodel:create(data.rsp.header)
|
||||
|
||||
for _, row in ipairs(data.rsp.rows) do
|
||||
self.m:appendRow(when, data.rsp.header, row)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
||||
-- @brief Transform data according to the specified transformation
|
||||
-- @param data The data to be transformed
|
||||
-- @param transformation The transformation to be applied
|
||||
-- @return transformed data
|
||||
function datasource:transform(transformation)
|
||||
return self.m:getData(transformation)
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
||||
return datasource
|
||||
|
||||
-- ##############################################
|
||||
Loading…
Add table
Add a link
Reference in a new issue