From 0a3bf70d563015a81e9885bcd24cfa7f43921669 Mon Sep 17 00:00:00 2001
From: Nils Schneider <nils@nilsschneider.net>
Date: Sat, 19 Jul 2014 12:35:32 +0200
Subject: [PATCH] split announce.d into nodeinfo + statistics

---
 package/gluon-alfred/files/lib/gluon/cron/alfred               | 3 ++-
 package/gluon-announce/files/lib/gluon/announce/announce.lua   | 3 ++-
 .../gluon/announce/{announce.d => nodeinfo.d}/hardware/model   | 0
 .../lib/gluon/announce/{announce.d => nodeinfo.d}/hostname     | 0
 .../lib/gluon/announce/{announce.d => nodeinfo.d}/network/mac  | 0
 .../lib/gluon/announce/{announce.d => nodeinfo.d}/node_id      | 0
 .../announce/{announce.d => nodeinfo.d}/software/firmware      | 0
 .../announce/{announce.d/statistics => statistics.d}/idletime  | 0
 .../announce/{announce.d/statistics => statistics.d}/loadavg   | 0
 .../announce/{announce.d/statistics => statistics.d}/memory    | 0
 .../files/lib/gluon/announce/statistics.d/node_id              | 1 +
 .../announce/{announce.d/statistics => statistics.d}/processes | 0
 .../announce/{announce.d/statistics => statistics.d}/uptime    | 0
 .../files/etc/hotplug.d/iface/10-gluon-announced               | 2 +-
 .../network/ath9k_workaround_trigger                           | 0
 .../announce/{announce.d => nodeinfo.d}/software/autoupdater   | 0
 .../announce/{announce.d => nodeinfo.d}/network/addresses      | 0
 .../{announce.d => nodeinfo.d}/network/mesh_interfaces         | 0
 .../announce/{announce.d => nodeinfo.d}/software/batman-adv    | 0
 .../announce/{announce.d/network => statistics.d}/gateway      | 0
 .../announce/{announce.d/statistics => statistics.d}/traffic   | 0
 .../gluon/announce/{announce.d => nodeinfo.d}/software/fastd   | 0
 .../lib/gluon/announce/{announce.d => nodeinfo.d}/location     | 0
 .../files/lib/gluon/announce/{announce.d => nodeinfo.d}/owner  | 0
 24 files changed, 6 insertions(+), 3 deletions(-)
 rename package/gluon-announce/files/lib/gluon/announce/{announce.d => nodeinfo.d}/hardware/model (100%)
 rename package/gluon-announce/files/lib/gluon/announce/{announce.d => nodeinfo.d}/hostname (100%)
 rename package/gluon-announce/files/lib/gluon/announce/{announce.d => nodeinfo.d}/network/mac (100%)
 rename package/gluon-announce/files/lib/gluon/announce/{announce.d => nodeinfo.d}/node_id (100%)
 rename package/gluon-announce/files/lib/gluon/announce/{announce.d => nodeinfo.d}/software/firmware (100%)
 rename package/gluon-announce/files/lib/gluon/announce/{announce.d/statistics => statistics.d}/idletime (100%)
 rename package/gluon-announce/files/lib/gluon/announce/{announce.d/statistics => statistics.d}/loadavg (100%)
 rename package/gluon-announce/files/lib/gluon/announce/{announce.d/statistics => statistics.d}/memory (100%)
 create mode 100644 package/gluon-announce/files/lib/gluon/announce/statistics.d/node_id
 rename package/gluon-announce/files/lib/gluon/announce/{announce.d/statistics => statistics.d}/processes (100%)
 rename package/gluon-announce/files/lib/gluon/announce/{announce.d/statistics => statistics.d}/uptime (100%)
 rename package/gluon-ath9k-workaround/files/lib/gluon/announce/{announce.d => statistics.d}/network/ath9k_workaround_trigger (100%)
 rename package/gluon-autoupdater/files/lib/gluon/announce/{announce.d => nodeinfo.d}/software/autoupdater (100%)
 rename package/gluon-mesh-batman-adv/files/lib/gluon/announce/{announce.d => nodeinfo.d}/network/addresses (100%)
 rename package/gluon-mesh-batman-adv/files/lib/gluon/announce/{announce.d => nodeinfo.d}/network/mesh_interfaces (100%)
 rename package/gluon-mesh-batman-adv/files/lib/gluon/announce/{announce.d => nodeinfo.d}/software/batman-adv (100%)
 rename package/gluon-mesh-batman-adv/files/lib/gluon/announce/{announce.d/network => statistics.d}/gateway (100%)
 rename package/gluon-mesh-batman-adv/files/lib/gluon/announce/{announce.d/statistics => statistics.d}/traffic (100%)
 rename package/gluon-mesh-vpn-fastd/files/lib/gluon/announce/{announce.d => nodeinfo.d}/software/fastd (100%)
 rename package/gluon-node-info/files/lib/gluon/announce/{announce.d => nodeinfo.d}/location (100%)
 rename package/gluon-node-info/files/lib/gluon/announce/{announce.d => nodeinfo.d}/owner (100%)

