From c91a7081cc709a8820e46b59a41bc255f7ced3a5 Mon Sep 17 00:00:00 2001 From: Rosiak Date: Sun, 17 Jan 2016 17:47:26 +0100 Subject: [PATCH 1/2] Basic commit --- doc/Extensions/Oxidized.md | 8 ++++++++ includes/defaults.inc.php | 3 ++- includes/functions.php | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/doc/Extensions/Oxidized.md b/doc/Extensions/Oxidized.md index aa8ca51136..7f7d2ebf57 100644 --- a/doc/Extensions/Oxidized.md +++ b/doc/Extensions/Oxidized.md @@ -53,6 +53,14 @@ You will need to configure default credentials for your devices, LibreNMS doesn' X-Auth-Token: '01582bf94c03104ecb7953dsadsadwed' ``` +LibreNMS is able to reload the Oxidized list of nodes, each time a device is added to LibreNMS. +To do so, add the following to your config.php. + +```php +$config['oxidized']['reload_nodes'] = TRUE; + +``` + ### Using Groups To return a group to Oxidized you can do this by matching a regex for either hostname or location. The order is hostname is matched first, if nothing is found then location is attempted. diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index c71b394427..eeb9b5da32 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -471,8 +471,9 @@ $config['rancid_ignorecomments'] = 0; // $config['collectd_dir'] = '/var/lib/collectd/rrd'; // $config['smokeping']['dir'] = "/var/lib/smokeping/"; $config['smokeping']['pings'] = 20; -// $config['oxidized']['enabled'] = FALSE;//Set to TRUE +$config['oxidized']['enabled'] = FALSE;//Set to TRUE // $config['oxidized']['url'] = 'http://127.0.0.1:8888';// Set the Oxidized rest URL +$config['oxidized']['reload_nodes'] = FALSE;//Set to TRUE, check documentation // NFSen RRD dir. $config['nfsen_enable'] = 0; // $config['nfsen_split_char'] = "_"; diff --git a/includes/functions.php b/includes/functions.php index bb128bd13a..c9d842b9a3 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -580,6 +580,7 @@ function createHost($host, $community = NULL, $snmpver, $port = 161, $transport if (host_exists($host) === false) { $device_id = dbInsert($device, 'devices'); if ($device_id) { + oxidized_reload_nodes(); return($device_id); } else { @@ -1302,3 +1303,20 @@ function warn_innodb_buffer($innodb_buffer) { $output .= 'Config proposal: "innodb_buffer_pool_size = '.pow(2,ceil(log(($innodb_buffer['used'] / 1024 / 1024),2))).'M"'.PHP_EOL; return $output; } + +function oxidized_reload_nodes() { + + global $config; + + if ($config['oxidized']['enabled'] === TRUE && $config['oxidized']['reload_nodes'] === TRUE && isset($config['oxidized']['url'])) { + $oxidized_reload_url = $config['oxidized']['url'] . '/reload'; + $ch = curl_init($oxidized_reload_url); + + curl_setopt($ch, CURLOPT_TIMEOUT, 5); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HEADER, 1); + curl_exec($ch); + curl_close($ch); + } +} From 4581366bf487f7d5cce79e819f9d6d9525ae6c71 Mon Sep 17 00:00:00 2001 From: Rosiak Date: Sun, 17 Jan 2016 19:19:56 +0100 Subject: [PATCH 2/2] Add WebUI settings --- doc/Extensions/Oxidized.md | 2 +- html/pages/settings/external.inc.php | 4 ++++ includes/defaults.inc.php | 4 ++-- sql-schema/090.sql | 1 + 4 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 sql-schema/090.sql diff --git a/doc/Extensions/Oxidized.md b/doc/Extensions/Oxidized.md index 7f7d2ebf57..23153780b2 100644 --- a/doc/Extensions/Oxidized.md +++ b/doc/Extensions/Oxidized.md @@ -54,7 +54,7 @@ You will need to configure default credentials for your devices, LibreNMS doesn' ``` LibreNMS is able to reload the Oxidized list of nodes, each time a device is added to LibreNMS. -To do so, add the following to your config.php. +To do so, edit the option in Global Settings>External Settings>Oxidized Integration or add the following to your config.php. ```php $config['oxidized']['reload_nodes'] = TRUE; diff --git a/html/pages/settings/external.inc.php b/html/pages/settings/external.inc.php index ccade1add5..fe89d4645e 100644 --- a/html/pages/settings/external.inc.php +++ b/html/pages/settings/external.inc.php @@ -25,6 +25,10 @@ $oxidized_conf = array( 'descr' => 'Set the default group returned', 'type' => 'text', ), + array('name' => 'oxidized.reload_nodes', + 'descr' => 'Reload Oxidized nodes list, each time a device is added', + 'type' => 'checkbox', + ), ); $unixagent_conf = array( diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index eeb9b5da32..39701fd39d 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -471,9 +471,9 @@ $config['rancid_ignorecomments'] = 0; // $config['collectd_dir'] = '/var/lib/collectd/rrd'; // $config['smokeping']['dir'] = "/var/lib/smokeping/"; $config['smokeping']['pings'] = 20; -$config['oxidized']['enabled'] = FALSE;//Set to TRUE +// $config['oxidized']['enabled'] = FALSE;//Set to TRUE // $config['oxidized']['url'] = 'http://127.0.0.1:8888';// Set the Oxidized rest URL -$config['oxidized']['reload_nodes'] = FALSE;//Set to TRUE, check documentation +// $config['oxidized']['reload_nodes'] = FALSE;//Set to TRUE, check documentation // NFSen RRD dir. $config['nfsen_enable'] = 0; // $config['nfsen_split_char'] = "_"; diff --git a/sql-schema/090.sql b/sql-schema/090.sql new file mode 100644 index 0000000000..dc08f0c671 --- /dev/null +++ b/sql-schema/090.sql @@ -0,0 +1 @@ +INSERT INTO config (config_name,config_value,config_default,config_descr,config_group,config_group_order,config_sub_group,config_sub_group_order,config_hidden,config_disabled) values ('oxidized.reload_nodes','false','false','Reload Oxidized nodes list, each time a device is added','external',0,'oxidized',0,'0','0'); \ No newline at end of file