Coder Social home page Coder Social logo

check_tr64_fritz's Introduction

Note:

This check plugin is no longer actively maintained. For the motives and alternatives please read the following comment: #80

check_tr64_fritz

Table of Contents

  1. Introduction
  2. Support
  3. Requirements
  4. Usage
  5. CheckCommand
  6. Security
  7. Contributors
  8. Thanks
  9. Development

Introduction

This is a check plugin for Icinga 2 to monitor a Fritz!Box.

Support

If you have any questions, please hop onto the community channels.

Requirements

Required packages

The following packages are required to use this check plugin.

  • curl
  • bc

Please use your favorite package manager to install them.

Fritz!Box configuration

The TR-064 feature must be enabled on the Fritz!Box. You can enable the feature in the following menu:

Heimnetz -> Netzwerk, switch over to the tab Netzwerkeinstellungen

The setting Zugriff für Anwendungen zulassen must be activated. After a restart of your Fritz!Box the TR-064 feature is activated.

Note:

You may need to activate the advanced view (Erweiterte Ansicht) to see the setting.

Installation

  1. Get the latest stable release
  2. Extract the archive
  3. Execute the getSecurityPort script, to find your TR-064 SSL port
  4. Copy the check_tr64_fritz script to your Icinga 2 check plugin directory
  5. Add the CheckCommand definition to your Icinga 2 configuration.
  6. Create a new service in Icinga 2 for your Fritz!Box

You can find additional information on how to setup check plugins for Icinga 2 in the offical Icinga 2 documentation

Usage

getSecurityPort

getSecurityPort <HOST>
Name Description
HOST Hostname or IP address of your Fritz!Box.

Example:

$ ./getSecurityPort 192.168.178.1
Your Fritz!Box Security Port (for TR-064 over SSL) is: 49443

check_tr64_fritz

check_tr64_fritz -h <HOSTNAME> -p <PORT> -u <USERNAME> -P <PASSWORD> -f <FUNCTION> -w <WARNING> -c <CRITICAL>

Arguments

Name Description
-h Optional. Hostname or IP address of your Fritz!Box. Defaults to "fritz.box".
-p Optional. The port number for TR-064 over SSL. Defaults to "49443".
-u Optional. Username to authenticate against the Fritz!Box. Defaults to "dslf-config".
-P Required. Password to authenticate against the Fritz!Box.
-f Optional. Function that should be checked. Defaults to "status".
-w Optional. Warning threshold. Defaults to "0".
-c Optional. Critical threshold. Defaults to "0".
-v Optional. Print current plugin version and usage text.
-d Optional. Print debug information (TR-064 XML output).

Note:

The username and password are the same as for the web interface of your Fritz!Box. If you don't use the login method with username and password, you can leave the username empty.

Functions

Name Description
status Optional Index. Returns the connection state. Default Index to "pppoe".
linkuptime Optional Index. Returns the uptime of the WAN link. Default Index to "pppoe".
uptime Returns the device uptime.
downstream Returns the usable downstream rate in MBit/s.
upstream Returns the usable upstream rate in MBit/s.
downstreamrate Returns the current downstream speed in MBit/s.
upstreamrate Returns the current upstream speed in MBits/s.
update Returns the update state.
thermometer Requires Index. Returns the connection status and temperature of a smart home thermometer device.
socketpower Requires Index. Returns the connection status and current power usage in watts of a smart home socket device.
socketenergy Requires Index. Returns the connection status and total consumption over the last year in kWh of a smart home socket device.
socketswitch Requires Index. Returns the connection status and the current switch state. Setting the thresholds to 1 or greater will threat the OFF state as critical.

Indexes

Function Index Description
status cable, pppoe Check the specified connection type.
linkuptime cable, pppoe Check the specified connection type.
thermometer [NUMBER] Check the specified DECT thermometer.
socketpower [NUMBER] Check the specified DECT socket.
socketenergy [NUMBER] Check the specified DECT socket.
socketswitch [NUMBER] Check the specified DECT socket.

Note:

You can specify the index with a double point and the index number after the function name e.g. thermometer:3.

Example:

$ ./check_tr64_fritz -P password -f uptime
OK - Uptime 29990 seconds (0d 8h 19m 50s) | uptime=2999

$ ./check_tr64_fritz -P password -f status:cable
WARNING - Connecting | status=1

