Giter Site home page Giter Site logo

blackw1ng / fritzbox-monitor Goto Github PK

View Code? Open in Web Editor NEW
75.0 5.0 12.0 464 KB

Monitor FritzBox metrics via a telegraf/influxdb/grafana stack that reads data from TR-064

License: MIT License

Python 100.00%
telegraf-exec fritzbox grafana-dashboard python3

fritzbox-monitor's Introduction

MIT license PRs Welcome made-with-python Python application

FritzBox-monitor

Monitor FritzBox metrics via a telegraf/influxdb/grafana stack that reads data from TR-064

What you get....

Grafana dashboard

  • Includes current DSL rates, possible line rates (over time)
  • Traffic on DSL line and LAN port (seems to only register LAN1 in TR-064)
  • Packets per second on WLAN, LAN and DSL
  • Clients associated in WLAN2.4 / WLAN 5 & WLAN guest
  • DECT clients, active VOIP numbers

Details

  • I decided that I want to parse the Fritzbox info via a single telegraf input.
  • Consequently, the checkfritz.py returns a json which can be easily disgested as array

Background

I have a FritzBox 7490 at home, which is connected to a vDSL 100/40 line - I was wondering regarding my traffic patterns, as well as things like connected WiFi clients, DSL line capacity and so on.

My use case

The special thing to mention is:

  • TR-064 is only accessible from the LAN (for good reasons, in terms of security)
  • My monitoring stack of influxDB etc runs on my server in Frankfurt - so the metrics need to get there safely and securely.
  • Another open port on my server, e.g. for InfluxDB etc was not deemed acceptable
  • For security considerations, I prefer a "direct pull" of metrics, e.g. by telegraf
  • So, the actual monitoring collector needs from a decoy host in the LAN, namely my diskstation or one of the raspis
  • I did not want to run an ssh command for every value
  • LAN hosts can be securely / directly accessed by IPv6, and thanks to DNS updates, also carry AAAA entries.

References

I started looking around, and found a good number of projects and descriptions, on how to do it...

All of those needed quite some extra work, or did not fit my use case directly... FritzBoxShell did not completely fetch all the information available, as described by https://avm.de/service/schnittstellen/, and the scripts provided with fritzconnection did need modification as well, the collectd plugin (based on FritzConnection) requires an collectd somewhere in LAN - and an accessible sink.

Installation

Pre-requisites

FritzBox

Diskstation extras

  • Have a Python 3 installation (install Python package) and fritzconnection running (this is quite a task):
    • Install opkg as your package manager, probably best via EasyBootstrapInstaller (see: https://community.synology.com/enu/forum/1/post/127148 )
    • Have "python3-pip" and "python3-lxml" (to tackle the TR-064 SOAP) ready and installed (either installed via opkg, or via pip-bootstrap - have fun getting lxml running on the diskstation without opkg... as the headers are missing)
    • Make sure you have the fritzconnection module: pip install fritzconnections
  • Create a monitoring user via web-ui, have this one be an admin user (otherwise ssh-login does not work)
  • Add your monitoring servers telegraf ssh key to ~monitoring/.ssh/authorized_keys

Monitoring server (in the internet)

  • Have a recent telegraf installation running
  • Have the local output configured, e.g. [[outputs.influxdb]]
  • Have grafana ready, to be able to read from said output
  • Configure telegraf to be able to ssh out with key-auth
    • Create an ssh-key for ~telegraf , probably in /etc/telegraf/.ssh/id_rsa without passphrase, so it can be called from telegraf directly.
    • Check whether telegraf can log in to your diskstation (in the LAN) via keyauth

Actual installation

  • Copy checkfritz.py to your decoy host
    • Adjust credentials
    • Check it is executable & works: Log in to decoy host as the user, and ./checkfritz.py
  • Integrate telegraf-fritzbox.conf into server grafana installation
    • Test the config: telegraf --filter inputs.exec --test
    • Restart grafana, and start collecting data
  • Add grafana-fritzbox-dashboard.json to your server grafana installation

fritzbox-monitor's People

Contributors

blackw1ng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

fritzbox-monitor's Issues

Python Script Failure

Hi,

with the fritzbox 7530 an OS 7,25 i get this error

`Could not query DeviceInfo1 with action GetInfo
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/fritzconnection/fritzconnection.py", line 460, in _get_action
service = self.services[service_name]
KeyError: 'DeviceInfo1:1'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "./checkfritz.py", line 91, in
deviceinfo = readout('DeviceInfo1', 'GetInfo', 'NewSerialNumber')
File "./checkfritz.py", line 27, in readout
answer_dict = fc.call_action(module, action)
File "/usr/local/lib/python3.7/dist-packages/fritzconnection/fritzconnection.py", line 489, in call_action
action = self._get_action(service_name, action_name)
File "/usr/local/lib/python3.7/dist-packages/fritzconnection/fritzconnection.py", line 462, in _get_action
raise ServiceError('Unknown Service: ' + service_name)
fritzconnection.fritzconnection.ServiceError: Unknown Service: DeviceInfo1:1
`

grafana-fritzbox-dashboard.json not working

Hello, I got this set up so far that data is reaching my influxdb instance.

But now that I'm importing the dashboard to Grafana, data is not shown. On import, it sets the datasource to "Grafana" for every panel filling them with random data when it should be using the templating instead.

Could this be related to the Grafana version I'm using (v8.5.5)? I'm so close to the goal. Maybe you can help me out here! :)

