Skip to content

Commit c7934c6

Browse files
authored
Support bare Git repository of RANCID (librenms#18541)
* Support bare Git repository of RANCID * Update the documentation * Null rancid_repo_url does not preclude reading directly from bare Git repository
1 parent b08151a commit c7934c6

File tree

6 files changed

+204
-104
lines changed

6 files changed

+204
-104
lines changed

app/Http/Controllers/Device/Tabs/ShowConfigController.php

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use App\Models\Device;
3333
use Illuminate\Http\Request;
3434
use LibreNMS\Interfaces\UI\DeviceTab;
35+
use Symfony\Component\Process\Process;
3536

3637
class ShowConfigController extends Controller implements DeviceTab
3738
{
@@ -106,24 +107,57 @@ private function findRancidConfigFile()
106107
if (LibrenmsConfig::has('rancid_configs.0')) {
107108
$device = DeviceCache::getPrimary();
108109
foreach (LibrenmsConfig::get('rancid_configs') as $configs) {
109-
if ($configs[strlen($configs) - 1] != '/') {
110-
$configs .= '/';
111-
}
110+
if (LibrenmsConfig::get('rancid_repo_type') == 'git-bare') {
111+
$topLevel = strpos($configs, '.git');
112+
$configPath = '';
113+
if ($topLevel === false) {
114+
if (is_dir($configs . '.git')) {
115+
$configs .= '.git';
116+
} else {
117+
return false;
118+
}
119+
} else {
120+
$configPath = substr($configs, $topLevel + 5);
121+
$configs = substr($configs, 0, $topLevel + 4);
122+
}
123+
if (strlen($configPath) > 0 && $configPath[strlen($configPath) - 1] != '/') {
124+
$configPath .= '/';
125+
}
126+
$process = new Process(['git', 'ls-tree', '--name-only', '-r', 'HEAD'], $configs);
127+
$process->run();
128+
$config_files = explode(PHP_EOL, $process->getOutput());
129+
if (count($config_files) > 0) {
130+
$this->rancidPath = $configs;
131+
}
132+
if (in_array($configPath . $device['hostname'], $config_files)) {
133+
return $configPath . $device['hostname'];
134+
}
135+
if (in_array($configPath . strtok($device['hostname'], '.'), $config_files)) {
136+
return $configPath . strtok($device['hostname'], '.');
137+
}
138+
if (! empty(LibrenmsConfig::get('mydomain')) && in_array($configPath . $device['hostname'] . '.' . LibrenmsConfig::get('mydomain'), $config_files)) {
139+
return $configPath . $device['hostname'] . '.' . LibrenmsConfig::get('mydomain');
140+
}
141+
} else {
142+
if ($configs[strlen($configs) - 1] != '/') {
143+
$configs .= '/';
144+
}
112145

113-
if (is_file($configs . $device['hostname'])) {
114-
$this->rancidPath = $configs;
146+
if (is_file($configs . $device['hostname'])) {
147+
$this->rancidPath = $configs;
115148

116-
return $configs . $device['hostname'];
117-
} elseif (is_file($configs . strtok($device['hostname'], '.'))) { // Strip domain
118-
$this->rancidPath = $configs;
149+
return $configs . $device['hostname'];
150+
} elseif (is_file($configs . strtok($device['hostname'], '.'))) { // Strip domain
151+
$this->rancidPath = $configs;
119152

120-
return $configs . strtok($device['hostname'], '.');
121-
} else {
122-
if (! empty(LibrenmsConfig::get('mydomain'))) { // Try with domain name if set
123-
if (is_file($configs . $device['hostname'] . '.' . LibrenmsConfig::get('mydomain'))) {
124-
$this->rancidPath = $configs;
153+
return $configs . strtok($device['hostname'], '.');
154+
} else {
155+
if (! empty(LibrenmsConfig::get('mydomain'))) { // Try with domain name if set
156+
if (is_file($configs . $device['hostname'] . '.' . LibrenmsConfig::get('mydomain'))) {
157+
$this->rancidPath = $configs;
125158

126-
return $configs . $device['hostname'] . '.' . LibrenmsConfig::get('mydomain');
159+
return $configs . $device['hostname'] . '.' . LibrenmsConfig::get('mydomain');
160+
}
127161
}
128162
}
129163
}

doc/Extensions/Rancid.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,25 @@ $config['rancid_ignorecomments'] = 0;
3030

3131
After that, you should see some "config" tab on routers that have a rancid update.
3232

33+
## Rancid Bare Git Repository
34+
35+
Rancid has capability to version the configuration files in Git, and it can push
36+
the commits to a remote repository which is bare, that is it lacks a
37+
worktree. GitWeb is a simple web frontend that visualizes bare
38+
repositories, and can be served by the same HTTP server as LibreNMS.
39+
40+
If the bare repository follows the usual naming conventions, that is, the path to
41+
it looks like `/some/path/rancid.git` (ending in `.git`), the configuration files
42+
are in `configs` directory in Git, and GitWeb is configured under `/repo` on the
43+
same server, then that bare Git repository can be integrated by the following
44+
configuration:
45+
46+
```
47+
$config['rancid_configs'][] = '/some/path/rancid.git/configs';
48+
$config['rancid_repo_type'] = 'git-bare';
49+
$config['rancid_repo_url'] = '/repo';
50+
```
51+
3352
## Ubuntu Rancid Install
3453

3554
The options shown below also contains the default values.
@@ -59,7 +78,7 @@ RCSSYS=svn; export RCSSYS
5978
```
6079

6180
NOTE - This only creates 1 group! You can of course make more when you
62-
get the hang of it, this is just a basic 'Need it to work" deal.
81+
get the hang of it, this is just a basic "Need it to work" deal.
6382

6483
`sudo su -c /var/lib/rancid/bin/rancid-cvs -s /bin/bash -l rancid`
6584
> NOTE - do NOT change cvs to svn here! Leave command as is!
@@ -78,7 +97,7 @@ alphcr1:cisco:up will change to:
7897
alphcr1;cisco;up
7998
```
8099

81-
copy and past results into the below file:
100+
copy and paste results into the below file:
82101
`sudo vi /var/lib/rancid/librenms/router.db`
83102

84103
NOTE - This ONLY applies to newer RANCID versions and Linux
@@ -107,11 +126,11 @@ sudo chmod 600 /var/lib/rancid/.cloginrc
107126
Test config:
108127
`sudo /usr/lib/rancid/bin/clogin -f /var/lib/rancid/.cloginrc <device hostname>`
109128

110-
NOTE: IF you run into a 'diffie-hellmen' kind of error, then it is
129+
NOTE: IF you run into a 'diffie-hellman' kind of error, then it is
111130
because your Linux distro is using newer encryption methods
112131
etc. This is basically just letting you know that the device you
113132
tested on is running an outdated encryption type. I recommend updating
114-
downstream device if able. If not, the following should fix:
133+
downstream device if possible. If not, the following should fix:
115134

116135
`sudo vi /etc/ssh/ssh_config`
117136

doc/Support/Configuration.md

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use some snmp configuration as an example:
4545
`lnms config:get <setting>` will fetch the current config settings (composite of database, config.php, and defaults).
4646
`lnms config:set <setting> <value>` will set the config setting in the database.
4747
Calling `lnms config:set <setting>` on a setting with no value will prompt you to reset
48-
it to it's default.
48+
it to its default.
4949

5050
If you set up bash completion, you can use tab completion to find config settings.
5151

@@ -222,7 +222,7 @@ value is in Megabytes and should just be an int value:
222222
223223
### Programs
224224
225-
A lot of these are self explanatory so no further information may be
225+
A lot of these are self-explanatory so no further information may be
226226
provided. Any extensions that have dedicated documentation page will
227227
be linked to rather than having the config provided.
228228
@@ -263,7 +263,7 @@ configuring your install to record data more frequently.
263263
to each target.
264264
* `interval` (`fping` parameter `-p`): Time in milliseconds that fping
265265
waits between successive packets to an individual target.
266-
* `tos` (`fping`parameter `-O`): Set the type of service flag (TOS). Value can be either decimal or hexadecimal (0xh) format. Can be used to ensure that ping packets are queued in following QOS mecanisms in the network. Table is accessible in the [TOS Wikipedia page](https://en.wikipedia.org/wiki/Type_of_service).
266+
* `tos` (`fping`parameter `-O`): Set the type of service flag (TOS). Value can be either decimal or hexadecimal (0xh) format. Can be used to ensure that ping packets are queued in following QOS mechanisms in the network. Table is accessible in the [TOS Wikipedia page](https://en.wikipedia.org/wiki/Type_of_service).
267267
268268
!!! note
269269
Setting a higher timeout value than the interval value can
@@ -294,7 +294,7 @@ Globally disable fping / icmp check:
294294
lnms config:set icmp_check false
295295
```
296296
297-
If you would like to do this on a per device basis then you can do so
297+
If you would like to do this on a per-device basis then you can do so
298298
under Device -> Edit -> Misc -> Disable ICMP Test? On
299299
300300
#### SNMP
@@ -337,7 +337,7 @@ Password minimum length for auth that allows user creation
337337
338338
## Proxy support
339339
340-
For alerting and the callback functionality, we support the use of a
340+
For alerting and the callback functionality, we support the use of an
341341
http proxy setting. These can be any one of the following:
342342
343343
!!! setting "system/proxy"
@@ -364,14 +364,14 @@ Please refer to [RRDCached](../Extensions/RRDCached.md)
364364
lnms config:set base_url http://demo.librenms.org
365365
```
366366
367-
LibreNMS will attempt to detect the URL you are using but you can override that here.
367+
LibreNMS will attempt to detect the URL you are using, but you can override that here.
368368
369369
!!! setting "webui/style"
370370
```bash
371371
lnms config:set site_style light
372372
```
373373
374-
Currently we have a number of styles which can be set which will alter
374+
Currently, we have a number of styles which can be set which will alter
375375
the navigation bar look. device, blue, dark, light and mono with light being the default.
376376
377377
You can override a large number of visual elements by creating your
@@ -402,7 +402,7 @@ minutes. Some pages don't refresh at all by design.
402402
```
403403
404404
You can create your own front page by adding a blade file in `resources/views/overview/custom/`
405-
and setting `front_page` to it's name.
405+
and setting `front_page` to its name.
406406
For example, if you create `resources/views/overview/custom/foobar.blade.php`, set `front_page` to `foobar`.
407407
408408
!!! setting "webui/front-page"
@@ -584,7 +584,7 @@ generation if this is very long.
584584
```
585585
586586
You can enable dynamic graphs which allow you to zoom in/out and scroll through
587-
the timeline of the graphs quite easiy.
587+
the timeline of the graphs quite easily.
588588
589589
!!! setting "webui/graph"
590590
```bash
@@ -619,7 +619,7 @@ prevents accidental duplicate hosts.
619619
# false- only check when adding host by ip.
620620
```
621621
622-
By default we allow hosts to be added with duplicate sysName's, you
622+
By default, we allow hosts to be added with duplicate sysName's, you
623623
can disable this with the following config:
624624
625625
!!! setting "discovery/general"
@@ -793,7 +793,7 @@ Assign a new discovered Port automatically to Port Group with this Port Group ID
793793
794794
### Rancid
795795
796-
Rancid configuration, `rancid_configs` is an array containing all of
796+
Rancid configuration, `rancid_configs` is an array containing all
797797
the locations of your rancid files. Setting `rancid_ignorecomments`
798798
will disable showing lines that start with #
799799
@@ -804,6 +804,21 @@ will disable showing lines that start with #
804804
lnms config:set rancid_ignorecomments false
805805
```
806806
807+
In case rancid repository is a bare Git repository, it must be stored in a
808+
directory with name ending `.git`. The path to that repository can then be
809+
combined with an additional path to rancid files in Git
810+
811+
!!! setting "external/rancid"
812+
```bash
813+
lnms config:set rancid_configs.+ /var/lib/rancid/git/rancid.git/configs/
814+
lnms config:set rancid_repo_type git-bare
815+
lnms config:set rancid_repo_url /rancid
816+
lnms config:set rancid_ignorecomments false
817+
```
818+
819+
An additional parameter, `rancid_repo_url`, must be set to the URL of GitWeb
820+
or a similar tool that visualizes the bare Git repository.
821+
807822
### Oxidized
808823
809824
Please refer to [Oxidized](../Extensions/Oxidized.md)
@@ -859,7 +874,7 @@ Please refer to [NFSen](../Extensions/NFSen.md)
859874
860875
### Location parsing
861876
862-
LibreNMS can interpret sysLocation information and map the device loction based on GeoCoordinates or GeoCoding information.
877+
LibreNMS can interpret sysLocation information and map the device location based on GeoCoordinates or GeoCoding information.
863878
864879
- Info-keywords
865880
- `[]` contains optional Latitude and Longitude information if manual GeoCoordinate positioning is desired.
@@ -868,7 +883,7 @@ LibreNMS can interpret sysLocation information and map the device loction based
868883
869884
#### GeoCoordinates
870885
871-
If device sysLocation information contains [lat, lng] (note the comma and square brackets), that is used to determin the GeoCoordinates.
886+
If device sysLocation information contains [lat, lng] (note the comma and square brackets), that is used to determine the GeoCoordinates.
872887
873888
Example:
874889
```bash
@@ -882,7 +897,7 @@ The coordinates will then be set to 40.424521 latitude and -86.912755 longitude.
882897
Next it will attempt to look up the sysLocation with a map engine provided you have configured one under
883898
`lnms config:get geoloc.engine`. The information has to be accurate or no result is returned, when it
884899
does it will ignore any information inside parentheses, allowing you to add details that would otherwise
885-
interfeeer with the lookup.
900+
interfere with the lookup.
886901
887902
Example:
888903
```bash
@@ -902,7 +917,7 @@ If you just want to set GPS coordinates on a location, you should
902917
visit Devices > Geo Locations > All Locations and edit the coordinates
903918
there.
904919
905-
However you can replace the sysLocation value that is returned for a single device or many devices.
920+
However, you can replace the sysLocation value that is returned for a single device or many devices.
906921
907922
For example, let's say that you have 100 devices which all contain the sysLocation value of `Under the Sink` which
908923
isn't the real address, rather than editing each device manually, you can specify a mapping to override the sysLocation
@@ -990,11 +1005,11 @@ Examples:
9901005
## Interfaces that shouldn't be ignored
9911006
9921007
It's also possible to whitelist ports so they are not ignored. `good_if` can
993-
be configured both globally and per os just like `bad_if`.
1008+
be configured both globally and per-os just like `bad_if`.
9941009
9951010
As an examples, let's say we have `bad_if_regexp` set to ignore `Ethernet` ports
9961011
but realise that we actually still want `FastEthernet` ports but not any others,
997-
we can add a `good_if` option to white list `FastEthernet`:
1012+
we can add a `good_if` option to whitelist `FastEthernet`:
9981013
9991014
!!! setting "discovery/ports"
10001015
```bash
@@ -1027,7 +1042,7 @@ Matches are compared case-insensitive.
10271042
Some devices register bogus sensors as they are returned via SNMP but
10281043
either don't exist or just don't return data. This allows you to
10291044
ignore those based on the descr field in the database. You can either
1030-
ignore globally or on a per os basis (recommended).
1045+
ignore globally or on a per-os basis (recommended).
10311046
10321047
As an example, if you have some sensors which contain the descriptions
10331048
below:
@@ -1164,10 +1179,10 @@ to indicate how you connect to libvirt. You also need to:
11641179
11651180
1. Generate a non-password-protected ssh key for use by LibreNMS, as the
11661181
user which runs polling & discovery (usually `librenms`).
1167-
1. On each VM host you wish to monitor:
1182+
2. On each VM host you wish to monitor:
11681183
1. Configure public key authentication from your LibreNMS server/poller by
11691184
adding the librenms public key to `~root/.ssh/authorized_keys`.
1170-
1. (xen+ssh only) Enable libvirtd to gather data from xend by setting
1185+
2. (xen+ssh only) Enable libvirtd to gather data from xend by setting
11711186
`(xend-unix-server yes)` in `/etc/xen/xend-config.sxp` and
11721187
restarting xend and libvirtd.
11731188
@@ -1196,7 +1211,7 @@ Please refer to [Updating](../General/Updating.md)
11961211
11971212
## IPMI
11981213
1199-
Setup the types of IPMI protocols to test a host for and in what
1214+
Set up the types of IPMI protocols to test a host for and in what
12001215
order. Don't forget to install ipmitool on the monitoring host.
12011216
12021217
!!! setting "discovery/ipmi"

includes/html/pages/device/showconfig.inc.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,27 @@
55
use Symfony\Component\Process\Process;
66

77
if (Auth::user()->hasGlobalAdmin()) {
8-
if (! empty($rancid_file)) {
8+
if (LibrenmsConfig::get('rancid_repo_type') == 'git-bare' && is_dir($rancid_path)) {
9+
echo '<div style="clear: both;">';
10+
11+
print_optionbar_start('', '');
12+
echo is_null(LibrenmsConfig::get('rancid_repo_url')) ? 'Git repository non-browsable'
13+
: '<a href="' . LibrenmsConfig::get('rancid_repo_url') . '/?a=blob;hb=HEAD;p=' . basename((string) $rancid_path) . ';f=' . $rancid_file . '">Git repository</a>';
14+
print_optionbar_end();
15+
16+
$process = new Process(['git', 'ls-tree', '-r', 'HEAD'], $rancid_path);
17+
$process->run();
18+
$full_tree = explode(PHP_EOL, $process->getOutput());
19+
foreach ($full_tree as $ft) {
20+
[$perm, $type, $hash_path] = explode(' ', $ft, 3);
21+
[$hash, $file] = explode("\t", $hash_path);
22+
if (strcmp($file, (string) $rancid_file) === 0) {
23+
$process = new Process(['git', 'cat-file', $type, $hash], $rancid_path);
24+
$process->run();
25+
$text = $process->getOutput();
26+
}
27+
}
28+
} elseif (! empty($rancid_file)) {
929
echo '<div style="clear: both;">';
1030

1131
print_optionbar_start('', '');

lang/en/settings.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,6 +1908,10 @@
19081908
'description' => 'RANCID Repository Type',
19091909
'help' => 'Type of repository used by RANCID, used to display config diffs on device pages',
19101910
],
1911+
'rancid_repo_url' => [
1912+
'description' => 'RANCID Repository URL',
1913+
'help' => 'RANCID repository URL, used to point at GitWeb that visualizes a bare Git repository',
1914+
],
19111915
'rancid_ignorecomments' => [
19121916
'description' => 'RANCID Ignore Comments',
19131917
'help' => 'Ignore comments when comparing RANCID configs, used to display config diffs on device pages',

0 commit comments

Comments
 (0)