load environment variables by default
[linksys-wrt3g-tools.git] / scripts / munin.php
index cf7892f9459f09c90fc3236cc92f4e58f7ad366c..0722035b74379e9359ac092a97f66f1eff3cf1d6 100755 (executable)
@@ -1,29 +1,37 @@
 #!/usr/bin/env php
 <?php
 /**
-* munin node output for the router status
-*
-* PHP version 5
-*
-* @category Tools
-* @package  linksys-wrt3g-tools
-* @author   Christian Weiske <cweiske@cweiske.de>
-* @license  AGPL v3
-* @link     http://cweiske.de/linksys-wrt3g-tools.htm
-*/
-require_once dirname(__FILE__) . '/../config.php';
+ * Munin node plugin to monitor the router status.
+ * Part of Linksys WRT3G tools
+ *
+ * PHP version 5
+ *
+ * @category Tools
+ * @package  linksys-wrt3g-tools
+ * @author   Christian Weiske <cweiske@cweiske.de>
+ * @license  AGPL v3
+ * @link     http://cweiske.de/linksys-wrt3g-tools.htm
+ * @link     http://munin-monitoring.org/wiki/ConcisePlugins
+ */
 require_once 'Wrt3g.php';
 
 if (isset($argv[1]) && $argv[1] == 'autoconf') {
-    echo "yes\n";
+    $router = new Wrt3g();
+    $router->loadConfig();
+    if ($router->config->host === null) {
+        echo "no (no host configured)\n";
+    } else {
+        echo "yes\n";
+    }
     exit();
+
 } else if (isset($argv[1]) && $argv[1] == 'config') {
     echo <<<TXT
 graph_title WRT3G router status
 graph_args --base 1000 -l 0 --upper-limit 7
 graph_vlabel Status values
 graph_category network
-graph_info This graph shows the status of WRT3G router
+graph_info This graph shows the status of WRT3G router
 conn_connected.label Connected
 conn_connected.info Router is connected
 conn_connected.draw LINE2
@@ -43,6 +51,22 @@ type_umts.label UMTS
 type_umts.info Connection via UMTS
 type_umts.draw LINE2
 
+TXT;
+    exit();
+
+} else if (isset($argv[1])
+    && ($argv[1] == 'help' || $argv[1] == '--help' || $argv[1] == '-h')
+) {
+    echo <<<TXT
+munin-node plugin to monitor a linksys wrt3g router.
+
+Supports environment variables: host, user, password
+
+Commands:
+  autoconf  - Check if the plugin would work
+  config    - Show munin config values
+  <nothing> - Print status for munin-node consumption
+
 TXT;
     exit();
 }
@@ -50,9 +74,7 @@ TXT;
 
 try {
     $router = new Wrt3g();
-    $router->host     = $GLOBALS['linksys-wrt3g-tools']['host'];
-    $router->user     = $GLOBALS['linksys-wrt3g-tools']['user'];
-    $router->password = $GLOBALS['linksys-wrt3g-tools']['password'];
+    $router->loadConfig();
 
     $arStatus = $router->getConnectionStatus();