configurehood/nodewatcher: Also process hood ID in addition to name

Submitted by Adrian Schmutzler on Nov. 23, 2018, 3:56 p.m.

Details

Message ID 20181123155643.28878-1-freifunk@adrianschmutzler.de
State Accepted
Headers show

Commit Message

Adrian Schmutzler Nov. 23, 2018, 3:56 p.m.
So far, the Monitoring evaluates hoods based on their names.

This introduces several problems, most prominently a hood
re-creation if it is renamed at the KeyXchange.

Since we have unique hood IDs in the KeyXchange and the
Monitoring retrieves those via hoods.php, it is logical use this
information instead of relying on string comparison.

This requires the hood files to contain an additional field "id".
While this has not been implemented, the changes in this patch
will still work and just write empty data to the uci field and
alfred data.

For local hoods, the "id" in the hood file will remain unset.

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
---
 src/packages/fff/fff-hoods/Makefile                         | 2 +-
 src/packages/fff/fff-hoods/files/usr/sbin/configurehood     | 5 ++++-
 src/packages/fff/fff-nodewatcher/Makefile                   | 2 +-
 src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher | 3 ++-
 4 files changed, 8 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/packages/fff/fff-hoods/Makefile b/src/packages/fff/fff-hoods/Makefile
index 5233e611..264d28ab 100644
--- a/src/packages/fff/fff-hoods/Makefile
+++ b/src/packages/fff/fff-hoods/Makefile
@@ -1,7 +1,7 @@ 
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=fff-hoods
-PKG_VERSION:=4
+PKG_VERSION:=5
 PKG_RELEASE:=1
 
 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
index e31ba219..de60c21d 100755
--- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
+++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
@@ -95,6 +95,7 @@  else
 			rm -f "$hoodfilewww" # delete this, so wrong hood file is not broadcasted anymore
 
 			uci -q del "system.@system[0].hood"
+			uci -q del "system.@system[0].hoodid"
 			uci -q commit system
 			reload_config
 		
@@ -125,6 +126,7 @@  if [ -s "$hoodfiletmp" ]; then
 		json_select hood
 
 		json_get_var hood name
+		json_get_var hoodid id
 		[ -n "$mesh_id" ] || json_get_var mesh_id mesh_id
 		[ -n "$mesh_bssid" ] || json_get_var mesh_bssid mesh_bssid
 		[ -n "$mesh_essid" ] || json_get_var mesh_essid mesh_essid
@@ -146,8 +148,9 @@  if [ -s "$hoodfiletmp" ]; then
 			exit 0
 		fi
 
-		echo "Setting hood name: $hood"
+		echo "Setting hood name: $hood (ID $hoodid)"
 		uci -q set "system.@system[0].hood=$hood"
+		uci -q set "system.@system[0].hoodid=$hoodid"
 		uci -q commit system
 		reload_config
 
diff --git a/src/packages/fff/fff-nodewatcher/Makefile b/src/packages/fff/fff-nodewatcher/Makefile
index 927c6293..3c66a0ae 100644
--- a/src/packages/fff/fff-nodewatcher/Makefile
+++ b/src/packages/fff/fff-nodewatcher/Makefile
@@ -1,7 +1,7 @@ 
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=fff-nodewatcher
-PKG_VERSION:=50
+PKG_VERSION:=51
 PKG_RELEASE:=1
 
 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
diff --git a/src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher b/src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher
index 9486fbc8..9d96b07b 100755
--- a/src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher
+++ b/src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher
@@ -12,7 +12,7 @@  if ! lock -n "$lockfile"; then
 fi
 trap "lock -u \"$lockfile\"" INT TERM EXIT
 
-SCRIPT_VERSION="50"
+SCRIPT_VERSION="51"
 
 #Get the configuration from the uci configuration file
 #If it does not exists, then get it from a normal bash file with variables.
