diff --git a/config_example.toml b/config_example.toml index 6b9175d..8f19ba4 100644 --- a/config_example.toml +++ b/config_example.toml @@ -13,8 +13,9 @@ webroot = "webroot" [nodes] enable = true nodes_version = 2 -nodes_path = "/var/www/html/meshviewer/data/nodes_all.json" +nodes_path = "/var/www/html/meshviewer/data/nodes.json" graph_path = "/var/www/html/meshviewer/data/graph.json" +state_path = "/var/lib/collector/state.json" # Export nodes and graph periodically save_interval = "5s" diff --git a/models/config.go b/models/config.go index bb63396..e2d4295 100644 --- a/models/config.go +++ b/models/config.go @@ -19,13 +19,13 @@ type Config struct { Webroot string } Nodes struct { - Enable bool - NodesVersion int - NodesPath string - NodesDynamicPath string - GraphPath string - SaveInterval Duration // Save nodes periodically - PruneAfter Duration // Remove nodes after n days of inactivity + Enable bool + NodesVersion int + NodesPath string + GraphPath string + StatePath string + SaveInterval Duration // Save nodes periodically + PruneAfter Duration // Remove nodes after n days of inactivity } Influxdb struct { Enable bool diff --git a/models/config_test.go b/models/config_test.go index 630b93b..ac0fa73 100644 --- a/models/config_test.go +++ b/models/config_test.go @@ -18,6 +18,6 @@ func TestReadConfig(t *testing.T) { assert.Equal(time.Minute, config.Respondd.CollectInterval.Duration) assert.Equal(2, config.Nodes.NodesVersion) - assert.Equal("/var/www/html/meshviewer/data/nodes_all.json", config.Nodes.NodesPath) + assert.Equal("/var/www/html/meshviewer/data/nodes.json", config.Nodes.NodesPath) assert.Equal(time.Hour*24*7, config.Nodes.PruneAfter.Duration) } diff --git a/models/nodes.go b/models/nodes.go index 2b24fde..3190132 100644 --- a/models/nodes.go +++ b/models/nodes.go @@ -28,7 +28,7 @@ func NewNodes(config *Config) *Nodes { config: config, } - if config.Nodes.NodesDynamicPath != "" { + if config.Nodes.StatePath != "" { nodes.load() } /** @@ -178,7 +178,7 @@ func (nodes *Nodes) expire() { } func (nodes *Nodes) load() { - path := nodes.config.Nodes.NodesDynamicPath + path := nodes.config.Nodes.StatePath if f, err := os.Open(path); err == nil { // transform data to legacy meshviewer if err = json.NewDecoder(f).Decode(nodes); err == nil { @@ -197,7 +197,7 @@ func (nodes *Nodes) save() { defer nodes.RUnlock() // serialize nodes - save(nodes, nodes.config.Nodes.NodesDynamicPath) + save(nodes, nodes.config.Nodes.StatePath) if path := nodes.config.Nodes.NodesPath; path != "" { version := nodes.config.Nodes.NodesVersion diff --git a/models/nodes_test.go b/models/nodes_test.go index 64f31b2..aa84adb 100644 --- a/models/nodes_test.go +++ b/models/nodes_test.go @@ -47,7 +47,7 @@ func TestLoadAndSave(t *testing.T) { assert := assert.New(t) config := &Config{} - config.Nodes.NodesDynamicPath = "testdata/nodes.json" + config.Nodes.StatePath = "testdata/nodes.json" nodes := NewNodes(config) nodes.load()