support netdisco-rancid-export GROUP config
This commit is contained in:
@@ -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
|
2.001000 - 2013-12-08
|
||||||
|
|
||||||
* Initial release
|
* Initial release
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package App::NetdiscoX::Web::Plugin::RANCID;
|
package App::NetdiscoX::Web::Plugin::RANCID;
|
||||||
|
|
||||||
our $VERSION = '2.001001';
|
our $VERSION = '2.002000';
|
||||||
|
|
||||||
use Dancer ':syntax';
|
use Dancer ':syntax';
|
||||||
|
|
||||||
use App::Netdisco::Web::Plugin;
|
use App::Netdisco::Web::Plugin;
|
||||||
|
use App::Netdisco::Util::Permission 'check_acl';
|
||||||
|
|
||||||
use File::ShareDir 'dist_dir';
|
use File::ShareDir 'dist_dir';
|
||||||
register_template_path(
|
register_template_path(
|
||||||
@@ -15,6 +17,34 @@ register_device_details({
|
|||||||
default => 'on',
|
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
|
=head1 NAME
|
||||||
|
|
||||||
App::NetdiscoX::Web::Plugin::RANCID - Link to device backups in RANCID/WebSVN
|
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
|
- X::RANCID
|
||||||
|
|
||||||
plugin_rancid:
|
plugin_rancid:
|
||||||
location: 'websvn-server.example.com/rancid'
|
location: 'https://websvn-server.example.com/rancid/%GROUP%/'
|
||||||
open_in_new_window: true
|
open_in_same_window: false
|
||||||
|
|
||||||
=head1 Description
|
=head1 Description
|
||||||
|
|
||||||
@@ -49,18 +79,34 @@ Value: String, Required.
|
|||||||
Name of the server hosting your local WebSVN installation. This should
|
Name of the server hosting your local WebSVN installation. This should
|
||||||
also include the path under which backup files are stored for the devices.
|
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.
|
Value: Boolean. Default: false.
|
||||||
|
|
||||||
If set to true, the hyperlink is configured to open the WebSVN page in a new
|
If set to true, the hyperlink is configured to open the WebSVN page in the
|
||||||
browser window or tab.
|
same browser window or tab as Netdisco.
|
||||||
|
|
||||||
=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.
|
|
||||||
|
|
||||||
=head1 AUTHOR
|
=head1 AUTHOR
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
<a href="http://[% settings.plugin_rancid.location | url %]/[% device.dns || device.name | uri %]"
|
<a href="[% settings.plugin_rancid.location.replace('\%GROUP\%',rancidgroup) %]/configs/[% ranciddevice | uri %]"
|
||||||
[% ' target="_blank"' IF settings.plugin_rancid.open_in_new_window %]
|
[% ' target="_blank"' UNLESS settings.plugin_rancid.open_in_same_window %]
|
||||||
class="btn"
|
>View Configuration <i class="icon-circle-arrow-right"></i></a>
|
||||||
>View Configuration</a>
|
|
||||||
|
|||||||
Reference in New Issue
Block a user