luci-app-statistics: check that uci config sections exist
[project/luci.git] / applications / luci-app-statistics / luasrc / statistics / datatree.lua
index 850b83a..5176a19 100644 (file)
@@ -1,17 +1,5 @@
---[[
-
-Luci statistics - rrd data tree builder
-(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-               http://www.apache.org/licenses/LICENSE-2.0
-
-$Id$
-
-]]--
+-- Copyright 2008 Freifunk Leipzig / Jo-Philipp Wich <jow@openwrt.org>
+-- Licensed to the public under the Apache License 2.0.
 
 module("luci.statistics.datatree", package.seeall)
 
 
 module("luci.statistics.datatree", package.seeall)
 
@@ -25,9 +13,17 @@ local sections = uci:get_all("luci_statistics")
 Instance = util.class()
 
 function Instance.__init__( self, host )
 Instance = util.class()
 
 function Instance.__init__( self, host )
-       self._host    = host or sections.collectd.Hostname or sys.hostname()
-       self._libdir  = sections.collectd.PluginDir        or "/usr/lib/collectd"
-       self._rrddir  = sections.collectd_rrdtool.DataDir  or "/tmp/rrd"
+       self._host    = host or sys.hostname()
+       self._libdir  = "/usr/lib/collectd"
+       self._rrddir  = "/tmp/rrd"
+
+       if sections and sections.collectd then
+               self._host    = host or sections.collectd.Hostname or sys.hostname()
+               self._libdir  = sections.collectd.PluginDir        or "/usr/lib/collectd"
+       end
+       if sections and sections.collectd_rrdtool then
+               self._rrddir  = sections.collectd_rrdtool.DataDir  or "/tmp/rrd"
+       end
 
        self._libdir  = self._libdir:gsub("/$","")
        self._rrddir  = self._rrddir:gsub("/$","")
 
        self._libdir  = self._libdir:gsub("/$","")
        self._rrddir  = self._rrddir:gsub("/$","")