* ffluci/statistics: include general configuration in stat-genconfig

This commit is contained in:
Jo-Philipp Wich 2008-05-21 04:17:25 +00:00
parent d51e33b8cb
commit f90684f321

View file

@ -27,41 +27,45 @@ local sections, names = uci:sections( "luci_statistics" )
function section( plugin ) function section( plugin )
local config = sections[ "collectd_" .. plugin ] local config = sections[ "collectd_" .. plugin ] or sections["general"]
if type(config) == "table" and config.enable == "1" then if type(config) == "table" and ( plugin == "general" or config.enable == "1" ) then
print( "<Plugin " .. plugin .. ">" ) if plugin ~= "general" then print( "<Plugin " .. plugin .. ">" ) end
if type( plugins[plugin] ) == "function" then if type( plugins[plugin] ) == "function" then
plugins[plugin]( config ) plugins[plugin]( config )
else else
config_generic( config, plugins[plugin][1], plugins[plugin][2], plugins[plugin][3] ) config_generic( config, plugins[plugin][1], plugins[plugin][2], plugins[plugin][3], plugin == "general" )
end end
print( "</Plugin>\n" ) if plugin ~= "general" then
print( "</Plugin>\n" )
else
print( "\n" )
end
end end
end end
function config_generic( c, singles, bools, lists ) function config_generic( c, singles, bools, lists, nopad )
if type(c) == "table" then if type(c) == "table" then
if type(singles) == "table" then if type(singles) == "table" then
for i, key in ipairs( singles ) do for i, key in ipairs( singles ) do
_string( c[key], key ) _string( c[key], key, nopad )
end end
end end
if type(bools) == "table" then if type(bools) == "table" then
for i, key in ipairs( bools ) do for i, key in ipairs( bools ) do
_bool( c[key], key ) _bool( c[key], key, nopad )
end end
end end
if type(lists) == "table" then if type(lists) == "table" then
_list_expand( c, lists ) _list_expand( c, lists, nopad )
end end
end end
@ -141,46 +145,60 @@ function config_network( c )
end end
function _list_expand( c, l ) function _list_expand( c, l, nopad )
for i, n in ipairs(l) do for i, n in ipairs(l) do
if c[n] then if c[n] then
_expand( c[n], n:gsub( "(%w+)s", "%1" ) ) _expand( c[n], n:gsub( "(%w+)s", "%1" ), nopad )
end end
end end
end end
function _expand( s, n ) function _expand( s, n, nopad )
if type(s) == "string" then if type(s) == "string" then
for i, v in ipairs( ffluci.util.split( s, "%s+", nil, true ) ) do for i, v in ipairs( ffluci.util.split( s, "%s+", nil, true ) ) do
_string( v, n ) _string( v, n, nopad )
end end
end end
end end
function _bool( s, n ) function _bool( s, n, nopad )
local pad = ""
if not nopad then pad = "\t" end
if s and s == "1" then if s and s == "1" then
print( "\t" .. n .. " true" ) print( pad .. n .. " true" )
else else
print( "\t" .. n .. " false" ) print( pad .. n .. " false" )
end end
end end
function _string( s, n ) function _string( s, n, nopad )
local pad = ""
if not nopad then pad = "\t" end
if s then if s then
if not s:find("%d") then if not s:find("%d") then
if not s:find("%s") then if not s:find("%s") then
print( "\t" .. n .. " " .. s ) print( pad .. n .. " " .. s )
else else
print( "\t" .. n .. ' "' .. s '"' ) print( pad .. n .. ' "' .. s '"' )
end end
else else
print( "\t" .. n .. " " .. s ) print( pad .. n .. " " .. s )
end end
end end
end end
plugins = { plugins = {
general = {
{ "BaseDir", "Include", "PIDFile", "PluginDir", "TypesDB", "Interval", "ReadThreads" },
{ },
{ }
},
csv = { csv = {
{ "DataDir" }, { "DataDir" },
{ "StoreRates" }, { "StoreRates" },
@ -256,7 +274,10 @@ plugins = {
} }
for plugin in pairs(plugins) do section("general")
section( plugin ) for plugin in pairs(plugins) do
if plugin ~= "general" then
section( plugin )
end
end end