$ ./check_tr64_fritz -P password -f thermometer:3
OK - Comet DECT 03.68 - Wohnzimmer CONNECTED 21.5 °C | thermometer_current_state=0 thermometer_current_temp=21.5 warn=0 crit=0

Note:

Please also read the seperate documentation about the Smart Home index

CheckCommand

You can use the following CheckCommand definition for your Icinga 2 configuration.

object CheckCommand "check_tr64_fritz" {
  command = [ PluginDir + "/check_tr64_fritz" ]

  arguments = {
    "-h" = "$fritz_host$"
    "-p" = "$fritz_port$"
    "-u" = "$fritz_username$"
    "-P" = "$fritz_password$"
    "-f" = "$fritz_function$"
    "-w" = "$fritz_warning$"
    "-c" = "$fritz_critical$"
  }

  vars.fritz_host = "$address$"
  vars.fritz_port = "49443"
  vars.fritz_username = "dslf-config"
  vars.fritz_function = "status"
}

You can find more information about a CheckCommand definition inside the offical Icinga 2 documentation.

Security

Authentication

You can use an independently account for the authentication against the Fritz!Box.

  1. Login to your Fritz!Box
  2. Navigate to System -> Fritz!Box-Benutzer

Here you can add a new user to your Fritz!Box. The user needs at least the following permissions to work properly.

  • FRITZ!Box Einstellungen_
  • Sprachnachrichten, Faxnachrichten, FRITZ!App Fon und Anrufliste
  • Smart Home

Script

The check_tr64_script use SSL to communicate with the Fritz!Box. Therefore you need to find out your SSL port for the TR-064 protocol. Please use the script getSecurityPort to find out the port that is used by your Fritz!Box.

Note:

The script getSecurityPort don't use the SSL protocol to communitcate with the Fritz!Box. The information about the used port for TR-064 over SSL is available without authentication against the Fritz!Box.

Icinga Web 2

You must specify your Fritz!Box password inside your Icinga 2 configuration to monitor your Fritz!Box, therefore ensure that you are hiding the custom password attribute in Icinga Web 2.

  1. Log in to Icinga Web 2.
  2. Go to Configuration -> Modules -> monitoring -> Security.
  3. Ensure that your custom password attribute is protected (defaults are *pw*,*pass*,community). If you named your custom variable fritz_password it will be protected by the default entry *pass*.
  4. Check it by going to one of your Fritz!Box service and check if the password is display with ***.

Contributors

Thanks to all contributors!

Thanks

Development

Fork the project to your GitHub account, commit your changes and send a pull request. For developing on this project it is advantageous to have a Fritz!Box at your place to test your changes.

Before we start to fetching and parsing the TR-064 data we need to know which data our Fritz!Box provides. We can either fetch a list of this directly from the Fritz!Box or we can also look into the documentation from the manufacturer AVM. It is good to do both, make sure that the data we want to fetch is supported by AVM and our Fritz!Box actually provides it.

You can fetch the list directly from the Fritz!Box, go to http://<Your Fritz!Box IP Address>:49000/tr64desc.xml to fetch this list. You will get a XML file that contains many entries and it looks like the following.

[...]
<service>
  serviceType>urn:dslforum-org:service:DeviceInfo:1</serviceType>
  serviceId>urn:DeviceInfo-com:serviceId:DeviceInfo1</serviceId>
  controlURL>/upnp/control/deviceinfo</controlURL>
  eventSubURL>/upnp/control/deviceinfo</eventSubURL>
  SCPDURL>/deviceinfoSCPD.xml</SCPDURL>
</service>
[...]
Name Description
serviceType Service category which we want to call
controlURL URL we need to call, when fetching information from the choosen category

You can find the manufacturer documentation here. Have a look into the PDF files and search for a action that provides your needed data.

To finally create our TR-064 request we need three information beforehand.

  1. The serviceType e.g. DeviceInfo
  2. The controlURL e.g. deviceinfo (Only the last part after the slash.)
  3. The action e.g. 'GetInfo' (Look into the manufacturer documentation to find those.)

Inside the devel directory you can find a bash script, that allows you to fetch the raw TR-064 data (basically in XML format).

fetch_tr64_data.sh

This script fetches and output the raw TR-064 data.

Arugments

Name Description
-h Hostname/IP Adress of your Fritz!Box.
-p The port number for TR-064 over SSL.
-u Username.
-P Password.
-U controlURL.
-s serviceType.
-a action.
-x Index.

