support configuration of munin plugin through environment variables
authorChristian Weiske <cweiske@cweiske.de>
Tue, 28 Dec 2010 22:04:12 +0000 (23:04 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Tue, 28 Dec 2010 22:04:12 +0000 (23:04 +0100)
scripts/munin.php

index 4872e90114e5e0dc89a412d2dc53e6241e7a4fbb..dc7d050ff862f0331e9c2a7ece7fe2185e60f6c6 100755 (executable)
  */
 require_once 'Wrt3g.php';
 
+$options = array();
+foreach (array('host', 'user', 'password') as $variable) {
+    if (isset($_SERVER[$variable])) {
+        $options[$variable] = $_SERVER[$variable];
+    }
+}
+
 if (isset($argv[1]) && $argv[1] == 'autoconf') {
     $router = new Wrt3g();
-    $router->loadConfig();
+    $router->loadConfig($options);
     if ($router->config->host === null) {
         echo "no (no host configured)\n";
     } else {
@@ -53,15 +60,19 @@ 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
+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
+  <nothing> - Print status for munin-node consumption
 
 TXT;
     exit();
@@ -70,7 +81,7 @@ TXT;
 
 try {
     $router = new Wrt3g();
-    $router->loadConfig();
+    $router->loadConfig($options);
 
     $arStatus = $router->getConnectionStatus();