diff --git a/package/gluon-alfred/files/lib/gluon/cron/alfred b/package/gluon-alfred/files/lib/gluon/cron/alfred
index 2d9316258..72f219a89 100644
--- a/package/gluon-alfred/files/lib/gluon/cron/alfred
+++ b/package/gluon-alfred/files/lib/gluon/cron/alfred
@@ -1 +1,2 @@
-* * * * * /lib/gluon/announce/announce.lua | gzip | alfred -s 158
+* * * * * /lib/gluon/announce/announce.lua nodeinfo | gzip | alfred -s 158
+* * * * * /lib/gluon/announce/announce.lua statistics | gzip | alfred -s 159
diff --git a/package/gluon-announce/files/lib/gluon/announce/announce.lua b/package/gluon-announce/files/lib/gluon/announce/announce.lua
index e51445f79..7bce0a783 100755
--- a/package/gluon-announce/files/lib/gluon/announce/announce.lua
+++ b/package/gluon-announce/files/lib/gluon/announce/announce.lua
@@ -1,6 +1,6 @@
 #!/usr/bin/lua
 
-local announce_dir = '/lib/gluon/announce/announce.d'
+local announce_base = '/lib/gluon/announce/'
 
 
 fs = require 'luci.fs'
@@ -37,6 +37,7 @@ function collect_dir(dir)
 	return ret
 end
 
+local announce_dir  = announce_base .. arg[1] .. '.d/'
 
 encoder = json.Encoder(collect_dir(announce_dir))
 ltn12.pump.all(encoder:source(), ltn12.sink.file(io.stdout))
