luci-app-statistics: convert plugin definitions to JSON
[project/luci.git] / applications / luci-app-statistics / luasrc / controller / luci_statistics / luci_statistics.lua
index eb7769b85fd4ed7ef3c6f400c94efb00664d9186..529cc2335ac9ca1c3e53e0eb6604093de99aae67 100644 (file)
@@ -9,6 +9,7 @@ function index()
        require("nixio.fs")
        require("luci.util")
        require("luci.statistics.datatree")
+       require("luci.jsonc")
 
        -- override entry(): check for existence <plugin>.so where <plugin> is derived from the called path
        function _entry( path, ... )
@@ -22,53 +23,25 @@ function index()
                s_output        = _("Output plugins"),
                s_general       = _("General plugins"),
                s_network       = _("Network plugins"),
-
-               apcups          = _("APC UPS"),
-               conntrack       = _("Conntrack"),
-               contextswitch   = _("Context Switches"),
-               cpu             = _("Processor"),
-               cpufreq         = _("CPU Frequency"),
-               csv             = _("CSV Output"),
-               curl            = _("cUrl"),
-               df              = _("Disk Space Usage"),
-               disk            = _("Disk Usage"),
-               dns             = _("DNS"),
-               email           = _("Email"),
-               entropy         = _("Entropy"),
-               exec            = _("Exec"),
-               interface       = _("Interfaces"),
-               iptables        = _("Firewall"),
-               irq             = _("Interrupts"),
-               iwinfo          = _("Wireless"),
-               load            = _("System Load"),
-               memory          = _("Memory"),
-               netlink         = _("Netlink"),
-               network         = _("Network"),
-               nut             = _("UPS"),
-               olsrd           = _("OLSRd"),
-               openvpn         = _("OpenVPN"),
-               ping            = _("Ping"),
-               processes       = _("Processes"),
-               rrdtool         = _("RRDTool"),
-               sensors         = _("Sensors"),
-               splash_leases   = _("Splash Leases"),
-               tcpconns        = _("TCP Connections"),
-               thermal         = _("Thermal"),
-               unixsock        = _("UnixSock"),
-               uptime          = _("Uptime")
        }
 
        -- our collectd menu
        local collectd_menu = {
-               output  = { "csv", "network", "rrdtool", "unixsock" },
-               general = { "apcups", "contextswitch", "cpu", "cpufreq", "df",
-                       "disk", "email", "entropy", "exec", "irq", "load", "memory",
-                       "nut", "processes", "sensors", "thermal", "uptime" },
-               network = { "conntrack", "curl", "dns", "interface", "iptables",
-                       "netlink", "olsrd", "openvpn", "ping",
-                       "splash_leases", "tcpconns", "iwinfo" }
+               output  = { },
+               general = { },
+               network = { }
        }
 
+       local plugin_dir = "/usr/share/luci/statistics/plugins/"
+       for filename in nixio.fs.dir(plugin_dir) do
+               local plugin_def = luci.jsonc.parse(nixio.fs.readfile(plugin_dir .. filename))
+               if type(plugin_def) == "table" then
+                       local name = filename:gsub("%.json", "")
+                       table.insert(collectd_menu[plugin_def.category], name)
+                       labels[name] = plugin_def.title
+               end
+       end
+
        -- create toplevel menu nodes
        local st = entry({"admin", "statistics"}, template("admin_statistics/index"), _("Statistics"), 80)
        st.index = true