Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a424725
Showing
1 changed file
with
385 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,385 @@ | ||
#!/bin/bash | ||
: << =cut | ||
=head1 NAME | ||
Freebox munin plugin to monitor the freebox v6 server (Revolution) from the french ISP free. | ||
=head1 DESCRIPTION | ||
This plugin monitors various aspects of the freebox server : | ||
* The connexion status | ||
* the uptime | ||
* the temperature of the chips | ||
* the fan rotationnal speed | ||
* the ATM synchronization bandwidth | ||
* the SNR margin | ||
* the line attenuation | ||
This plugin uses the following tools : awk, bc, grep, wget | ||
=head1 CONFIGURATION | ||
For this plugin to work, you need to set the password to the web interface of | ||
the freebox (http://mafreebox.freebox.fr) in the file /etc/munin/plugin-conf.d/ | ||
[freebox_*] | ||
env.password secret | ||
=head1 AUTHOR | ||
d-matt | ||
=head1 LICENSE | ||
GPLv2 | ||
=head1 CONTRIBUTE | ||
find this plugin on github at http://github.com/d-matt/freebox_munin | ||
=head1 VERSION | ||
1.0 | ||
=head1 CHANGELOG | ||
=head2 1.0 - 2011/11/22 | ||
first release. Works with firmware 1.1.3 | ||
=cut | ||
|
||
#MONITOR can only be status, uptime, temp, fan, attenuation, atm or snr | ||
MONITOR=`basename $0 | sed 's/^freebox_//g'` | ||
|
||
HTML_OUT="/tmp/freebox.html" | ||
|
||
WGET_CMD="wget -q --tries=1 --timeout=2 --output-document=$HTML_OUT" | ||
|
||
function identification { | ||
#---------------------------------------------------------------------------- | ||
# This function tries to connect to the freebox web interface. | ||
# The login page provide a authentification form which is posted | ||
# with wget and the authtification cookie is stored on the filesystem. | ||
# | ||
# Exit if the password is incorrect | ||
#---------------------------------------------------------------------------- | ||
|
||
#Try to authentificate | ||
$($WGET_CMD \ | ||
--save-cookies=/tmp/free_cookies.txt \ | ||
--post-data="login=freebox&passwd=$password" \ | ||
"http://mafreebox.freebox.fr/login.php") | ||
|
||
if grep -q "bad-pass" $HTML_OUT | ||
then | ||
#Bad password -> exit | ||
exit 1 | ||
fi | ||
|
||
} | ||
|
||
function get_page { | ||
#---------------------------------------------------------------------------- | ||
# This function fetch a page from the freebox web interface. The URL of the | ||
# page must be given as a parameter. | ||
# | ||
# If the session doesn't exist or is invalid on the freebox server, wget | ||
# will at first get the identification form with an error message | ||
# -> call identification function, then retry to download the page | ||
# | ||
# If the freebox is down, wget will exit with an error code (>0). If so, this | ||
# function will also exit with an error code. | ||
#---------------------------------------------------------------------------- | ||
local SUCCESS=false | ||
while ! $SUCCESS ; do | ||
$($WGET_CMD \ | ||
--load-cookies=/tmp/free_cookies.txt \ | ||
$1) | ||
|
||
# Make sure the connexion is OK. | ||
WGET_STATUS=$? | ||
if [ $WGET_STATUS -ne 0 ] | ||
then | ||
# wget had problems. | ||
# Stop there, because the freebox is probably offline | ||
exit 1 | ||
fi | ||
|
||
if grep -q "bad-pass" $HTML_OUT | ||
then | ||
identification | ||
else | ||
SUCCESS=true | ||
fi | ||
done | ||
} | ||
|
||
function get_status { | ||
#---------------------------------------------------------------------------- | ||
# Check the adsl status of the freebox : | ||
# - 1, if connected to the internet | ||
# - 0, otherwise | ||
# | ||
# This information is parsed from the settings first tab, in the span with | ||
# the id "conn_state". | ||
#---------------------------------------------------------------------------- | ||
get_page "http://mafreebox.freebox.fr/settings.php" | ||
|
||
CONN_STATE=$(grep "conn_state" $HTML_OUT|awk -F "[<>]" {'print $5'}) | ||
if [[ ! -z $CONN_STATE && $CONN_STATE == "Connecté" ]]; then | ||
CONN_STATE=1; | ||
else | ||
CONN_STATE=0; | ||
fi | ||
|
||
printf "status.value $CONN_STATE\n" | ||
} | ||
|
||
function get_uptime { | ||
#---------------------------------------------------------------------------- | ||
# Get the uptime of the freebox server. | ||
# | ||
# This information is parsed from the "Système" tab of the settings page, in | ||
# the <span> element after "Allumée depuis :". The format is | ||
# xx jour xx heures xx minutes xx secondes | ||
# | ||
# This function outputs the uptime in days | ||
#---------------------------------------------------------------------------- | ||
get_page "http://mafreebox.freebox.fr/settings.php?page=misc_system" | ||
|
||
UPTIME=$( grep "Allumée depuis" $HTML_OUT | awk -F "[<>]" {'print $5'} ) | ||
|
||
local DAY=$(echo "$UPTIME" | grep -oP '\K[0-9]+(?= jour)' ) | ||
local HOU=$(echo "$UPTIME" | grep -oP '\K[0-9]+(?= heure)' ) | ||
local MIN=$(echo "$UPTIME" | grep -oP '\K[0-9]+(?= minute)' ) | ||
local SEC=$(echo "$UPTIME" | grep -oP '\K[0-9]+(?= seconde)' ) | ||
|
||
if [ -z $DAY ]; then | ||
DAY=0 | ||
fi | ||
if [ -z $HOU ]; then | ||
HOU=0 | ||
fi | ||
if [ -z $MIN ]; then | ||
MIN=0 | ||
fi | ||
if [ -z $SEC ]; then | ||
SEC=0 | ||
fi | ||
|
||
UPTIME=$(echo "scale=2; ($DAY * 86400 + $HOU * 3600 + $MIN * 60 + $SEC) / 86400" |bc) | ||
|
||
printf "uptime.value $UPTIME\n" | ||
} | ||
|
||
function get_temperature { | ||
#---------------------------------------------------------------------------- | ||
# Get the temperature of the chips in the freebox. | ||
# This information is parsed from the "Système" tab of the settings page. | ||
# | ||
# CPUm : Marvell 88F6281 (http://www.marvell.com//embedded-processors/kirkwood/assets/HW_88F6281_OpenSource.pdf) | ||
# CPUb : Broadcom BCM6368 (for adsl) http://www.broadcom.com/products/Broadband-Carrier-Access/xDSL-CPE-Solutions/BCM6368 | ||
# SW : Marvell switch | ||
# | ||
# This function outputs the various temperature in degree celsius | ||
#---------------------------------------------------------------------------- | ||
get_page "http://mafreebox.freebox.fr/settings.php?page=misc_system" | ||
|
||
TCPUM=$( grep "Température CPUm" $HTML_OUT | grep -oP '\K[0-9]+(?= °C)' ) | ||
TCPUB=$( grep "Température CPUb" $HTML_OUT | grep -oP '\K[0-9]+(?= °C)' ) | ||
TSW=$( grep "Température SW" $HTML_OUT | grep -oP '\K[0-9]+(?= °C)' ) | ||
|
||
printf "tcpum.value $TCPUM\n" | ||
printf "tcpub.value $TCPUB\n" | ||
printf "tsw.value $TSW\n" | ||
} | ||
|
||
function get_fanspeed { | ||
#---------------------------------------------------------------------------- | ||
# Get the fan rotationnal speed of the freebox server. | ||
# | ||
# This information is parsed from the "Système" tab of the settings page, in | ||
# the <span> element after "Vitesse ventilateur :". | ||
# | ||
# This function outputs the value in RPM. | ||
#---------------------------------------------------------------------------- | ||
get_page "http://mafreebox.freebox.fr/settings.php?page=misc_system" | ||
|
||
FANSPEED=$(grep "Vitesse ventilateur" $HTML_OUT| grep -oP '\K[0-9]+(?= RPM)') | ||
|
||
if [ -z $FANSPEED ]; then | ||
FANSPEED="0" | ||
fi | ||
|
||
printf "fan.value $FANSPEED\n" | ||
} | ||
|
||
function get_atm_bandwidth { | ||
#---------------------------------------------------------------------------- | ||
# Get the ATM bandwidth in kbit/s. | ||
# | ||
# This information is parsed from the "ADSL > Statistiques" tab from the | ||
# following html structure : | ||
# | ||
# <tr> | ||
# <th>Débit ATM</th> | ||
# <td>[0-9]+ kbit/s</td> | ||
# <td>[0-9]+ kbit/s</td> | ||
# | ||
# -> The download value is obained with the first match of "kbit/s" on the | ||
# page | ||
# -> The upload value is obtained with the second match | ||
#---------------------------------------------------------------------------- | ||
get_page "http://mafreebox.freebox.fr/settings.php?page=conn_dsl_stats" | ||
|
||
grep -oP '\K[0-9]+(?= kbit/s)' $HTML_OUT |awk 'NR==1 {print "atm_down.value " $1}' | ||
grep -oP '\K[0-9]+(?= kbit/s)' $HTML_OUT |awk 'NR==2 {print "atm_up.value " $1}' | ||
|
||
} | ||
|
||
function get_attenuation { | ||
#---------------------------------------------------------------------------- | ||
# Get the line attenuation in dB. | ||
# | ||
# This information is parsed from the "ADSL > Statistiques" tab from the | ||
# following html structure : | ||
# | ||
# <tr> | ||
# <th>Atténuation</th> | ||
# <td>[0-9]+ dB</td> | ||
# <td>[0-9]+ dB</td> | ||
# </tr> | ||
# <tr> | ||
# <th>Marge de bruit</th> | ||
# <td>[0-9]+ dB</td> | ||
# <td>[0-9]+ dB</td> | ||
# </tr> | ||
# | ||
# -> The download value is obained with the first match of "dB" on the | ||
# page | ||
# -> The upload value is obtained with the second match | ||
#---------------------------------------------------------------------------- | ||
get_page "http://mafreebox.freebox.fr/settings.php?page=conn_dsl_stats" | ||
|
||
grep -oP '\K[0-9]+(?= dB)' $HTML_OUT |awk 'NR==1 {print "attenuation_down.value " $1}' | ||
grep -oP '\K[0-9]+(?= dB)' $HTML_OUT |awk 'NR==2 {print "attenuation_up.value " $1}' | ||
} | ||
|
||
function get_SNR_margin { | ||
#---------------------------------------------------------------------------- | ||
# Get the SNR margin in dB. | ||
# | ||
# This information is parsed from the "ADSL > Statistiques" tab from the | ||
# following html structure : | ||
# | ||
# <tr> | ||
# <th>Atténuation</th> | ||
# <td>[0-9]+ dB</td> | ||
# <td>[0-9]+ dB</td> | ||
# </tr> | ||
# <tr> | ||
# <th>Marge de bruit</th> | ||
# <td>[0-9]+ dB</td> | ||
# <td>[0-9]+ dB</td> | ||
# </tr> | ||
# -> The download value is obained with the third match of "dB" on the | ||
# page | ||
# -> The upload value is obtained with the fourth match | ||
#---------------------------------------------------------------------------- | ||
get_page "http://mafreebox.freebox.fr/settings.php?page=conn_dsl_stats" | ||
|
||
grep -oP '\K[0-9]+(?= dB)' $HTML_OUT |awk 'NR==3 {print "snr_down.value " $1}' | ||
grep -oP '\K[0-9]+(?= dB)' $HTML_OUT |awk 'NR==4 {print "snr_up.value " $1}' | ||
} | ||
|
||
|
||
if [ "$1" = "config" ]; then | ||
printf "graph_category freebox\n" | ||
printf "graph_args --base 1000 -l 0\n" | ||
|
||
case "$MONITOR" in | ||
status) | ||
printf "graph_title Freebox $MONITOR\n" | ||
printf "$MONITOR.label $MONITOR\n" | ||
printf "graph_vlabel $MONITOR\n" | ||
printf "graph_info This graph shows the status of the freebox server. 1-> Connected, 0-> Disconnected\n" | ||
printf "$MONITOR.draw AREA\n" | ||
;; | ||
uptime) | ||
printf "graph_title Freebox $MONITOR in days\n" | ||
printf "$MONITOR.label $MONITOR\n" | ||
printf "graph_vlabel $MONITOR\n" | ||
printf "graph_info This graph shows the uptime of the freebox server.\n" | ||
printf "$MONITOR.draw AREA\n" | ||
;; | ||
temp) | ||
printf "graph_title Freebox temperatures\n" | ||
printf "graph_info This graph shows the temperatures of the freebox server.\n" | ||
printf "graph_vlabel Temp in °C\n" | ||
printf "tcpum.label Temp CPUm\n" | ||
printf "tcpub.label Temp CPUb\n" | ||
printf "tsw.label Temp SW\n" | ||
;; | ||
fan) | ||
printf "graph_title Freebox fan speed\n" | ||
printf "graph_info This graph shows the fan rotationnal speed of the freebox server.\n" | ||
printf "$MONITOR.label fan speed\n" | ||
printf "graph_vlabel fan speed (RPM)\n" | ||
;; | ||
atm) | ||
printf "graph_title Freebox ATM Bandwidth (Up and Down)\n" | ||
printf "graph_info This graph shows the ATM bandwith of the freebox server.\n" | ||
printf "atm_down.label ATM down\n" | ||
printf "atm_up.label ATM up\n" | ||
printf "graph_vlabel ATM Bandwidth (kbit/s)\n" | ||
;; | ||
attenuation) | ||
printf "graph_title Freebox Attenuation (Up and Down)\n" | ||
printf "graph_info This graph shows the Attenuation of the ADSL line of the freebox server.\n" | ||
printf "attenuation_down.label Attenuation down\n" | ||
printf "attenuation_up.label Attenuation up\n" | ||
printf "graph_vlabel Line attenuation (dB)\n" | ||
;; | ||
snr) | ||
printf "graph_title Freebox SNR margin (Up and Down)\n" | ||
printf "graph_info This graph shows the SNR margin of the adsl line of the freebox server.\n" | ||
printf "snr_down.label SNR margin down\n" | ||
printf "snr_up.label SNR margin up\n" | ||
printf "graph_vlabel SNR margin (dB)\n" | ||
;; | ||
*) | ||
printf "ERROR : Monitor can only be status, uptime, temp or fan\n" | ||
exit 1; | ||
;; | ||
esac | ||
exit 0 | ||
fi; | ||
|
||
case "$MONITOR" in | ||
status) | ||
get_status | ||
;; | ||
uptime) | ||
get_uptime | ||
;; | ||
temp) | ||
get_temperature | ||
;; | ||
fan) | ||
get_fanspeed | ||
;; | ||
atm) | ||
get_atm_bandwidth | ||
;; | ||
attenuation) | ||
get_attenuation | ||
;; | ||
snr) | ||
get_SNR_margin | ||
;; | ||
*) | ||
printf "ERROR : Monitor can only be status, uptime, temp or fan\n" | ||
exit 1; | ||
;; | ||
esac | ||
exit 0 |