use new config for munin script
[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 'Wrt3g.php';
15
16 if (isset($argv[1]) && $argv[1] == 'autoconf') {
17     echo "yes\n";
18     exit();
19 } else if (isset($argv[1]) && $argv[1] == 'config') {
20     echo <<<TXT
21 graph_title WRT3G router status
22 graph_args --base 1000 -l 0 --upper-limit 7
23 graph_vlabel Status values
24 graph_category network
25 graph_info This graph shows the status of WRT3G router
26 conn_connected.label Connected
27 conn_connected.info Router is connected
28 conn_connected.draw LINE2
29 conn_connecting.label Connecting
30 conn_connecting.info Router is connecting
31 conn_connecting.draw LINE2
32 conn_disconnected.label Disconnected
33 conn_disconnected.info Router is disconnected
34 conn_disconnected.draw LINE2
35 notavailable.label Not available
36 notavailable.info Router cannot be reached
37 notavailable.draw LINE2
38 type_gprs.label GPRS
39 type_gprs.info Connection via GPRS
40 type_gprs.draw LINE2
41 type_umts.label UMTS
42 type_umts.info Connection via UMTS
43 type_umts.draw LINE2
44
45 TXT;
46     exit();
47 }
48
49
50 try {
51     $router = new Wrt3g();
52     $router->loadConfig();
53
54     $arStatus = $router->getConnectionStatus();
55
56     $conn = $arStatus['connection'];
57     if ($conn == 'disconnected') {
58         echo "conn_disconnected.value 1\n";
59     } else if ($conn == 'connecting') {
60         echo "conn_connecting.value 2\n";
61     } else if ($conn == 'connected') {
62         echo "conn_connected.value 3\n";
63     }
64
65     $type = strtolower($arStatus['type']);
66     if ($type == 'gprs') {
67         echo "type_gprs.value 4.5\n";
68     } else if ($type == 'umts') {
69         echo "type_umts.value 5\n";
70     }
71 } catch (Exception $e) {
72     echo "notavailable 0.5\n";
73 }
74 ?>