Example:

./fetch_tr64_data.sh -P [PASSWORD] -U deviceinfo -s DeviceInfo -a GetInfo


fritz.box
49443
dslf-config
[PASSWORD]
deviceinfo
DeviceInfo
GetInfo



<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:GetInfoResponse xmlns:u="urn:dslforum-org:service:DeviceInfo:1">
<NewManufacturerName>AVM</NewManufacturerName>
<NewManufacturerOUI>00040E</NewManufacturerOUI>
<NewModelName>FRITZ!Box 7490</NewModelName>
<NewDescription>FRITZ!Box 7490 113.06.92</NewDescription>
<NewProductClass>FRITZ!Box</NewProductClass>
<NewSerialNumber>[SERIALNO.]</NewSerialNumber>
<NewSoftwareVersion>113.06.92</NewSoftwareVersion>
<NewHardwareVersion>FRITZ!Box 7490</NewHardwareVersion>
<NewSpecVersion>1.0</NewSpecVersion>
<NewProvisioningCode>[CODE]</NewProvisioningCode>
<NewUpTime>97384</NewUpTime>
<NewDeviceLog>
[LOG]
</NewDeviceLog>
</u:GetInfoResponse>
</s:Body>
</s:Envelope>

Now you can see the raw TR-064 and see if your needed information is in there. If yes you can now extend the check plugin script and parsing the output to output the result in a proper format.

check_tr64_fritz's People

Contributors

benschweizer avatar mcktr avatar nbuchwitz avatar slm0n87 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

check_tr64_fritz's Issues

Development documentation

Create documentation for development

  • provide development script to fetch the raw TR-064 data
  • doc: how to use this script
  • doc: how to find information about the FritzBox TR-064 interface

Storing the password

object CheckCommand "check_tr64_fritz" {
  command = [ PluginDir + "/check_tr64_fritz" ]

  arguments = {
    "-h" = "$fritz_host$"
    "-p" = "$fritz_port$"
    "-u" = "$fritz_username$"
    "-P" = "$fritz_password$"
    "-f" = "$fritz_function$"
    "-w" = "$fritz_warning$"
    "-c" = "$fritz_critical$"
  }

  vars.fritz_host = "$address$"
  vars.fritz_port = "49443"
  vars.fritz_username = "dslf-config"
  vars.fritz_function = "status"
}

Where do you store fritz_password?

Enhance README.md

I am not satisfied with the README, before 2.0 a enhancement/improvement is necessary

Add dedicated help parameter

Add a parameter that print out the help/usage page, currently there is no dedicated parameter for it. The help page should also print out the version number.

Since -h is occupied, maybe -v (--version) is a good alternative?

Handle SpecifiedArrayIndexInvalid in Smart Home device functions

If you use an index for a smart home device which doesn't exist, you'll get erroneous output.

$ ./check_tr64_fritz -P <PASSWORD> -f thermometer:7 -d
<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<s:Fault>
<faultcode>s:Client</faultcode>
<faultstring>UPnPError</faultstring>
<detail>
<UPnPError xmlns="urn:dslforum-org:control-1-0">
<errorCode>713</errorCode>
<errorDescription>SpecifiedArrayIndexInvalid</errorDescription>
</UPnPError>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>
(standard_in) 1: syntax error
CRITICAL -   -    °C | thermometer_current_state=2;0;0;0;0

Monitor the battery status of thermometers

This needs some more research, maybe it is not possible (now).

It would be nice to have the current battery status in the thermometer check function and exit with a warning or critical status code if the threshold is to low.

I searched a bit through the AVM documentation and it seems that the value can't be fetched through TR-064.

Allow more than one function at once

I looked at the code and know, that the functions have different endpoint urls, so this change would mean more than one request per script call. But as it is currently handled, the script does not help us at all, we would have to implement 5 different services just to get the information of one of our multiple Fritz!Boxes.

We would like to have at least the status, linkuptime, downstreamrate and upstreamrate bundled as information.

If you say, no way. I'll try to write a wrapper for this.

Missing attribute handling

When calling the script without attributes, it says that the function is unknown. There should be a proper error message.

Example:

./check_tr64_fritz
UNKNOWN - Unknown function

The error message now is just wrong.

Consider to make some attributes mandatory.

Improve error handling

Improve the error handling