diff --git a/package/gluon-announce/files/lib/gluon/announce/announce.d/hardware/model b/package/gluon-announce/files/lib/gluon/announce/nodeinfo.d/hardware/model
similarity index 100%
rename from package/gluon-announce/files/lib/gluon/announce/announce.d/hardware/model
rename to package/gluon-announce/files/lib/gluon/announce/nodeinfo.d/hardware/model
diff --git a/package/gluon-announce/files/lib/gluon/announce/announce.d/hostname b/package/gluon-announce/files/lib/gluon/announce/nodeinfo.d/hostname
similarity index 100%
rename from package/gluon-announce/files/lib/gluon/announce/announce.d/hostname
rename to package/gluon-announce/files/lib/gluon/announce/nodeinfo.d/hostname
diff --git a/package/gluon-announce/files/lib/gluon/announce/announce.d/network/mac b/package/gluon-announce/files/lib/gluon/announce/nodeinfo.d/network/mac
similarity index 100%
rename from package/gluon-announce/files/lib/gluon/announce/announce.d/network/mac
rename to package/gluon-announce/files/lib/gluon/announce/nodeinfo.d/network/mac
diff --git a/package/gluon-announce/files/lib/gluon/announce/announce.d/node_id b/package/gluon-announce/files/lib/gluon/announce/nodeinfo.d/node_id
similarity index 100%
rename from package/gluon-announce/files/lib/gluon/announce/announce.d/node_id
rename to package/gluon-announce/files/lib/gluon/announce/nodeinfo.d/node_id
diff --git a/package/gluon-announce/files/lib/gluon/announce/announce.d/software/firmware b/package/gluon-announce/files/lib/gluon/announce/nodeinfo.d/software/firmware
similarity index 100%
rename from package/gluon-announce/files/lib/gluon/announce/announce.d/software/firmware
rename to package/gluon-announce/files/lib/gluon/announce/nodeinfo.d/software/firmware
diff --git a/package/gluon-announce/files/lib/gluon/announce/announce.d/statistics/idletime b/package/gluon-announce/files/lib/gluon/announce/statistics.d/idletime
similarity index 100%
rename from package/gluon-announce/files/lib/gluon/announce/announce.d/statistics/idletime
rename to package/gluon-announce/files/lib/gluon/announce/statistics.d/idletime
diff --git a/package/gluon-announce/files/lib/gluon/announce/announce.d/statistics/loadavg b/package/gluon-announce/files/lib/gluon/announce/statistics.d/loadavg
similarity index 100%
rename from package/gluon-announce/files/lib/gluon/announce/announce.d/statistics/loadavg
rename to package/gluon-announce/files/lib/gluon/announce/statistics.d/loadavg
diff --git a/package/gluon-announce/files/lib/gluon/announce/announce.d/statistics/memory b/package/gluon-announce/files/lib/gluon/announce/statistics.d/memory
similarity index 100%
rename from package/gluon-announce/files/lib/gluon/announce/announce.d/statistics/memory
rename to package/gluon-announce/files/lib/gluon/announce/statistics.d/memory
diff --git a/package/gluon-announce/files/lib/gluon/announce/statistics.d/node_id b/package/gluon-announce/files/lib/gluon/announce/statistics.d/node_id
new file mode 100644
index 000000000..7ff75b2d2
--- /dev/null
+++ b/package/gluon-announce/files/lib/gluon/announce/statistics.d/node_id
@@ -0,0 +1 @@
+return require('gluon.sysconfig').primary_mac:gsub(':', '')
diff --git a/package/gluon-announce/files/lib/gluon/announce/announce.d/statistics/processes b/package/gluon-announce/files/lib/gluon/announce/statistics.d/processes
similarity index 100%
rename from package/gluon-announce/files/lib/gluon/announce/announce.d/statistics/processes
rename to package/gluon-announce/files/lib/gluon/announce/statistics.d/processes
diff --git a/package/gluon-announce/files/lib/gluon/announce/announce.d/statistics/uptime b/package/gluon-announce/files/lib/gluon/announce/statistics.d/uptime
similarity index 100%
rename from package/gluon-announce/files/lib/gluon/announce/announce.d/statistics/uptime
rename to package/gluon-announce/files/lib/gluon/announce/statistics.d/uptime
diff --git a/package/gluon-announced/files/etc/hotplug.d/iface/10-gluon-announced b/package/gluon-announced/files/etc/hotplug.d/iface/10-gluon-announced
index b5546ff03..4fb154f14 100644
--- a/package/gluon-announced/files/etc/hotplug.d/iface/10-gluon-announced
+++ b/package/gluon-announced/files/etc/hotplug.d/iface/10-gluon-announced
@@ -21,7 +21,7 @@ restart_announced () {
 	DEVS=$(cat $DEVLIST | while read dev iface;do echo -n " -i $dev";done)
 
 	service_stop $DAEMON
-	service_start $DAEMON -g ff02:0:0:0:0:0:2:1001 -p 1001 -s /lib/gluon/announce/announce.lua $DEVS
+	service_start $DAEMON -g ff02:0:0:0:0:0:2:1001 -p 1001 -s '/lib/gluon/announce/announce.lua nodeinfo' $DEVS
 }
 
 case "$ACTION" in
