From 8ca0382f423d3eb9d33d3cc6701105e261591fa8 Mon Sep 17 00:00:00 2001 From: Steven Stallion Date: Tue, 7 Nov 2017 18:18:40 -0600 Subject: [PATCH] Support host-specific local plugins --- graph.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/graph.php b/graph.php index f1696fa..89056ea 100644 --- a/graph.php +++ b/graph.php @@ -4,6 +4,7 @@ require_once 'inc/functions.inc.php'; require_once 'inc/collectd.inc.php'; +$host = GET('h'); $plugin = GET('p'); $type = GET('t'); $width = GET('x') ? filter_var(GET('x'), FILTER_VALIDATE_INT, array( @@ -58,6 +59,19 @@ $plugin_json = $plugin_json_local; } } + if (file_exists('plugin/local/'.$host.'.json')) { + $json = file_get_contents('plugin/local/'.$host.'.json'); + $plugin_json_local = json_decode($json, true); + + if (is_null($plugin_json_local)) + error_log('CGP Error: invalid json in plugin/local/'.$host.'.json'); + + if (is_array($plugin_json)) { + $plugin_json = array_replace_recursive($plugin_json, $plugin_json_local); + } else { + $plugin_json = $plugin_json_local; + } + } } if (!isset($plugin_json[$type]['type']))