From 27ea9ea8ebc20d6deb40c0ae7562a10ae3007709 Mon Sep 17 00:00:00 2001 From: Bob van de Vijver Date: Wed, 6 Sep 2017 21:57:40 +0200 Subject: [PATCH] Fixes #14. Added localization for english --- README.md | 18 +++++++++++++++--- fritzbox_uptime.py | 15 +++++++++++---- fritzbox_wifi_devices.py | 5 ++++- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 98e4337..ce488d3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # fritzbox-munin -A collection of munin plugins to monitor your AVM FRITZ!Box router. The scripts have been developed using a [FRITZ!Box 7362 SL](http://geni.us/fTyoY)(Amazon link) running FRITZ!OS 06.83. This script also only works if the language of the Fritz!Box is set to German (this holds only for the uptime and wifi devices check). +A collection of munin plugins to monitor your AVM FRITZ!Box router. The scripts have been developed using a [FRITZ!Box 7362 SL](http://geni.us/fTyoY)(Amazon link) running FRITZ!OS 06.83. If you are using the scripts on a different Fritz!Box model please let me know by @@ -54,12 +54,12 @@ If you are using the scripts on a different Fritz!Box model please let me know b ## fritzbox\_uptime - fritzbox\_uptime shows you the uptime in days (requires password) + fritzbox\_uptime shows you the uptime in days (requires password) (language dependant, see below). ![http://i.imgur.com/Jr8OibH.png](http://i.imgur.com/Jr8OibH.png) ## fritzbox\_wifi\_devices - fritzbox\_wifi\_devices shows you the number of connected wifi clients (requires password) + fritzbox\_wifi\_devices shows you the number of connected wifi clients (requires password) (language dependant, see below). ![http://i.imgur.com/lqvK1b2.png](http://i.imgur.com/lqvK1b2.png) @@ -83,6 +83,18 @@ If you are using the scripts on a different Fritz!Box model please let me know b 5. Done. You should now start to see the charts on the Munin pages. +## Localization + +Two scripts depend on the language selected in your fritzbox: the uptime and wifi\_devices. Currently, two locales are +supported: + +1. German: `de` (default) +2. English: `en` + +You can change the used locale by setting an environment variable in your plugin configuration: + + env.locale en + ## Environment Settings Do not forget to restart the munin-node daemon as described in step 3 of the installation instructions above. diff --git a/fritzbox_uptime.py b/fritzbox_uptime.py index d6e2878..7d2c149 100755 --- a/fritzbox_uptime.py +++ b/fritzbox_uptime.py @@ -21,8 +21,15 @@ import re import sys import fritzbox_helper as fh +locale = os.environ.get('locale', 'de') +patternLoc = {"de":"(\d+)\s(Tag|Stunden|Minuten)", \ + "en":"(\d+)\s(days|hours|minutes)"} +dayLoc = {"de":"Tag", "en":"days"} +hourLoc = {"de":"Stunden", "en":"hours"} +minutesLoc = {"de":"Minuten", "en":"minutes"} + PAGE = '/system/energy.lua' -pattern = re.compile("(\d+)\s(Tag|Stunden|Minuten)") +pattern = re.compile(patternLoc[locale]) def get_uptime(): @@ -37,11 +44,11 @@ def get_uptime(): if matches: hours = 0.0 for m in matches: - if m.group(2) == 'Tag': + if m.group(2) == dayLoc[locale]: hours += 24 * int(m.group(1)) - if m.group(2) == "Stunden": + if m.group(2) == hourLoc[locale]: hours += int(m.group(1)) - if m.group(2) == "Minuten": + if m.group(2) == minutesLoc[locale]: hours += int(m.group(1)) / 60.0 uptime = hours / 24 print "uptime.value %.2f" % uptime diff --git a/fritzbox_wifi_devices.py b/fritzbox_wifi_devices.py index 8d9fded..ad143fc 100755 --- a/fritzbox_wifi_devices.py +++ b/fritzbox_wifi_devices.py @@ -21,8 +21,11 @@ import re import sys import fritzbox_helper as fh +locale = os.environ.get('locale', 'de') +patternLoc = {"de":"(\d+) WLAN", "en":"(\d+) wireless LAN"} + PAGE = '/system/energy.lua' -pattern = re.compile("(\d+) WLAN") +pattern = re.compile(patternLoc[locale]) def get_connected_wifi_devices():