5 Luci statistics - collectd configuration generator
6 (c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
8 Licensed under the Apache License, Version 2.0 (the "License");
9 you may not use this file except in compliance with the License.
10 You may obtain a copy of the License at
12 http://www.apache.org/licenses/LICENSE-2.0
19 require("ffluci.model.uci")
20 require("ffluci.sys.iptparser")
21 require("ffluci.util")
23 local ipt = ffluci.sys.iptparser.IptParser()
24 local uci = ffluci.model.uci.Session()
25 local sections, names = uci:sections( "luci_statistics" )
28 function section( plugin )
30 local config = sections[ "collectd_" .. plugin ]
32 if type(config) == "table" and config.enable == "1" then
34 print( "<Plugin " .. plugin .. ">" )
36 if type( plugins[plugin] ) == "function" then
37 plugins[plugin]( config )
39 config_generic( config, plugins[plugin][1], plugins[plugin][2], plugins[plugin][3] )
42 print( "</Plugin>\n" )
47 function config_generic( c, singles, bools, lists )
49 if type(c) == "table" then
51 if type(singles) == "table" then
52 for i, key in ipairs( singles ) do
54 print( "\t" .. key .. ' "' .. c[key] .. '"' )
59 if type(bools) == "table" then
60 for i, key in ipairs( bools ) do
62 print( "\t" .. key .. " true" )
64 print( "\t" .. key .. " false" )
69 if type(lists) == "table" then
70 _list_expand( c, lists )
77 function config_exec( c )
79 for s in pairs(sections) do
80 for key, type in pairs({ Exec="collectd_exec_input", NotificationExec="collectd_exec_notify" }) do
81 if sections[s][".type"] == type then
83 cmd = sections[s].cmdline
84 user = sections[s].cmduser or "root"
85 group = sections[s].cmdgroup or "root"
87 print( "\t" .. key .. " " .. user .. ":" .. group .. ' "' .. cmd .. '"' )
93 function config_iptables( c )
95 for s in pairs(sections) do
96 if sections[s][".type"] == "collectd_iptables_match" then
100 for i, k in ipairs( {
101 "table", "chain", "target", "protocol", "source", "destination",
102 "inputif", "outputif", "options"
106 if type(v) == "string" then
107 if k == "options" then v = ffluci.util.split( v, "%s+", nil, true ) end
112 for i, rule in ipairs( ipt:find( search ) ) do
114 name = sections[s].name
115 if i > 1 then name = name .. " (" .. i .. ")" end
117 print( "\tChain " .. rule.table .. " " .. rule.chain .. " " .. rule.index .. ' "' .. name .. '"' )
125 function _list_expand( c, l )
126 for i, n in ipairs(l) do
128 _expand( c[n], n:gsub( "(%w+)s", "%1" ) )
133 function _expand( s, n )
135 if type(s) == "string" then
136 for i, v in ipairs( ffluci.util.split( s, "%s+", nil, true ) ) do
137 print( "\t" .. n .. ' "' .. v .. '"' )
153 { "IgnoreSelected" },
154 { "Devices", "MountPoints", "FSTypes" }
159 { "IgnoreSelected" },
166 { "Interfaces", "IgnoreSources" }
170 { "SocketFile", "SocketUser", "SocketPerms", "MaxConns" },
179 { "IgnoreSelected" },
183 iptables = config_iptables,
188 for plugin in pairs(plugins) do