@@ -147,6 +147,7 @@  crawl() {
     SYSTEM_DATA=$SYSTEM_DATA"${position_comment}"
     SYSTEM_DATA=$SYSTEM_DATA"${contact}"
     SYSTEM_DATA=$SYSTEM_DATA"<hood>$(uci -q get "system.@system[0].hood")</hood>"
+    SYSTEM_DATA=$SYSTEM_DATA"<hoodid>$(uci -q get "system.@system[0].hoodid")</hoodid>"
     SYSTEM_DATA=$SYSTEM_DATA"<distname>$distname</distname>"
     SYSTEM_DATA=$SYSTEM_DATA"<distversion>$distversion</distversion>"
     SYSTEM_DATA=$SYSTEM_DATA"$cpu"

Comments

Robert Langhammer Nov. 24, 2018, 7:13 p.m.
hallo Adrian,

sieht fuer mich ganz harmlos aus. Und wenn es dem Monitoring hilft, rein
damit.

Reviewd-by: Robert Langhammer <rlanghammer@web.de>

Am 23.11.18 um 16:56 schrieb Adrian Schmutzler:
> So far, the Monitoring evaluates hoods based on their names.
>
> This introduces several problems, most prominently a hood
> re-creation if it is renamed at the KeyXchange.
>
> Since we have unique hood IDs in the KeyXchange and the
> Monitoring retrieves those via hoods.php, it is logical use this
> information instead of relying on string comparison.
>
> This requires the hood files to contain an additional field "id".
> While this has not been implemented, the changes in this patch
> will still work and just write empty data to the uci field and
> alfred data.
>
> For local hoods, the "id" in the hood file will remain unset.
>
> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
> ---
>  src/packages/fff/fff-hoods/Makefile                         | 2 +-
>  src/packages/fff/fff-hoods/files/usr/sbin/configurehood     | 5 ++++-
>  src/packages/fff/fff-nodewatcher/Makefile                   | 2 +-
>  src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher | 3 ++-
>  4 files changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/src/packages/fff/fff-hoods/Makefile b/src/packages/fff/fff-hoods/Makefile
> index 5233e611..264d28ab 100644
> --- a/src/packages/fff/fff-hoods/Makefile
> +++ b/src/packages/fff/fff-hoods/Makefile
> @@ -1,7 +1,7 @@
>  include $(TOPDIR)/rules.mk
>  
>  PKG_NAME:=fff-hoods
> -PKG_VERSION:=4
> +PKG_VERSION:=5
>  PKG_RELEASE:=1
>  
>  PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
> diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> index e31ba219..de60c21d 100755
> --- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> @@ -95,6 +95,7 @@ else
>  			rm -f "$hoodfilewww" # delete this, so wrong hood file is not broadcasted anymore
>  
>  			uci -q del "system.@system[0].hood"
> +			uci -q del "system.@system[0].hoodid"
>  			uci -q commit system
>  			reload_config
>  		
> @@ -125,6 +126,7 @@ if [ -s "$hoodfiletmp" ]; then
>  		json_select hood
>  
>  		json_get_var hood name
> +		json_get_var hoodid id
>  		[ -n "$mesh_id" ] || json_get_var mesh_id mesh_id
>  		[ -n "$mesh_bssid" ] || json_get_var mesh_bssid mesh_bssid
>  		[ -n "$mesh_essid" ] || json_get_var mesh_essid mesh_essid
> @@ -146,8 +148,9 @@ if [ -s "$hoodfiletmp" ]; then
>  			exit 0
>  		fi
>  
> -		echo "Setting hood name: $hood"
> +		echo "Setting hood name: $hood (ID $hoodid)"
>  		uci -q set "system.@system[0].hood=$hood"
> +		uci -q set "system.@system[0].hoodid=$hoodid"
>  		uci -q commit system
>  		reload_config
>  
> diff --git a/src/packages/fff/fff-nodewatcher/Makefile b/src/packages/fff/fff-nodewatcher/Makefile
> index 927c6293..3c66a0ae 100644
> --- a/src/packages/fff/fff-nodewatcher/Makefile
> +++ b/src/packages/fff/fff-nodewatcher/Makefile
> @@ -1,7 +1,7 @@
>  include $(TOPDIR)/rules.mk
>  
>  PKG_NAME:=fff-nodewatcher
> -PKG_VERSION:=50
> +PKG_VERSION:=51
>  PKG_RELEASE:=1
>  
>  PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
> diff --git a/src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher b/src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher
> index 9486fbc8..9d96b07b 100755
> --- a/src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher
> +++ b/src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher
> @@ -12,7 +12,7 @@ if ! lock -n "$lockfile"; then
>  fi
>  trap "lock -u \"$lockfile\"" INT TERM EXIT
>  
> -SCRIPT_VERSION="50"
> +SCRIPT_VERSION="51"
>  
>  #Get the configuration from the uci configuration file
>  #If it does not exists, then get it from a normal bash file with variables.
> @@ -147,6 +147,7 @@ crawl() {
>      SYSTEM_DATA=$SYSTEM_DATA"${position_comment}"
>      SYSTEM_DATA=$SYSTEM_DATA"${contact}"
>      SYSTEM_DATA=$SYSTEM_DATA"<hood>$(uci -q get "system.@system[0].hood")</hood>"
> +    SYSTEM_DATA=$SYSTEM_DATA"<hoodid>$(uci -q get "system.@system[0].hoodid")</hoodid>"
>      SYSTEM_DATA=$SYSTEM_DATA"<distname>$distname</distname>"
>      SYSTEM_DATA=$SYSTEM_DATA"<distversion>$distversion</distversion>"
>      SYSTEM_DATA=$SYSTEM_DATA"$cpu"
Fabian Blaese Nov. 27, 2018, 9:14 a.m.
Hallo Adrian,

das sollte man imho eigentlich generell für alles so machen, nicht nur für den nodewatcher. Aber eins nach dem anderen, dieser Patch gefällt mir soweit.

Später kann man sich ggf. noch folgendes um die Hood-ID erweitern:
- macnocker (würde Kompatibilität brechen..)
- show_info

Reviewed-by: Fabian Bläse <fabian@blaese.de>

Fabian

On 23.11.18 16:56, Adrian Schmutzler wrote:
> So far, the Monitoring evaluates hoods based on their names.
> 
> This introduces several problems, most prominently a hood
> re-creation if it is renamed at the KeyXchange.
> 
> Since we have unique hood IDs in the KeyXchange and the
> Monitoring retrieves those via hoods.php, it is logical use this
> information instead of relying on string comparison.
> 
> This requires the hood files to contain an additional field "id".
> While this has not been implemented, the changes in this patch
> will still work and just write empty data to the uci field and
> alfred data.
> 
> For local hoods, the "id" in the hood file will remain unset.
> 
> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
> ---
>  src/packages/fff/fff-hoods/Makefile                         | 2 +-
>  src/packages/fff/fff-hoods/files/usr/sbin/configurehood     | 5 ++++-
>  src/packages/fff/fff-nodewatcher/Makefile                   | 2 +-
>  src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher | 3 ++-
>  4 files changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/src/packages/fff/fff-hoods/Makefile b/src/packages/fff/fff-hoods/Makefile
> index 5233e611..264d28ab 100644
> --- a/src/packages/fff/fff-hoods/Makefile
> +++ b/src/packages/fff/fff-hoods/Makefile
> @@ -1,7 +1,7 @@
>  include $(TOPDIR)/rules.mk
>  
>  PKG_NAME:=fff-hoods
> -PKG_VERSION:=4
> +PKG_VERSION:=5
>  PKG_RELEASE:=1
>  
>  PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
> diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> index e31ba219..de60c21d 100755
> --- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> @@ -95,6 +95,7 @@ else
>  			rm -f "$hoodfilewww" # delete this, so wrong hood file is not broadcasted anymore
>  
>  			uci -q del "system.@system[0].hood"
> +			uci -q del "system.@system[0].hoodid"
>  			uci -q commit system
>  			reload_config
>  		
> @@ -125,6 +126,7 @@ if [ -s "$hoodfiletmp" ]; then
>  		json_select hood
>  
>  		json_get_var hood name
> +		json_get_var hoodid id
>  		[ -n "$mesh_id" ] || json_get_var mesh_id mesh_id
>  		[ -n "$mesh_bssid" ] || json_get_var mesh_bssid mesh_bssid
>  		[ -n "$mesh_essid" ] || json_get_var mesh_essid mesh_essid
> @@ -146,8 +148,9 @@ if [ -s "$hoodfiletmp" ]; then
>  			exit 0
>  		fi
>  
> -		echo "Setting hood name: $hood"
> +		echo "Setting hood name: $hood (ID $hoodid)"
>  		uci -q set "system.@system[0].hood=$hood"
> +		uci -q set "system.@system[0].hoodid=$hoodid"
>  		uci -q commit system
>  		reload_config
>  
> diff --git a/src/packages/fff/fff-nodewatcher/Makefile b/src/packages/fff/fff-nodewatcher/Makefile
> index 927c6293..3c66a0ae 100644
> --- a/src/packages/fff/fff-nodewatcher/Makefile
> +++ b/src/packages/fff/fff-nodewatcher/Makefile
> @@ -1,7 +1,7 @@
>  include $(TOPDIR)/rules.mk
>  
>  PKG_NAME:=fff-nodewatcher
> -PKG_VERSION:=50
> +PKG_VERSION:=51
>  PKG_RELEASE:=1
>  
>  PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
> diff --git a/src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher b/src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher
> index 9486fbc8..9d96b07b 100755
> --- a/src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher
> +++ b/src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher
> @@ -12,7 +12,7 @@ if ! lock -n "$lockfile"; then
>  fi
>  trap "lock -u \"$lockfile\"" INT TERM EXIT
>  
> -SCRIPT_VERSION="50"
> +SCRIPT_VERSION="51"
>  
>  #Get the configuration from the uci configuration file
>  #If it does not exists, then get it from a normal bash file with variables.
> @@ -147,6 +147,7 @@ crawl() {
>      SYSTEM_DATA=$SYSTEM_DATA"${position_comment}"
>      SYSTEM_DATA=$SYSTEM_DATA"${contact}"
>      SYSTEM_DATA=$SYSTEM_DATA"<hood>$(uci -q get "system.@system[0].hood")</hood>"
> +    SYSTEM_DATA=$SYSTEM_DATA"<hoodid>$(uci -q get "system.@system[0].hoodid")</hoodid>"
>      SYSTEM_DATA=$SYSTEM_DATA"<distname>$distname</distname>"
>      SYSTEM_DATA=$SYSTEM_DATA"<distversion>$distversion</distversion>"
>      SYSTEM_DATA=$SYSTEM_DATA"$cpu"
>
Adrian Schmutzler Nov. 27, 2018, 10:23 p.m.
Applied.

 

From: Fabian Bläse [mailto:fabian@blaese.de] 
Sent: Dienstag, 27. November 2018 10:15
To: Adrian Schmutzler <freifunk@adrianschmutzler.de>; franken-dev@freifunk.net
Subject: Re: [PATCH] configurehood/nodewatcher: Also process hood ID in addition to name

 

Hallo Adrian, 

das sollte man imho eigentlich generell für alles so machen, nicht nur für den nodewatcher. Aber eins nach dem anderen, dieser Patch gefällt mir soweit.

Später kann man sich ggf. noch folgendes um die Hood-ID erweitern: 
- macnocker (würde Kompatibilität brechen..) 
- show_info 

Reviewed-by: Fabian Bläse <fabian@blaese.de <mailto:fabian@blaese.de> > 

Fabian 

On 23.11.18 16:56, Adrian Schmutzler wrote: 
> So far, the Monitoring evaluates hoods based on their names. 
> 
> This introduces several problems, most prominently a hood 
> re-creation if it is renamed at the KeyXchange. 
> 
> Since we have unique hood IDs in the KeyXchange and the 
> Monitoring retrieves those via hoods.php, it is logical use this 
> information instead of relying on string comparison. 
> 
> This requires the hood files to contain an additional field "id". 
> While this has not been implemented, the changes in this patch 
> will still work and just write empty data to the uci field and 
> alfred data. 
> 
> For local hoods, the "id" in the hood file will remain unset. 
> 
> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de <mailto:freifunk@adrianschmutzler.de> > 
> --- 
>  src/packages/fff/fff-hoods/Makefile                         | 2 +- 
>  src/packages/fff/fff-hoods/files/usr/sbin/configurehood     | 5 ++++- 
>  src/packages/fff/fff-nodewatcher/Makefile                   | 2 +- 
>  src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher | 3 ++- 
>  4 files changed, 8 insertions(+), 4 deletions(-) 
> 
> diff --git a/src/packages/fff/fff-hoods/Makefile b/src/packages/fff/fff-hoods/Makefile 
> index 5233e611..264d28ab 100644 
> --- a/src/packages/fff/fff-hoods/Makefile 
> +++ b/src/packages/fff/fff-hoods/Makefile 
> @@ -1,7 +1,7 @@ 
>  include $(TOPDIR)/rules.mk 
>  
>  PKG_NAME:=fff-hoods 
> -PKG_VERSION:=4 
> +PKG_VERSION:=5 
>  PKG_RELEASE:=1 
>  
>  PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) 
> diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood

> index e31ba219..de60c21d 100755 
> --- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood 
> +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood 
> @@ -95,6 +95,7 @@ else 
>                       rm -f "$hoodfilewww" # delete this, so wrong hood file is not broadcasted anymore 
>  
>                       uci -q del "system.@system[0].hood <mailto:system.@system[0].hood> " 
> +                     uci -q del "system.@system[0].hoodid <mailto:system.@system[0].hoodid> " 
>                       uci -q commit system 
>                       reload_config 
>               
> @@ -125,6 +126,7 @@ if [ -s "$hoodfiletmp" ]; then 
>               json_select hood 
>  
>               json_get_var hood name 
> +             json_get_var hoodid id 
>               [ -n "$mesh_id" ] || json_get_var mesh_id mesh_id 
>               [ -n "$mesh_bssid" ] || json_get_var mesh_bssid mesh_bssid 
>               [ -n "$mesh_essid" ] || json_get_var mesh_essid mesh_essid 
> @@ -146,8 +148,9 @@ if [ -s "$hoodfiletmp" ]; then 
>                       exit 0 
>               fi 
>  
> -             echo "Setting hood name: $hood" 
> +             echo "Setting hood name: $hood (ID $hoodid)" 
>               uci -q set "system.@system[0].hood=$hood <mailto:system.@system[0].hood=$hood> " 
> +             uci -q set "system.@system[0].hoodid=$hoodid <mailto:system.@system[0].hoodid=$hoodid> " 
>               uci -q commit system 
>               reload_config 
>  
> diff --git a/src/packages/fff/fff-nodewatcher/Makefile b/src/packages/fff/fff-nodewatcher/Makefile 
> index 927c6293..3c66a0ae 100644 
> --- a/src/packages/fff/fff-nodewatcher/Makefile 
> +++ b/src/packages/fff/fff-nodewatcher/Makefile 
> @@ -1,7 +1,7 @@ 
>  include $(TOPDIR)/rules.mk 
>  
>  PKG_NAME:=fff-nodewatcher 
> -PKG_VERSION:=50 
> +PKG_VERSION:=51 
>  PKG_RELEASE:=1 
>  
>  PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) 
> diff --git a/src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher b/src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher

> index 9486fbc8..9d96b07b 100755 
> --- a/src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher 
> +++ b/src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher 
> @@ -12,7 +12,7 @@ if ! lock -n "$lockfile"; then 
>  fi 
>  trap "lock -u \"$lockfile\"" INT TERM EXIT 
>  
> -SCRIPT_VERSION="50" 
> +SCRIPT_VERSION="51" 
>  
>  #Get the configuration from the uci configuration file 
>  #If it does not exists, then get it from a normal bash file with variables. 
> @@ -147,6 +147,7 @@ crawl() { 
>      SYSTEM_DATA=$SYSTEM_DATA"${position_comment}" 
>      SYSTEM_DATA=$SYSTEM_DATA"${contact}" 
>      SYSTEM_DATA=$SYSTEM_DATA"<hood>$(uci -q get "system.@system[0].hood <mailto:system.@system[0].hood> ")</hood>" 
> +    SYSTEM_DATA=$SYSTEM_DATA"<hoodid>$(uci -q get "system.@system[0].hoodid <mailto:system.@system[0].hoodid> ")</hoodid>" 
>      SYSTEM_DATA=$SYSTEM_DATA"<distname>$distname</distname>" 
>      SYSTEM_DATA=$SYSTEM_DATA"<distversion>$distversion</distversion>" 
>      SYSTEM_DATA=$SYSTEM_DATA"$cpu" 
>