mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Merge pull request #2994 from murrant/config_diff
Oxidized config diffs
This commit is contained in:
@@ -12,14 +12,13 @@ $config['oxidized']['enabled'] = TRUE;
|
||||
$config['oxidized']['url'] = 'http://127.0.0.1:8888';
|
||||
```
|
||||
|
||||
We also support config versioning within Oxidized, this will allow you to see the old configs stored.
|
||||
|
||||
LibreNMS supports config versioning if Oxidized does. This is known to work with the git output module.
|
||||
```php
|
||||
$config['oxidized']['features']['versioning'] = true;
|
||||
```
|
||||
|
||||
Oxidized supports various ways to utilise credentials to login to devices, you can specify global username/password within Oxidized, Group level username/password or per device.
|
||||
We currently support sending groups back to Oxidized so that you can then define group credentials within Oxidized. To enable this support please switch on 'Enable the return of groups to Oxidized':
|
||||
LibreNMS currently supports sending groups back to Oxidized so that you can then define group credentials within Oxidized. To enable this support please switch on 'Enable the return of groups to Oxidized':
|
||||
|
||||
```php
|
||||
$config['oxidized']['group_support'] = true;
|
||||
@@ -35,7 +34,7 @@ $config['oxidized']['default_group'] = 'default';
|
||||
|
||||
Oxidized has support for feeding devices into it via an API call, support for Oxidized has been added to the LibreNMS API. A sample config for Oxidized is provided below.
|
||||
|
||||
You will need to configure default credentials for your devices, LibreNMS doesn't provide login credentials at this time.
|
||||
You will need to configure default credentials for your devices in the Oxidized config, LibreNMS doesn't provide login credentials at this time.
|
||||
|
||||
```bash
|
||||
source:
|
||||
@@ -61,7 +60,7 @@ $config['oxidized']['reload_nodes'] = TRUE;
|
||||
|
||||
```
|
||||
|
||||
### Using Groups
|
||||
#### 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.
|
||||
The first match found will be used. To match on the device hostnames that contain 'lon-sw' or if the location contains 'London' then you would place the following within config.php:
|
||||
@@ -80,7 +79,7 @@ groups:
|
||||
password: <password>
|
||||
```
|
||||
|
||||
### Miscellaneous
|
||||
#### Miscellaneous
|
||||
|
||||
If you have devices which you do not wish to appear in Oxidized then you can edit those devices in Device -> Edit -> Misc and enable "Exclude from Oxidized?"
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ LibreNMS 3rd party acknowledgements
|
||||
- TW Sack (https://code.google.com/p/tw-sack/): GPLv3
|
||||
- Gridster (http://gridster.net/): MIT
|
||||
- Pure PHP radius class (http://developer.sysco.ch/php/): GPLv3
|
||||
- GeSHi - Generic Syntax Highlighter (http://qbnz.com/highlighter/): GPLv2+
|
||||
|
||||
#### 3rd Party GPLv3 Non-compliant
|
||||
|
||||
|
||||
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
/*************************************************************************************
|
||||
* diff.php
|
||||
* --------
|
||||
* Author: Conny Brunnkvist ([email protected]), W. Tasin ([email protected])
|
||||
* Copyright: (c) 2004 Fuchsia Open Source Solutions (http://www.fuchsia.se/)
|
||||
* Release Version: 1.0.8.12
|
||||
* Date Started: 2004/12/29
|
||||
*
|
||||
* Diff-output language file for GeSHi.
|
||||
*
|
||||
* CHANGES
|
||||
* -------
|
||||
* 2008/05/23 (1.0.7.22)
|
||||
* - Added description of extra language features (SF#1970248)
|
||||
* 2006/02/27
|
||||
* - changing language file to use matching of start (^) and end ($) (wt)
|
||||
* 2004/12/29 (1.0.0)
|
||||
* - First Release
|
||||
*
|
||||
* TODO (updated 2006/02/27)
|
||||
* -------------------------
|
||||
*
|
||||
*
|
||||
*************************************************************************************
|
||||
*
|
||||
* This file is part of GeSHi.
|
||||
*
|
||||
* GeSHi is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GeSHi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GeSHi; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
|
||||
$language_data = array (
|
||||
'LANG_NAME' => 'Diff',
|
||||
'COMMENT_SINGLE' => array(),
|
||||
'COMMENT_MULTI' => array(),
|
||||
'CASE_KEYWORDS' => GESHI_CAPS_NO_CHANGE,
|
||||
'QUOTEMARKS' => array(),
|
||||
'ESCAPE_CHAR' => ' ',
|
||||
'KEYWORDS' => array(
|
||||
1 => array(
|
||||
'\ No newline at end of file'
|
||||
),
|
||||
// 2 => array(
|
||||
// '***************' /* This only seems to works in some cases? */
|
||||
// ),
|
||||
),
|
||||
'SYMBOLS' => array(
|
||||
),
|
||||
'CASE_SENSITIVE' => array(
|
||||
1 => false,
|
||||
// 2 => false
|
||||
),
|
||||
'STYLES' => array(
|
||||
'KEYWORDS' => array(
|
||||
1 => 'color: #aaaaaa; font-style: italic;',
|
||||
// 2 => 'color: #dd6611;',
|
||||
),
|
||||
'COMMENTS' => array(
|
||||
),
|
||||
'ESCAPE_CHAR' => array(
|
||||
0 => ''
|
||||
),
|
||||
'BRACKETS' => array(
|
||||
0 => ''
|
||||
),
|
||||
'STRINGS' => array(
|
||||
0 => ''
|
||||
),
|
||||
'NUMBERS' => array(
|
||||
0 => ''
|
||||
),
|
||||
'METHODS' => array(
|
||||
0 => ''
|
||||
),
|
||||
'SYMBOLS' => array(
|
||||
0 => ''
|
||||
),
|
||||
'SCRIPT' => array(
|
||||
0 => ''
|
||||
),
|
||||
'REGEXPS' => array(
|
||||
0 => 'color: #440088;',
|
||||
1 => 'color: #991111;',
|
||||
2 => 'color: #00b000;',
|
||||
3 => 'color: #888822;',
|
||||
4 => 'color: #888822;',
|
||||
5 => 'color: #0011dd;',
|
||||
6 => 'color: #440088;',
|
||||
7 => 'color: #991111;',
|
||||
8 => 'color: #00b000;',
|
||||
9 => 'color: #888822;',
|
||||
),
|
||||
),
|
||||
'URLS' => array(
|
||||
1 => '',
|
||||
// 2 => ''
|
||||
),
|
||||
'OOLANG' => false,
|
||||
'OBJECT_SPLITTERS' => array(),
|
||||
'REGEXPS' => array(
|
||||
0 => "[0-9,]+[acd][0-9,]+",
|
||||
//Removed lines
|
||||
1 => array(
|
||||
GESHI_SEARCH => '(^|(?<=\A\s))\\<.*$',
|
||||
GESHI_REPLACE => '\\0',
|
||||
GESHI_MODIFIERS => 'm',
|
||||
GESHI_BEFORE => '',
|
||||
GESHI_AFTER => ''
|
||||
),
|
||||
//Inserted lines
|
||||
2 => array(
|
||||
GESHI_SEARCH => '(^|(?<=\A\s))\\>.*$',
|
||||
GESHI_REPLACE => '\\0',
|
||||
GESHI_MODIFIERS => 'm',
|
||||
GESHI_BEFORE => '',
|
||||
GESHI_AFTER => ''
|
||||
),
|
||||
//Location line
|
||||
3 => array(
|
||||
GESHI_SEARCH => '(^|(?<=\A\s))-{3}\\s.*$',
|
||||
GESHI_REPLACE => '\\0',
|
||||
GESHI_MODIFIERS => 'm',
|
||||
GESHI_BEFORE => '',
|
||||
GESHI_AFTER => ''
|
||||
),
|
||||
//Inserted line
|
||||
4 => array(
|
||||
GESHI_SEARCH => '(^|(?<=\A\s))(\\+){3}\\s.*$',
|
||||
GESHI_REPLACE => '\\0',
|
||||
GESHI_MODIFIERS => 'm',
|
||||
GESHI_BEFORE => '',
|
||||
GESHI_AFTER => ''
|
||||
),
|
||||
//Modified line
|
||||
5 => array(
|
||||
GESHI_SEARCH => '(^|(?<=\A\s))\\!.*$',
|
||||
GESHI_REPLACE => '\\0',
|
||||
GESHI_MODIFIERS => 'm',
|
||||
GESHI_BEFORE => '',
|
||||
GESHI_AFTER => ''
|
||||
),
|
||||
//File specification
|
||||
6 => array(
|
||||
GESHI_SEARCH => '(^|(?<=\A\s))[\\@]{2}.*$',
|
||||
GESHI_REPLACE => '\\0',
|
||||
GESHI_MODIFIERS => 'm',
|
||||
GESHI_BEFORE => '',
|
||||
GESHI_AFTER => ''
|
||||
),
|
||||
//Removed line
|
||||
7 => array(
|
||||
GESHI_SEARCH => '(^|(?<=\A\s))\\-.*$',
|
||||
GESHI_REPLACE => '\\0',
|
||||
GESHI_MODIFIERS => 'm',
|
||||
GESHI_BEFORE => '',
|
||||
GESHI_AFTER => ''
|
||||
),
|
||||
//Inserted line
|
||||
8 => array(
|
||||
GESHI_SEARCH => '(^|(?<=\A\s))\\+.*$',
|
||||
GESHI_REPLACE => '\\0',
|
||||
GESHI_MODIFIERS => 'm',
|
||||
GESHI_BEFORE => '',
|
||||
GESHI_AFTER => ''
|
||||
),
|
||||
//File specification
|
||||
9 => array(
|
||||
GESHI_SEARCH => '(^|(?<=\A\s))(\\*){3}\\s.*$',
|
||||
GESHI_REPLACE => '\\0',
|
||||
GESHI_MODIFIERS => 'm',
|
||||
GESHI_BEFORE => '',
|
||||
GESHI_AFTER => ''
|
||||
),
|
||||
),
|
||||
'STRICT_MODE_APPLIES' => GESHI_NEVER,
|
||||
'SCRIPT_DELIMITERS' => array(
|
||||
),
|
||||
'HIGHLIGHT_STRICT_BLOCK' => array(
|
||||
)
|
||||
);
|
||||
@@ -314,7 +314,7 @@ if (device_permitted($vars['device']) || $check_device == $vars['device']) {
|
||||
</li>';
|
||||
}
|
||||
|
||||
if ($_SESSION['userlevel'] >= '7') {
|
||||
if (is_admin()) {
|
||||
if (!is_array($config['rancid_configs'])) {
|
||||
$config['rancid_configs'] = array($config['rancid_configs']);
|
||||
}
|
||||
@@ -405,7 +405,7 @@ if (device_permitted($vars['device']) || $check_device == $vars['device']) {
|
||||
<li><a href="https://'.$device['hostname'].'"><img src="images/16/http.png" alt="https" title="Launch browser to https://'.$device['hostname'].'" border="0" width="16" height="16" target="_blank"> Launch</a></li>
|
||||
<li><a href="ssh://'.$device['hostname'].'"><img src="images/16/ssh.png" alt="ssh" title="SSH to '.$device['hostname'].'" border="0" width="16" height="16"> SSH</a></li>
|
||||
<li><a href="telnet://'.$device['hostname'].'"><img src="images/16/telnet.png" alt="telnet" title="Telnet to '.$device['hostname'].'" border="0" width="16" height="16"> Telnet</a></li>';
|
||||
if ($_SESSION['userlevel'] >= '7') {
|
||||
if (is_admin()) {
|
||||
echo '<li>
|
||||
<a href="'.generate_device_url($device, array('tab' => 'edit')).'">
|
||||
<img src="images/16/wrench.png" align="absmiddle" border="0" />
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
require 'includes/geshi/geshi.php';
|
||||
|
||||
// FIXME svn stuff still using optc etc, won't work, needs updating!
|
||||
if ($_SESSION['userlevel'] >= '7') {
|
||||
if (is_admin()) {
|
||||
if (!is_array($config['rancid_configs'])) {
|
||||
$config['rancid_configs'] = array($config['rancid_configs']);
|
||||
}
|
||||
@@ -103,19 +103,68 @@ if ($_SESSION['userlevel'] >= '7') {
|
||||
}
|
||||
}
|
||||
else if ($config['oxidized']['enabled'] === true && isset($config['oxidized']['url'])) {
|
||||
// fetch info about the node and then a list of versions for that node
|
||||
$node_info = json_decode(file_get_contents($config['oxidized']['url'].'/node/show/'.$device['hostname'].'?format=json'), true);
|
||||
if ($config['oxidized']['features']['versioning'] === true && isset($_POST['config'])) {
|
||||
list($oid,$date,$version) = explode('|',mres($_POST['config']));
|
||||
$text = file_get_contents($config['oxidized']['url'].'/node/version/view?node='.$device['hostname'].'&group='.(!empty($node_info['group']) ? $node_info['group'] : '').'&oid='.$oid.'&date='.urlencode($date).'&num='.$version.'&format=text');
|
||||
}
|
||||
else {
|
||||
$text = file_get_contents($config['oxidized']['url'].'/node/fetch/'.(!empty($node_info['group']) ? $node_info['group'].'/' : '').$device['hostname']);
|
||||
}
|
||||
if ($config['oxidized']['features']['versioning'] === true) {
|
||||
$config_versions = json_decode(file_get_contents($config['oxidized']['url'].'/node/version?node_full='.(!empty($node_info['group']) ? $node_info['group'].'/' : '').$device['hostname'].'&format=json'), true);
|
||||
if ($config['oxidized']['features']['versioning'] === true) { // fetch a list of versions
|
||||
$config_versions = json_decode(file_get_contents($config['oxidized']['url'].'/node/version?node_full='.(isset($node_info['full_name']) ? $node_info['full_name'] : $device['hostname']).'&format=json'), true);
|
||||
}
|
||||
|
||||
if (is_array($node_info) || is_array($config_versions)) {
|
||||
$config_total = 1;
|
||||
if (is_array($config_versions)) {
|
||||
$config_total = count($config_versions);
|
||||
}
|
||||
|
||||
if ($config_total > 1) {
|
||||
// populate current_version
|
||||
if (isset($_POST['config'])) {
|
||||
list($oid,$date,$version) = explode('|',mres($_POST['config']));
|
||||
$current_config = array('oid'=>$oid, 'date'=>$date, 'version'=>$version);
|
||||
}
|
||||
else { // no version selected
|
||||
$current_config = array('oid'=>$config_versions[0]['oid'], 'date'=>$current_config[0]['date'], 'version'=>$config_total);
|
||||
}
|
||||
|
||||
// populate previous_version
|
||||
if (isset($_POST['diff'])) { // diff requested
|
||||
list($oid,$date,$version) = explode('|',mres($_POST['prevconfig']));
|
||||
if (isset($oid) && $oid != $current_config['oid']) {
|
||||
$previous_config = array('oid'=>$oid, 'date'=>$date, 'version'=>$version);
|
||||
}
|
||||
else if ($current_config['version'] != 1) { // assume previous, unless current is first config
|
||||
foreach ($config_versions as $key => $version) {
|
||||
if ($version['oid'] == $current_config['oid']) {
|
||||
$prev_key = $key + 1;
|
||||
$previous_config['oid'] = $config_versions[$prev_key]['oid'];
|
||||
$previous_config['date'] = $config_versions[$prev_key]['date'];
|
||||
$previous_config['version'] = $config_total - $prev_key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
print_error('No previous version, please select a different version.');
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($previous_config)) {
|
||||
$url = $config['oxidized']['url'].'/node/version/diffs?node='.$device['hostname'].'&group=';
|
||||
if (!empty($node_info['group'])) {
|
||||
$url .= $node_info['group'];
|
||||
}
|
||||
$url .= '&oid='.$current_config['oid'].'&date='.urlencode($current_config['date']).'&num='.$current_config['version'].'&oid2='.$previous_config['oid'].'&format=text';
|
||||
|
||||
$text = file_get_contents($url); // fetch diff
|
||||
} else {
|
||||
// fetch current_version
|
||||
$text = file_get_contents($config['oxidized']['url'].'/node/version/view?node='.$device['hostname'].'&group='.(!empty($node_info['group']) ? $node_info['group'] : '').'&oid='.$current_config['oid'].'&date='.urlencode($current_config['date']).'&num='.$current_config['version'].'&format=text');
|
||||
}
|
||||
}
|
||||
else { // just fetch the only version
|
||||
$text = file_get_contents($config['oxidized']['url'].'/node/fetch/'.(!empty($node_info['group']) ? $node_info['group'].'/' : '').$device['hostname']);
|
||||
|
||||
}
|
||||
|
||||
if (is_array($node_info) || $config_total > 1) {
|
||||
echo '<br />
|
||||
<div class="row">
|
||||
';
|
||||
@@ -136,7 +185,7 @@ if ($_SESSION['userlevel'] >= '7') {
|
||||
';
|
||||
}
|
||||
|
||||
if (is_array($config_versions)) {
|
||||
if ($config_total > 1) {
|
||||
echo '
|
||||
<div class="col-sm-8">
|
||||
<form class="form-horizontal" action="" method="post">
|
||||
@@ -144,13 +193,27 @@ if ($_SESSION['userlevel'] >= '7') {
|
||||
<label for="config" class="col-sm-2 control-label">Config version</label>
|
||||
<div class="col-sm-6">
|
||||
<select id="config" name="config" class="form-control">
|
||||
<option value="">Select version</option>
|
||||
';
|
||||
|
||||
$config_total = count($config_versions);
|
||||
$i = $config_total;
|
||||
foreach ($config_versions as $version) {
|
||||
echo '<option value="'.$version['oid'].'|'.$version['date'].'|'.$config_total.'">'.$config_total.' :: '.$version['date'].' - '.$version['message'].'</option>';
|
||||
$config_total--;
|
||||
echo '<option value="'.$version['oid'].'|'.$version['date'].'|'.$config_total.'" ';
|
||||
if ($current_config['oid'] == $version['oid']) {
|
||||
if (isset($previous_config)) {
|
||||
echo 'selected>+';
|
||||
}
|
||||
else {
|
||||
echo 'selected>*';
|
||||
}
|
||||
}
|
||||
else if ($previous_config['oid'] == $version['oid']) {
|
||||
echo '> -';
|
||||
}
|
||||
else {
|
||||
echo '> ';
|
||||
}
|
||||
echo $i.' :: '.$version['date'].'</option>';
|
||||
$i--;
|
||||
}
|
||||
|
||||
echo '
|
||||
@@ -159,7 +222,11 @@ if ($_SESSION['userlevel'] >= '7') {
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-6">
|
||||
<button type="submit" class="btn btn-primary btn-sm">Show version</button>
|
||||
<input type="hidden" name="prevconfig" value="';
|
||||
echo implode('|',$current_config);
|
||||
echo '">
|
||||
<button type="submit" class="btn btn-primary btn-sm" name="show">Show version</button>
|
||||
<button type="submit" class="btn btn-primary btn-sm" name="diff">Show diff</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@@ -177,8 +244,12 @@ if ($_SESSION['userlevel'] >= '7') {
|
||||
}//end if
|
||||
|
||||
if (!empty($text)) {
|
||||
$language = 'ios';
|
||||
$geshi = new GeSHi($text, $language);
|
||||
if (isset($previous_config)) {
|
||||
$language = 'diff';
|
||||
} else {
|
||||
$language = 'ios';
|
||||
}
|
||||
$geshi = new GeSHi($text, $language);
|
||||
$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
|
||||
$geshi->set_overall_style('color: black;');
|
||||
// $geshi->set_line_style('color: #999999');
|
||||
|
||||
Reference in New Issue
Block a user