Also, it's nicer when on import it allows you to select the datasource. You could include the following to your json file right after the first opening '{':

"__inputs": [
{
"name": "DS_INFLUXDB_TELEGRAF",
"label": "influxdb_telegraf",
"description": "",
"type": "datasource",
"pluginId": "influxdb",
"pluginName": "InfluxDB"
}
],

Then at the bottom of the file replace the datasource with: "datasource": "${DS_INFLUXDB_TELEGRAF}",

For me, it was always using the wrong instance of influxdb as I got two of them set up which is why I added this bit.

Best Regards

Multilanguage interface

@blackw1ng

Could be possible to modify source code to have an external language file to translate strings in the GUI in different language?

Could not query WANDSLInterfaceConfig1 with action GetInfo

Hi,

I setup all the needed components, but when i start the script i get the following output:

Could not query WANDSLInterfaceConfig1 with action GetInfo
Traceback (most recent call last):
  File "checkfritz.py", line 113, in <module>
    info = readout('WANDSLInterfaceConfig1', 'GetInfo')
  File "checkfritz.py", line 27, in readout
    answer_dict = fc.call_action(module, action)
  File "/usr/local/lib/python3.8/dist-packages/fritzconnection/core/fritzconnection.py", line 284, in call_action
    return self.soaper.execute(service, action_name, arguments)
  File "/usr/local/lib/python3.8/dist-packages/fritzconnection/core/soaper.py", line 259, in execute
    return handle_response(response)
  File "/usr/local/lib/python3.8/dist-packages/fritzconnection/core/soaper.py", line 241, in handle_response
    raise_fritzconnection_error(response)
  File "/usr/local/lib/python3.8/dist-packages/fritzconnection/core/soaper.py", line 164, in raise_fritzconnection_error
    raise exception(message)
fritzconnection.core.exceptions.FritzActionError: UPnPError: 
errorCode: 401
errorDescription: Invalid Action

When i do this manuel i get this:

root@inflgraf:/home/telegraf# fritzconnection -i 192.168.232.254 -S WANDSLInterfaceConfig1

fritzconnection v1.9.1
FRITZ!Box 6591 Cable (kdg) at http://192.168.232.254
FRITZ!OS: 7.29


Servicename:        WANDSLInterfaceConfig1
Actionnames:
                    GetInfo
                    GetStatisticsTotal
                    X_AVM-DE_GetDSLDiagnoseInfo
                    X_AVM-DE_GetDSLInfo

So, fritzconnection should work.
And it is a CableBox.
The OS is Ubuntu 20.04 with the latest updates, Python 3.8

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.