diff --git a/package/gluon-ath9k-workaround/files/lib/gluon/announce/announce.d/network/ath9k_workaround_trigger b/package/gluon-ath9k-workaround/files/lib/gluon/announce/statistics.d/network/ath9k_workaround_trigger
similarity index 100%
rename from package/gluon-ath9k-workaround/files/lib/gluon/announce/announce.d/network/ath9k_workaround_trigger
rename to package/gluon-ath9k-workaround/files/lib/gluon/announce/statistics.d/network/ath9k_workaround_trigger
diff --git a/package/gluon-autoupdater/files/lib/gluon/announce/announce.d/software/autoupdater b/package/gluon-autoupdater/files/lib/gluon/announce/nodeinfo.d/software/autoupdater
similarity index 100%
rename from package/gluon-autoupdater/files/lib/gluon/announce/announce.d/software/autoupdater
rename to package/gluon-autoupdater/files/lib/gluon/announce/nodeinfo.d/software/autoupdater
diff --git a/package/gluon-mesh-batman-adv/files/lib/gluon/announce/announce.d/network/addresses b/package/gluon-mesh-batman-adv/files/lib/gluon/announce/nodeinfo.d/network/addresses
similarity index 100%
rename from package/gluon-mesh-batman-adv/files/lib/gluon/announce/announce.d/network/addresses
rename to package/gluon-mesh-batman-adv/files/lib/gluon/announce/nodeinfo.d/network/addresses
diff --git a/package/gluon-mesh-batman-adv/files/lib/gluon/announce/announce.d/network/mesh_interfaces b/package/gluon-mesh-batman-adv/files/lib/gluon/announce/nodeinfo.d/network/mesh_interfaces
similarity index 100%
rename from package/gluon-mesh-batman-adv/files/lib/gluon/announce/announce.d/network/mesh_interfaces
rename to package/gluon-mesh-batman-adv/files/lib/gluon/announce/nodeinfo.d/network/mesh_interfaces
diff --git a/package/gluon-mesh-batman-adv/files/lib/gluon/announce/announce.d/software/batman-adv b/package/gluon-mesh-batman-adv/files/lib/gluon/announce/nodeinfo.d/software/batman-adv
similarity index 100%
rename from package/gluon-mesh-batman-adv/files/lib/gluon/announce/announce.d/software/batman-adv
rename to package/gluon-mesh-batman-adv/files/lib/gluon/announce/nodeinfo.d/software/batman-adv
diff --git a/package/gluon-mesh-batman-adv/files/lib/gluon/announce/announce.d/network/gateway b/package/gluon-mesh-batman-adv/files/lib/gluon/announce/statistics.d/gateway
similarity index 100%
rename from package/gluon-mesh-batman-adv/files/lib/gluon/announce/announce.d/network/gateway
rename to package/gluon-mesh-batman-adv/files/lib/gluon/announce/statistics.d/gateway
diff --git a/package/gluon-mesh-batman-adv/files/lib/gluon/announce/announce.d/statistics/traffic b/package/gluon-mesh-batman-adv/files/lib/gluon/announce/statistics.d/traffic
similarity index 100%
rename from package/gluon-mesh-batman-adv/files/lib/gluon/announce/announce.d/statistics/traffic
rename to package/gluon-mesh-batman-adv/files/lib/gluon/announce/statistics.d/traffic
diff --git a/package/gluon-mesh-vpn-fastd/files/lib/gluon/announce/announce.d/software/fastd b/package/gluon-mesh-vpn-fastd/files/lib/gluon/announce/nodeinfo.d/software/fastd
similarity index 100%
rename from package/gluon-mesh-vpn-fastd/files/lib/gluon/announce/announce.d/software/fastd
rename to package/gluon-mesh-vpn-fastd/files/lib/gluon/announce/nodeinfo.d/software/fastd
diff --git a/package/gluon-node-info/files/lib/gluon/announce/announce.d/location b/package/gluon-node-info/files/lib/gluon/announce/nodeinfo.d/location
similarity index 100%
rename from package/gluon-node-info/files/lib/gluon/announce/announce.d/location
rename to package/gluon-node-info/files/lib/gluon/announce/nodeinfo.d/location
diff --git a/package/gluon-node-info/files/lib/gluon/announce/announce.d/owner b/package/gluon-node-info/files/lib/gluon/announce/nodeinfo.d/owner
similarity index 100%
rename from package/gluon-node-info/files/lib/gluon/announce/announce.d/owner
rename to package/gluon-node-info/files/lib/gluon/announce/nodeinfo.d/owner
-- 
GitLab