Example:
screenshot_20171211_195453

When this happens, we should go on UNKNOWN state instead of CRITICAL state.

This should be part of the next release.

2 questionas about upstreamrate & downstreamrate

hello
would it be possible to have the upstreamrate + downstreamrate as a Unit with negativ and possitive number. like down is negativ and upstream is possitiv.
so with gaphiphte it would Show, if possible, a graph with both Information?

  1. question
    would it be possible to check this upstreamrate + downstreamrate more frequently?

have a nice day
vinc

Some other examples for fetch_tr64_data.sh

Hi,

thanks for your fetch_tr64_data.sh tool and the example ./fetch_tr64_data.sh -P [PASSWORD] -U deviceinfo -s DeviceInfo -a GetInfo ...

I see that not all FRITZ!Box logs will be read, but I'm far away to understand the AVM documentation to create or extend the searches. Could you please give a few more examples maybe with explanation where in the AVM documentation I can find the necessary parameters?

Thanks a lot!
Ulli

Broken status/linkuptime functions on FritzBox cabel models

Hello,

the script always returns UNKNOWN - Could not get a response | status=3 for me.
-d claims I'm using the wrong password, which I can rule out as I'm using the same credentials to log into the webinterface using copy&paste:

./check_tr64_fritz -d -h fritz.box -p 49443 -u redacted -P redacted -f status

<HTML>
  <HEAD>
    <TITLE>401 Unauthorized (ERR_ACCESS_DENIED)</TITLE>
  </HEAD>
  <BODY>
    <H1>401 Unauthorized</H1><BR>ERR_ACCESS_DENIED<HR><B>Webserver</B> Sat, 11 Nov 2017 15:46:31 GMT
  </BODY>
</HTML>

Oddly enough the reponse looks very different when I remove -d:

./check_tr64_fritz -h fritz.box -p 49443 -u redacted -P redacted -f status


<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <s:Body>
    <s:Fault>
      <faultcode>s:Client</faultcode>
      <faultstring>UPnPError</faultstring>
      <detail>
        <UPnPError xmlns="urn:dslforum-org:control-1-0">
          <errorCode>402</errorCode>
          <errorDescription>Invalid Args</errorDescription>
        </UPnPError>
      </detail>
    </s:Fault>
  </s:Body>
</s:Envelope>

Environment:
FritzBox 6360 Cable (Kabel Deutschland)
FRITZ!OS 06.54

Adjust the options and consider reserved one

Consider reserved options.

There are a few reserved options that should not be used for other purposes:

          -V version (--version)
          -h help (--help)
          -t timeout (--timeout)
          -w warning threshold (--warning)
          -c critical threshold (--critical)
          -H hostname (--hostname)
          -v verbose (--verbose)

In addition to the reserved options above, some other standard options are:

          -C SNMP community (--community)
          -a authentication password (--authentication)
          -l login name (--logname)
          -p port or password (--port or --passwd/--password)monitors operational
          -u url or username (--url or --username)

Check FRITZ!Box LogFiles

Hi,

which annoys me for a long time is the fact that's not possible to forward the Events/Logfiles from FRITZ!Box to a syslog/syslog-ng/rsyslog server ...

OK, with Freetz it is/was possible but it's not the way that i like ...

Do you know if it's possible to grab the FRITZ!Box events via tr64 protocol?

Ulli

Debug parameter is not working properly

When setting the -d parameter the script is expecting an argument for it.

Reproduce:

$ ./check_tr64_fritz -P <PASSWORD> -f status -d

./check_tr64_fritz: Diese Option erfordert ein Argument -- d
usage: check_tr64_fritz -h <HOSTNAME> -p <PORT> -u <USERNAME> -P <PASSWORD> -f <FUNCTION> -w <WARNING> -c <CRITICAL>

  -h: IP-Adress or hostname from the Fritz!Box
      default = fritz.box

  -p: SSL-Port from the Fritz!Box
      default = 49443

  -u: Login Username for the Fritz!Box
      default = dslf-config

  -P: Login Password for the Fritz!Box
[....]

Future of this Check Plugin

In the last couple of months there where not many activity on this project from my side. I want to clarify what is going to happen with this project and why there are was so less activity.

First things first I am still interested in to develop a check plugin to monitor a Fritz!Box and (if possible) connected smart devices.

