Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Many changes #39

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,30 @@ This script has been tested upon Python 2.7, 3.2 & 3.5. See [below](#graphs) for
3. Launch authorization script

```bash
./main.py authorize
./freebox_ authorize
```

4. Update permissions on authorization file

```bash
chmod 0660 freebox.json
sudo chgrp munin freebox.json
mkdir /var/lib/munin-node/plugin-state/nobody/Freebox-OS-munin
cp freebox.json /var/lib/munin-node/plugin-state/nobody/Freebox-OS-munin/
cp Freebox ECC Root CA.pem /var/lib/munin-node/plugin-state/nobody/Freebox-OS-munin/
cp Freebox Root CA.pem /var/lib/munin-node/plugin-state/nobody/Freebox-OS-munin/
```

5. Install the plugins

> Tip: you don't have to symlink each mode. Skip some if you don't need all information

```bash
./create_symlinks.py
sudo ln -sf $(pwd)/freebox-* /etc/munin/plugins
cp freebox_ /usr/share/munin/plugins/
mkdir /usr/local/lib/python3.7/dist-packages/munin/
cp *.py /usr/local/lib/python3.7/dist-packages/munin/
munin-node-configure --shell | grep -i freebox
copy and execute all symlinks generated
```

6. Restart munin node service
Expand All @@ -48,14 +55,14 @@ This script has been tested upon Python 2.7, 3.2 & 3.5. See [below](#graphs) for
7. Test it

```
sudo munin-run freebox-traffic
sudo munin-run freebox_traffic
```

## Contribute
Fork this repository, and submit pull requests upon master branch.

> Tip: when making changes that affects all plugins, you can tests them all
by running `./main.py --mode all`. This will execute each plugin in both config
by running `./freebox_ --mode all`. This will execute each plugin in both config
& poll modes.

## Graphs
Expand Down
11 changes: 0 additions & 11 deletions create_symlinks.py

This file was deleted.

2 changes: 1 addition & 1 deletion db.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fields import *
from munin.fields import *

db_net = 'net'
db_temp = 'temp'
Expand Down
12 changes: 9 additions & 3 deletions fields.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from modes import *
from munin.modes import *

# mode_traffic
field_rate_down = 'rate_down'
Expand All @@ -11,9 +11,12 @@
field_cpub = 'cpub'
field_sw = 'sw'
field_hdd = 'hdd'
field_temp_hdd = 'temp_hdd'
field_temp_cpu = 'temp_cpu'
field_temp_t = 'temp_t'

# mode_fan_speed
field_fan_speed = 'fan_speed'
field_fan_speed = 'fan'

# mode_xdsl
field_snr_down = 'snr_down'
Expand Down Expand Up @@ -100,7 +103,10 @@
field_cpum,
field_cpub,
field_sw,
field_hdd
field_hdd,
field_temp_hdd,
field_temp_cpu,
field_temp_t
],
mode_fan_speed: [
field_fan_speed
Expand Down
23 changes: 18 additions & 5 deletions freebox.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
import requests
import socket

from util import *
from munin.util import *

freebox_config_file = os.path.join(os.path.dirname(__file__), 'freebox.json')
app_id = 'freebox-revolution-munin' # Script legacy name. Changing this would break authentication
app_name = 'Freebox-OS-munin'
# debian's systemd limitation : https://github.com/munin-monitoring/munin/issues/1236
# ProtectSystem=full
write_dir = '/var/lib/munin-node/plugin-state/nobody/'
freebox_config_file = write_dir + app_name + '/freebox.json'
app_id = 'freebox-revolution-munin' # Script legacy name. Changing this would break authentication
app_version = '1.0.0'
device_name = socket.gethostname()

Expand All @@ -22,8 +25,18 @@ class Freebox:
session_challenge = None
session_token = None

def api_get_info(self):
uri = self.protocol + '://mafreebox.freebox.fr/api_version'
r = requests.get(uri, verify=self.root_ca)
r_json = r.json()
return r_json

def get_api_call_uri(self, endpoint):
return self.protocol + '://mafreebox.freebox.fr/api/v3/' + endpoint
r_json = self.api_get_info()
api_base_url = r_json['api_base_url']
api_version = r_json['api_version']
major_api_version = re.search(r'\d+', api_version).group()
return self.protocol + '://mafreebox.freebox.fr' + api_base_url + 'v' + major_api_version + '/' + endpoint

def save(self):
with open(freebox_config_file, 'w') as fh:
Expand All @@ -38,7 +51,7 @@ def retrieve(self):

if 'root_ca' in self.__dict__:
# compute the full filename
self.root_ca = os.path.join(os.path.dirname(__file__), self.root_ca)
self.root_ca = self.root_ca
else:
# backward compatibility with old config file
self.root_ca = ''
Expand Down
Loading