add help to munin plugin
[linksys-wrt3g-tools.git] / scripts / munin.php
1 #!/usr/bin/env php
2 <?php
3 /**
4  * Munin node plugin to monitor the router status.
5  * Part of Linksys WRT3G tools
6  *
7  * PHP version 5
8  *
9  * @category Tools
10  * @package  linksys-wrt3g-tools
11  * @author   Christian Weiske <cweiske@cweiske.de>
12  * @license  AGPL v3
13  * @link     http://cweiske.de/linksys-wrt3g-tools.htm
14  * @link     http://munin-monitoring.org/wiki/ConcisePlugins
15  */
16 require_once 'Wrt3g.php';
17
18 if (isset($argv[1]) && $argv[1] == 'autoconf') {
19     $router = new Wrt3g();
20     $router->loadConfig();
21     if ($router->config->host === null) {
22         echo "no (no host configured)\n";
23     } else {
24         echo "yes\n";
25     }
26     exit();
27
28 } else if (isset($argv[1]) && $argv[1] == 'config') {
29     echo <<<TXT
30 graph_title WRT3G router status
31 graph_args --base 1000 -l 0 --upper-limit 7
32 graph_vlabel Status values
33 graph_category network
34 graph_info This graph shows the status of a WRT3G router
35 conn_connected.label Connected
36 conn_connected.info Router is connected
37 conn_connected.draw LINE2
38 conn_connecting.label Connecting
39 conn_connecting.info Router is connecting
40 conn_connecting.draw LINE2
41 conn_disconnected.label Disconnected
42 conn_disconnected.info Router is disconnected
43 conn_disconnected.draw LINE2
44 notavailable.label Not available
45 notavailable.info Router cannot be reached
46 notavailable.draw LINE2
47 type_gprs.label GPRS
48 type_gprs.info Connection via GPRS
49 type_gprs.draw LINE2
50 type_umts.label UMTS
51 type_umts.info Connection via UMTS
52 type_umts.draw LINE2
53
54 TXT;
55     exit();
56 } else if (isset($argv[1])
57     && ($argv[1] == 'help' || $argv[1] == '--help' || $argv[1] == '-h')
58 ) {
59     echo <<<TXT
60 munin-node plugin to monitor a linksys wrt3g router
61 Commands:
62   autoconf  - Check if the plugin would work
63   config    - Show munin config values
64   <nothing> - Print status
65
66 TXT;
67     exit();
68 }
69
70
71 try {
72     $router = new Wrt3g();
73     $router->loadConfig();
74
75     $arStatus = $router->getConnectionStatus();
76
77     $conn = $arStatus['connection'];
78     if ($conn == 'disconnected') {
79         echo "conn_disconnected.value 1\n";
80     } else if ($conn == 'connecting') {
81         echo "conn_connecting.value 2\n";
82     } else if ($conn == 'connected') {
83         echo "conn_connected.value 3\n";
84     }
85
86     $type = strtolower($arStatus['type']);
87     if ($type == 'gprs') {
88         echo "type_gprs.value 4.5\n";
89     } else if ($type == 'umts') {
90         echo "type_umts.value 5\n";
91     }
92 } catch (Exception $e) {
93     echo "notavailable 0.5\n";
94 }
95 ?>