I had a few issues with the implementation in Bash and the check plugin became hard to maintain. Lately I struggled to implement new features into the plugin due to its complexity and over time gained function scope. This plugin was created in my beginnings of writing Bash scripts, therefore some issues are related to my inexperienced myself. Nowadays, with more experience, I would do a few things different.

A quite time ago I decided to go the long way and re-write the whole check plugin in Golang to tackle the issues I had with the implementation in Bash. The result of the re-write can be found here: https://github.com/mcktr/check_fritz.

What happens with the Bash implementation? Since this check plugin works in the current version I'll leave it as it is. I plan to release a last release to tackle a few bugs and to merge outstanding pull requests. But new features will only be implemented in the Golang version.

If you are interested in a actively maintained check plugin to monitor a Fritz!Box I invite you to test the re-write in Golang. I also highly appreciate contribution in any form (test feedback, feature requests, bug reports) for the Golang version, you don't need to be a Golang developer to contribute. :-)

Purpose of the warning and critical levels for Downstream and Upstream checks

Hi,

I don't understand the purpose of the warning and critical levels for Downstream and Upstream checks. If for example I have a DSL line with max. 100Mbit/s DownstreamI get in 110Mbit/s connection rate in the DSL settings of the Fritz!Box.
I would like to check that the DSL connection is at least 100Mbit (warning level) and at least 80Mbit/s (critical level).

In the current version of check_tr64_fritz I get a critical status if I try to set this two levels in this way:

./check_tr64_fritz -h "192.168.187.1" -p "49443" -P "supersecret" -f "downstream" -w 100 -c 80
CRITICAL - Downstream 110 Mbit/s | downstream_rate=110 warn=100 crit=80

I think you should invers the logic for the Downstream and Upstream warning and critical levels to get a warning and critical alarm if the connection rate is lower than connection rate, as I get an OK status today if I set the warning and critical level higher as the expected connection rate:

./check_tr64_fritz -h "192.168.187.1" -p "49443" -P "supersecret" -f "downstream" -w 120 -c 150
OK - Downstream 110 Mbit/s | downstream_rate=110 warn=120 crit=150

Ulli

Downloadrate not correct

Hello,

my downloadrate is 1150 mbit/s on the fritzbox. But the plugin output write only 525 Mbit/s. Can you check it?

<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:X_AVM-DE_GetOnlineMonitorResponse xmlns:u="urn:dslforum-org:service:WANCommonInterfaceConfig:1">
<NewTotalNumberSyncGroups>2</NewTotalNumberSyncGroups>
<NewSyncGroupName>sync_cable</NewSyncGroupName>
<NewSyncGroupMode>CABLE</NewSyncGroupMode>
<Newmax_ds>65632291</Newmax_ds>
<Newmax_us>7188253</Newmax_us>
<Newds_current_bps>2271,5811,1995,2799,3633,5108,6104,7659,8426,6269,1641,3226,7636,1769,1029,392,478,193,523,3998</Newds_current_bps>
<Newmc_current_bps>51,17,68,85,34,103,34,17,68,34,51,34,17,51,34,51,34,0,51,17</Newmc_current_bps>
<Newus_current_bps>2383,32496,5589,12254,18143,805,41492,50183,55369,41257,3159,13231,880,1772,1048,351,483,261,585,1725</Newus_current_bps>
<Newprio_realtime_bps>945,400,473,11,72,39,23,227,683,384,61,521,11,23,618,11,48,26,0,1093</Newprio_realtime_bps>
<Newprio_high_bps>95,191,72,143,0,48,23,48,51,208,140,97,828,844,71,95,0,48,0,223</Newprio_high_bps>
<Newprio_default_bps>1502,32065,5168,12332,18153,825,41380,49954,54934,41157,3090,12677,473,2455,434,350,491,328,593,592</Newprio_default_bps>
<Newprio_low_bps>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Newprio_low_bps>
</u:X_AVM-DE_GetOnlineMonitorResponse>
</s:Body>
</s:Envelope>
OK - Downstream 525 Mbit/s | 'downstream_rate'=525;;;;

image

Investigate the warning behavior of the update check

The update check often returns a warning state but no update is available.

The check returns the following output:

WARNING - Update State: Stopped

I guess the update mechanism on the FritzBox itself only run in a certain interval and between a restart and the first run of the update mechanism the state is stopped. But this needs further investigation.

But imho the warning state is wrong here, unknown would be better.

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.