-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathavm-fritzbox-wan-live-traffic
124 lines (111 loc) · 5.22 KB
/
avm-fritzbox-wan-live-traffic
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/php
<?php
##############################
# Plugin: AVM Fritz!Box WAN traffic (over UPNP)
# Author: Andreas Kreisl
#
# Licence: Creative Commons - Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
# http://creativecommons.org/licenses/by-sa/3.0/
##############################
# Modification by: Vincent Kocher / www.wombat.ch/munin
# Modicication data/reason: 12.01.2015 / removed all Max UP and Max Down and created new file
# Modification date/reason: 09.01.2015 / upnp path changed with AVM Fritzbox IOS 6.20 (7390)
# Modification date/reason: 08.01.2015 / "graph_category" Titel modified from Network to WAN
##############################
#%# family=auto
#%# capabilities=autoconf
# if you don't get a graph, change "fritz.box" to your Router IP Adresse
$host = "fritz.box";
if(isset($argv[1]) && $argv[1] == "autoconf") {
echo "yes\n";
} else if(isset($argv[1]) && $argv[1] == "config") {
$data_prop = GetCommonLinkProperties();
//$data_ip = GetExternalIP(); // $data_ip['NewExternalIPAddress']
echo "graph_order down up\n";
echo "graph_title AVM Fritz!Box WAN (live) traffic\n";
echo "graph_args --base 1024\n";
echo "graph_vlabel bits in (-) / out (+) per \${graph_period}\n";
echo "graph_category WAN\n";
echo "graph_info This graph shows the traffic of the AVM Fritz!Box WAN network interface. Without showing MaxUP and MaxDOWN. Please note that the traffic is shown in bits per second, not bytes.\n";
echo "down.label received\n";
echo "down.type COUNTER\n";
echo "down.graph no\n";
echo "down.cdef down,8,*\n";
echo "up.label " . $data_prop['NewWANAccessType'] . " (" . $data_prop['NewPhysicalLinkStatus'] . ")\n";
echo "up.type COUNTER\n";
echo "up.negative down\n";
echo "up.draw AREA\n";
echo "up.cdef up,8,*\n";
echo "up.info Traffic of the WAN interface.\n";
} else {
$data_prop = GetCommonLinkProperties();
$data_stats = GetAddonInfos();
echo "up.value " . $data_stats['NewTotalBytesSent'] . "\n";
echo "down.value " . $data_stats['NewTotalBytesReceived'] . "\n";
}
function GetCommonLinkProperties() {
$data_url = '/igdupnp/control/WANCommonIFC1';
$data_soap = '"urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1#GetCommonLinkProperties"';
$data_xml = '<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetCommonLinkProperties xmlns:u=urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1 /></s:Body></s:Envelope>';
$tmp = DoCurl($data_url,$data_soap,$data_xml);
$data_result = Array();
$data_result['NewLayer1UpstreamMaxBitRate'] = FindKey($tmp,"NewLayer1UpstreamMaxBitRate");
$data_result['NewLayer1DownstreamMaxBitRate'] = FindKey($tmp,"NewLayer1DownstreamMaxBitRate");
$data_result['NewWANAccessType'] = FindKey($tmp,"NewWANAccessType");
$data_result['NewPhysicalLinkStatus'] = FindKey($tmp,"NewPhysicalLinkStatus");
return $data_result;
}
function GetAddonInfos() {
$data_url = '/igdupnp/control/WANCommonIFC1';
$data_soap = '"urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1#GetAddonInfos"';
$data_xml = '<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetAddonInfos xmlns:u=urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1 /></s:Body></s:Envelope>';
$tmp = DoCurl($data_url,$data_soap,$data_xml);
$data_result = Array();
$data_result['NewTotalBytesSent'] = FindKey($tmp,"NewTotalBytesSent");
$data_result['NewTotalBytesReceived'] = FindKey($tmp,"NewTotalBytesReceived");
return $data_result;
}
function GetExternalIP() {
$data_url = '/igdupnp/control/WANIPConn1';
$data_soap = '"urn:schemas-upnp-org:service:WANIPConnection:1#GetExternalIPAddress"';
$data_xml = '<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetExternalIPAddress xmlns:u=urn:schemas-upnp-org:service:WANIPConnection:1 /></s:Body></s:Envelope>';
$tmp = DoCurl($data_url,$data_soap,$data_xml);
$data_result = Array();
$data_result['NewExternalIPAddress'] = FindKey($tmp,"NewExternalIPAddress");
return $data_result;
}
function DoCurl($url,$soap,$xml) {
$ch = curl_init("http://" . $GLOBALS["host"] . ":49000" . $url);
$headers = array();
//$headers[] = 'POST ' . $url . ' HTTP/1.1'; // Will be automaticly set.
$headers[] = 'Content-Type: text/xml; charset="utf-8"';
$headers[] = 'HOST: ' . $GLOBALS["host"] . ':49000';
$headers[] = 'Content-Length: ' . strlen($xml);
$headers[] = 'SOAPACTION: ' . $soap;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_IPRESOLVE, 1); // Force IPv4
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); // Add XML in POST-Header
$tmp = curl_exec($ch);
curl_close($ch);
return $tmp;
}
function FindKey($text,$key) {
$p1 = strpos($text,$key);
if($p1 === false) {
$tmp = "";
} else {
$p1 = strpos($text,'>',$p1) +1;
$p2 = strpos($text,'<',$p1);
if($p2 === false) {
$tmp = "";
} else {
$tmp = substr($text,$p1,$p2-$p1);
}
}
return $tmp;
}
?>