feature: Rancid config file generator (#5689)

This commit is contained in:
Xavier Beaudouin
2017-02-02 16:44:15 +01:00
committed by Neil Lathwood
parent 9f8f8b6c26
commit cb5dd299af
2 changed files with 85 additions and 0 deletions

30
doc/Extensions/Rancid.md Normal file
View File

@@ -0,0 +1,30 @@
source: Extensions/Rancid.md
# Rancid integration
Librenms can generate a list of hosts that can be monitored by RANCID.
We assume you have currently a running Rancid, and you just need to create and update the file 'router.db'
### Included Rancid script
To generate the config file (maybe even add a cron to schedule this). We've assumed a few locations for Rancid, the config file you want to call it and where LibreNMS is:
```bash
cd /opt/librenms/scripts/
php ./gen_rancid.php > /the/path/where/is/rancid/core/router.db
```
Sample cron:
```bash
15 0 * * * root cd /opt/librenms/scripts && php ./gen_rancid.php > /the/path/where/is/rancid/core/router.db
```
Now configure LibreNMS (make sure you point dir to your rancid data directory):
```php
$config['rancid_configs']['core'] = '/the/path/where/is/rancid/core';
$config['rancid_ignorecomments'] = 0;
```
After that, you should see some "config" tab on routers that have a rancid update.

55
scripts/gen_rancid.php Executable file
View File

@@ -0,0 +1,55 @@
#!/usr/bin/env php
<?php
/*
* LibreNMS
*
* Copyright (c) 2017 Xavier Beaudouin <kiwi@oav.net>
* This program 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 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
$init_modules = array();
require realpath(__DIR__ . '/..') . '/includes/init.php';
?>
# RANCID router.db autogenerated by LibreNMS
# Do not edit this file manualy
<?php
/*
* Rancid real OS to rancid OS map.
* Maybe we can add this somewhere?
*/
$rancid_map['arista'] = 'arista';
$rancid_map['asa'] = 'cisco';
$rancid_map['avocent'] = 'avocent';
$rancid_map['edgeos'] = 'edgerouter';
$rancid_map['f5'] = 'f5';
$rancid_map['fortigate']= 'fortigate';
$rancid_map['ftos'] = 'force10';
$rancid_map['ios'] = 'cisco';
$rancid_map['iosxe'] = 'cisco';
$rancid_map['iosxr'] = 'cisco-xr';
$rancid_map['ironware'] = 'foundry';
$rancid_map['junos'] = 'juniper';
$rancid_map['pfsense'] = 'pfsense';
$rancid_map['procurve'] = 'hp';
$rancid_map['nxos'] = 'cisco-nx';
$rancid_map['mikrotik'] = 'mikrotik';
$rancid_map['screenos'] = 'netscreen';
foreach (dbFetchRows("SELECT `hostname`,`os`,`disabled`,`status` FROM `devices` WHERE `ignore` = 0 AND `type` != '' GROUP BY `hostname`") as $devices) {
if (isset($rancid_map[$devices['os']])) {
$status = "up";
if ($devices['disabled']) {
$status = "down";
}
echo $devices['hostname'] . ':' . $rancid_map[$devices['os']] . ':' . $status . PHP_EOL;
}
}
echo "# EOF " . PHP_EOL;