184f889a8ab7d6df77df1ce73a6d9eca28f91195
[linksys-wrt3g-tools.git] / scripts / munin.php
1 #!/usr/bin/env php
2 <?php
3 /**
4 * munin node output for the router status
5 *
6 * PHP version 5
7 *
8 * @category Tools
9 * @package  linksys-wrt3g-tools
10 * @author   Christian Weiske <cweiske@cweiske.de>
11 * @license  AGPL v3
12 * @link     http://cweiske.de/linksys-wrt3g-tools.htm
13 */
14 require_once dirname(__FILE__) . '/../config.php';
15 require_once 'Wrt3g.php';
16
17 if (isset($argv[1]) && $argv[1] == 'autoconf') {
18     echo "yes\n";
19     exit();
20 } else if (isset($argv[1]) && $argv[1] == 'config') {
21     echo <<<TXT
22 graph_title WRT3G router status
23 graph_args --base 1000 -l 0 --upper-limit 7
24 graph_vlabel Status values
25 graph_category network
26 graph_info This graph shows the status of WRT3G router
27 conn_connected.label Connected
28 conn_connected.info Router is connected
29 conn_connected.draw LINE2
30 conn_connecting.label Connecting
31 conn_connecting.info Router is connecting
32 conn_connecting.draw LINE2
33 conn_disconnected.label Disconnected
34 conn_disconnected.info Router is disconnected
35 conn_disconnected.draw LINE2
36 notavailable.label Not available
37 notavailable.info Router cannot be reached
38 notavailable.draw LINE2
39 type_gprs.label GPRS
40 type_gprs.info Connection via GPRS
41 type_gprs.draw LINE2
42 type_umts.label UMTS
43 type_umts.info Connection via UMTS
44 type_umts.draw LINE2
45
46 TXT;
47     exit();
48 }
49
50
51 try {
52     $w = new Wrt3g();
53     $arStatus = $w->getStatus();
54
55     $conn = $arStatus['connection'];
56     if ($conn == 'disconnected') {
57         echo "conn_disconnected.value 1\n";
58     } else if ($conn == 'connecting') {
59         echo "conn_connecting.value 2\n";
60     } else if ($conn == 'connected') {
61         echo "conn_connected.value 3\n";
62     }
63
64     $type = strtolower($arStatus['type']);
65     if ($type == 'gprs') {
66         echo "type_gprs.value 4.5\n";
67     } else if ($type == 'umts') {
68         echo "type_umts.value 5\n";
69     }
70 } catch (Exception $e) {
71     echo "notavailable 0.5\n";
72 }
73 ?>