Skip to content

Commit

Permalink
some minor refactorings and content updates
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Massmann <[email protected]>
  • Loading branch information
ma4nn committed Sep 29, 2023
1 parent 4032300 commit 943e735
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

- Bob van de Vijver ([bobvandevijver](https://github.com/bobvandevijver))
- Framps ([framps](https://github.com/framps))
- Christian Stade-Schuldt
- Christian Stade-Schuldt ([Tafkas](https://github.com/Tafkas))
- Oliver Edelmann
- Rene Walendy ([RenWal](https://github.com/RenWal))
- Christoph Massmann ([ma4nn](https://github.com/ma4nn))
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ Multigraph plugin, showing for 2.4GHz and 5GHz

## Installation & Configuration

1. Pre-requisites for the `fritzbox_traffic` and `fritzbox_connection_uptime` plugins are the [fritzconnection](https://pypi.python.org/pypi/fritzconnection) and [requests](https://pypi.python.org/pypi/requests) package. To install run
1. To install requirements run

pip install -r requirements.txt

1. Make sure the FRITZ!Box has UPnP status information enabled. (web interface: _Home Network > Network > Network Settings > Universal Plug & Play (UPnP)_)

1. Copy all the scripts from `src/` folder to `/usr/share/munin/plugins`
1. Copy all the scripts from the [published release](https://github.com/ma4nn/fritzbox-munin-fast/releases) to `/usr/share/munin/plugins`

1. (optional) If you want to connect to FRITZ!Box using SSL, download the Fritz certificate (web interface: _Internet > Freigaben > FritzBox Dienste > Zertifikat > Zertifikat herunterladen_) and save it to `/etc/munin/box.cer`.

Expand All @@ -98,9 +98,9 @@ Multigraph plugin, showing for 2.4GHz and 5GHz

See the plugin files for plugin-specific configuration options.

1. For each plugin you want to activate, create a symbolic link to `/etc/munin/plugins`, e.g.:
1. For each plugin you want to activate, create a symbolic link to `/etc/munin/plugins` and make it executable, e.g.:
```
ln -s fritzbox_dsl.py /etc/munin/plugins/fritzbox_dsl.py
ln -s fritzbox_dsl.py /etc/munin/plugins/fritzbox_dsl.py && chmod +x /etc/munin/plugins/fritzbox_dsl.py
```

1. Restart the munin-node daemon: `service munin-node restart`.
Expand Down Expand Up @@ -138,14 +138,16 @@ You can split the graphs of your FRITZ!Box from the localhost graphs by followin

## Testing

To test a plugin use
### Manual Testing

To manually test a plugin use
```
munin-run --debug fritzbox_connection_uptime.py
```

## Unit Tests
### Unit Tests

Run all unit tests with
```
pytest
pytest --cov
```
18 changes: 8 additions & 10 deletions src/fritzbox_energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import os
import re
import sys
from fritzbox_interface import FritzboxInterface
from fritzbox_munin_plugin_interface import MuninPluginInterface,main_handler

Expand All @@ -43,8 +42,7 @@

# date-from-text extractor foo
locale = os.getenv('locale', 'de')
patternLoc = {"de": "(\d+)\s(Tag|Stunden|Minuten)",
"en": "(\d+)\s(days|hours|minutes)"}
patternLoc = {"de": r"(\d+)\s(Tag|Stunden|Minuten)", "en": r"(\d+)\s(days|hours|minutes)"}
dayLoc = {"de": "Tag", "en": "days"}
hourLoc = {"de": "Stunden", "en": "hours"}
minutesLoc = {"de": "Minuten", "en": "minutes"}
Expand All @@ -56,28 +54,29 @@ def get_modes():
def get_type():
return os.getenv('energy_product')


class FritzboxEnergy(MuninPluginInterface):
__connection = None

def __init__(self, fritzbox_interface: FritzboxInterface):
self.__connection = fritzbox_interface

def __get_devices_for(self, type):
if type == "DSL":
def __get_devices_for(self, device_type):
if device_type == "DSL":
return DEVICES
if type == "repeater":
if device_type == "repeater":
return DEVICES_REPEATER

raise Exception("No such type")

def print_stats(self):
"""print the current energy statistics"""

modes = get_modes()
type = get_type()

# download the graphs
jsondata = self.__connection.post_page_with_login(PAGE, data=PARAMS)['data']['drain']
devices = self.__get_devices_for(type)
devices = self.__get_devices_for(get_type())

if 'power' in modes:
print("multigraph power")
Expand Down Expand Up @@ -121,8 +120,7 @@ def print_stats(self):

def print_config(self):
modes = get_modes()
type = get_type()
devices = self.__get_devices_for(type)
devices = self.__get_devices_for(get_type())

if 'power' in modes:
print("multigraph power")
Expand Down
2 changes: 1 addition & 1 deletion src/fritzbox_munin_plugin_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ def main_handler(plugin: MuninPluginInterface):
try:
plugin.print_stats()
except Exception as e:
sys.exit(f"Couldn't retrieve fritzbox stats of {os.path.basename(sys.argv[0])}/{type(plugin).__name__}: {str(e)}")
sys.exit(f"Couldn't retrieve Fritzbox stats of {os.path.basename(sys.argv[0])}/{type(plugin).__name__}: {str(e)}")

0 comments on commit 943e735

Please sign in to comment.