support netdisco-rancid-export GROUP config

This commit is contained in:
Oliver Gorwits
2014-03-04 21:09:54 +00:00
parent a7cbc443c6
commit eeb5705fbc
3 changed files with 66 additions and 16 deletions

View File

@@ -1,3 +1,8 @@
2.002000 - 2014-02-04
* Support for netdisco-rancid-export config for GROUP name
* Change to use location and open_in_same_window
2.001000 - 2013-12-08
* Initial release

View File

@@ -1,9 +1,11 @@
package App::NetdiscoX::Web::Plugin::RANCID;
our $VERSION = '2.001001';
our $VERSION = '2.002000';
use Dancer ':syntax';
use App::Netdisco::Web::Plugin;
use App::Netdisco::Util::Permission 'check_acl';
use File::ShareDir 'dist_dir';
register_template_path(
@@ -15,6 +17,34 @@ register_device_details({
default => 'on',
});
hook 'before_template' => sub {
return unless
index(request->path, uri_for('/ajax/content/device/details')->path) == 0;
my $config = config;
my $tokens = shift;
my $device = $tokens->{d};
# defaults
$tokens->{rancidgroup} = '';
$tokens->{ranciddevice} = ($device->{dns} || $device->{name} || $device->{ip});
return unless exists $config->{rancid};
my $rancid = $config->{rancid};
$rancid->{groups} ||= {};
$rancid->{by_ip} ||= [];
foreach my $g (keys %{ $rancid->{groups} }) {
if (check_acl( $d, $rancid->{groups}->{$g} )) {
$tokens->{rancidgroup} = $g;
$tokens->{ranciddevice} = $device->{ip}
if 0 < scalar grep {$_ eq $g} @{ $rancid->{by_ip} };
last;
}
}
};
=head1 NAME
App::NetdiscoX::Web::Plugin::RANCID - Link to device backups in RANCID/WebSVN
@@ -27,8 +57,8 @@ App::NetdiscoX::Web::Plugin::RANCID - Link to device backups in RANCID/WebSVN
- X::RANCID
plugin_rancid:
location: 'websvn-server.example.com/rancid'
open_in_new_window: true
location: 'https://websvn-server.example.com/rancid/%GROUP%/'
open_in_same_window: false
=head1 Description
@@ -49,18 +79,34 @@ Value: String, Required.
Name of the server hosting your local WebSVN installation. This should
also include the path under which backup files are stored for the devices.
=head2 open_in_new_window
B<Note that "configs/" will be added to the end of the location for you.>
The text "C<%GROUP%>" will be replaced with the group name for this device, if
known to Netdisco. This uses the same configuration as for
L<netdisco-rancid-export>, an example of which is below:
rancid:
by_ip: [ other ]
groups:
switch: [ 'name:.*[Ss][Ww].*' ]
rtr: [ 'name:[rR]tr.*' ]
ap: [ 'name:[aA][pP].*' ]
Briefly, each group value is a list of rules for matching devices similar to
those used by any C<*_only> configuration item. You can provide an IP, subnet
or prefix, regular expression to match a device name, or device attribute and
regular expression as in the above example.
The device DNS name is used, or if missing the device SNMP sysName. Adding the
group to the list in C<by_ip> will make the link include the device IP
instead.
=head2 open_in_same_window
Value: Boolean. Default: false.
If set to true, the hyperlink is configured to open the WebSVN page in a new
browser window or tab.
=head1 TODO
At the moment the device name is used in the link. This is kind of useless
for most installations. Needs config to control how to specify device in
generated link.
If set to true, the hyperlink is configured to open the WebSVN page in the
same browser window or tab as Netdisco.
=head1 AUTHOR

View File

@@ -1,4 +1,3 @@
<a href="http://[% settings.plugin_rancid.location | url %]/[% device.dns || device.name | uri %]"
[% ' target="_blank"' IF settings.plugin_rancid.open_in_new_window %]
class="btn"
>View Configuration</a>
<a href="[% settings.plugin_rancid.location.replace('\%GROUP\%',rancidgroup) %]/configs/[% ranciddevice | uri %]"
[% ' target="_blank"' UNLESS settings.plugin_rancid.open_in_same_window %]
>View Configuration <i class="icon-circle-arrow-right"></i></a>