new version of core plugin manager with better config and filters
This commit is contained in:
@@ -12,45 +12,46 @@ Dancer::Factory::Hook->instance->install_hooks(
|
|||||||
@{ setting('core_phases') }
|
@{ setting('core_phases') }
|
||||||
);
|
);
|
||||||
|
|
||||||
# cache hints for working through phases
|
register 'register_core_driver' => sub {
|
||||||
set(
|
my ($self, $args, $code) = @_;
|
||||||
map {("_phase_before_$_" => {}, "_phase_$_" => {}, "_phase_after_$_" => {})}
|
return error "bad param to register_core_driver"
|
||||||
@{ setting('core_phases') },
|
unless (ref sub {} eq ref $code) and (ref {} eq ref $args)
|
||||||
# TODO: store in here (caller)[0] => $args
|
and exists $args->{phase} and exists $args->{driver}
|
||||||
);
|
and Dancer::Factory::Hook->instance->hook_is_registered($args->{phase});
|
||||||
|
|
||||||
register 'register_core_action' => sub {
|
my $no = (exists $args->{no} ? $args->{no} : undef);
|
||||||
my ($self, $code, $args) = @_;
|
my $only = (exists $args->{only} ? $args->{only} : undef);
|
||||||
return error "bad param to register_core_action"
|
$args->{plugin} = (caller)[0];
|
||||||
unless ref sub {} eq ref $code and ref {} eq ref $args
|
|
||||||
and exists $args->{action}
|
|
||||||
and Dancer::Factory::Hook->instance->hook_is_registered($args->{action});
|
|
||||||
|
|
||||||
my $no = $args->{no};
|
|
||||||
my $only = $args->{only};
|
|
||||||
my $store = Dancer::Factory::Hook->instance;
|
|
||||||
|
|
||||||
my $hook = sub {
|
my $hook = sub {
|
||||||
my $device = shift or return -1;
|
my ($device, $userconf) = @_;
|
||||||
return 0 if ($no and check_acl_no($device, $no))
|
return false unless (ref $device and (ref {} eq ref $userconf));
|
||||||
or ($only and not check_acl_only($device, $only));
|
|
||||||
|
# first check internal (args) exclusion/inclusion criteria
|
||||||
|
return false if ($no and check_acl_no($device, $no));
|
||||||
|
return false if ($only and not (exists $userconf->{driver})
|
||||||
|
and not check_acl_only($device, $only));
|
||||||
|
|
||||||
|
# then check external (userconf) exclusion/inclusion criteria
|
||||||
|
return false if exists $userconf->{phase}
|
||||||
|
and (($userconf->{phase} || '') ne $args->{phase});
|
||||||
|
|
||||||
|
return false if exists $userconf->{driver}
|
||||||
|
and (($userconf->{driver} || '') ne $args->{driver});
|
||||||
|
|
||||||
|
return false if exists $userconf->{plugin}
|
||||||
|
and (($userconf->{plugin} || '') ne $args->{plugin});
|
||||||
|
|
||||||
my $happy = false;
|
my $happy = false;
|
||||||
try {
|
try {
|
||||||
$code->($args);
|
$code->($device, $args, $userconf);
|
||||||
$happy = true;
|
$happy = true;
|
||||||
};
|
}
|
||||||
|
catch { debug $_ };
|
||||||
return ($happy ? ($args->{final} ? 1 : 0) : -1);
|
return $happy;
|
||||||
};
|
};
|
||||||
|
|
||||||
# NOTE: using Dancer::Factory::Hook internals
|
Dancer::Factory::Hook->instance->register_hook($args->{phase}, $hook);
|
||||||
if ($args->{final} and $args->{action} !~ m/^(?:before|after)_/) {
|
|
||||||
unshift @{$store->hooks->{ $args->{action} }}, $hook;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
push @{$store->hooks->{ $args->{action} }}, $hook;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
register_plugin;
|
register_plugin;
|
||||||
@@ -58,103 +59,66 @@ true;
|
|||||||
|
|
||||||
=head1 NAME
|
=head1 NAME
|
||||||
|
|
||||||
App::Netdisco::Web::Plugin - Netdisco Web UI components
|
App::Netdisco::Core::Plugin - Netdisco Backend Drivers
|
||||||
|
|
||||||
=head1 Introduction
|
=head1 Introduction
|
||||||
|
|
||||||
L<App::Netdisco>'s plugin system allows you more control of what Netdisco
|
L<App::Netdisco>'s plugin system allows users to create backend I<drivers>
|
||||||
components are displayed in the web interface. Plugins can be distributed
|
which use different I<transports> to gather information from network devices
|
||||||
independently from Netdisco and are a better alternative to source code
|
and store in the database.
|
||||||
patches.
|
|
||||||
|
|
||||||
The following web interface components are implemented as plugins:
|
For example, transports might be SNMP, SSH, or HTTPS. Drivers might be
|
||||||
|
combining those transports with application protocols such as SNMP, NETCONF
|
||||||
|
(OpenConfig with XML), RESTCONF (OpenConfig with JSON), eAPI, or even CLI
|
||||||
|
scraping.
|
||||||
|
|
||||||
=over 4
|
Drivers can be restricted to certain vendor platforms using familiar ACL
|
||||||
|
syntax. They are also attached to specific phases in Netdisco's backend
|
||||||
=item *
|
operation.
|
||||||
|
|
||||||
Navigation Bar items (e.g. Inventory link)
|
|
||||||
|
|
||||||
=item *
|
|
||||||
|
|
||||||
Tabs for Search and Device pages
|
|
||||||
|
|
||||||
=item *
|
|
||||||
|
|
||||||
Reports (pre-canned searches)
|
|
||||||
|
|
||||||
=item *
|
|
||||||
|
|
||||||
Additional Device Port Columns
|
|
||||||
|
|
||||||
=item *
|
|
||||||
|
|
||||||
Additional Device Details
|
|
||||||
|
|
||||||
=item *
|
|
||||||
|
|
||||||
Admin Menu function (job control, manual topology, pseudo devices)
|
|
||||||
|
|
||||||
=back
|
|
||||||
|
|
||||||
This document explains how to configure which plugins are loaded. See
|
|
||||||
L<App::Netdisco::Manual::WritingPlugins> if you want to develop new plugins.
|
|
||||||
|
|
||||||
=head1 Application Configuration
|
=head1 Application Configuration
|
||||||
|
|
||||||
Netdisco configuration supports a C<web_plugins> directive along with the
|
The C<collector_plugins> and C<extra_collector_plugins> settings list in YAML
|
||||||
similar C<extra_web_plugins>. These list, in YAML format, the set of Perl
|
format the set of Perl module names which are the plugins to be loaded.
|
||||||
module names which are the plugins to be loaded. Each item injects one part of
|
|
||||||
the Netdisco web user interface.
|
|
||||||
|
|
||||||
You can override these settings to add, change, or remove entries from the
|
|
||||||
default lists. Here is an example of the C<web_plugins> list:
|
|
||||||
|
|
||||||
web_plugins:
|
|
||||||
- Inventory
|
|
||||||
- Report::DuplexMismatch
|
|
||||||
- Search::Device
|
|
||||||
- Search::Node
|
|
||||||
- Search::Port
|
|
||||||
- Device::Details
|
|
||||||
- Device::Ports
|
|
||||||
|
|
||||||
Any change should go into your local C<deployment.yml> configuration file. If
|
Any change should go into your local C<deployment.yml> configuration file. If
|
||||||
you want to view the default settings, see the C<share/config.yml> file in the
|
you want to view the default settings, see the C<share/config.yml> file in the
|
||||||
C<App::Netdisco> distribution.
|
C<App::Netdisco> distribution.
|
||||||
|
|
||||||
|
Driver phases are in the C<core_phases> setting and for a given backend
|
||||||
|
action, the registered drivers at one or more phases will be executed if they
|
||||||
|
apply to the target device. Each phase ("X") also gets a C<before_X> and
|
||||||
|
C<after_X> phase added for preparatory or optional work, respectively.
|
||||||
|
|
||||||
=head1 How to Configure
|
=head1 How to Configure
|
||||||
|
|
||||||
The C<extra_web_plugins> setting is empty, and used only if you want to add
|
The C<extra_collector_plugins> setting is empty, and used only if you want to
|
||||||
new plugins but not change the set enabled by default. If you do want to add
|
add new plugins but not change the set enabled by default. If you do want to
|
||||||
to or remove from the default set, then create a version of C<web_plugins>
|
add to or remove from the default set, then create a version of
|
||||||
instead.
|
C<collector_plugins> instead.
|
||||||
|
|
||||||
Netdisco prepends "C<App::Netdisco::Web::Plugin::>" to any entry in the list.
|
Netdisco prepends "C<App::Netdisco::Core::Plugin::>" to any entry in the list.
|
||||||
For example, "C<Inventory>" will load the
|
For example, "C<Discover::WirelessServices::UniFi>" will load the
|
||||||
C<App::Netdisco::Web::Plugin::Inventory> module.
|
C<App::Netdisco::Core::Plugin::Discover::WirelessServices::UniFi> package.
|
||||||
|
|
||||||
Such plugin modules can either ship with the App::Netdisco distribution
|
|
||||||
itself, or be installed separately. Perl uses the standard C<@INC> path
|
|
||||||
searching mechanism to load the plugin modules.
|
|
||||||
|
|
||||||
If an entry in the list starts with a "C<+>" (plus) sign then Netdisco attemps
|
If an entry in the list starts with a "C<+>" (plus) sign then Netdisco attemps
|
||||||
to load the module as-is, without prepending anything to the name. This allows
|
to load the module as-is, without prepending anything to the name. This allows
|
||||||
you to have App::Netdiso web UI plugins in other namespaces:
|
you to have App::Netdiso web UI plugins in other namespaces.
|
||||||
|
|
||||||
web_plugins:
|
Plugin modules can either ship with the App::Netdisco distribution itself, or
|
||||||
- Inventory
|
be installed separately. Perl uses the standard C<@INC> path searching
|
||||||
- Search::Device
|
mechanism to load the plugin modules. See the C<include_paths> and
|
||||||
- Device::Details
|
C<site_local_files> settings in order to modify C<@INC> for loading local
|
||||||
- +My::Other::Netdisco::Web::Component
|
plugins.
|
||||||
|
|
||||||
The order of the entries is significant. Unsurprisingly, the modules are
|
The order of the entries is significant. Drivers are executed in REVERSE
|
||||||
loaded in order. Therefore Navigation Bar items appear in the order listed,
|
order that they appear in the C<extra_collector_plugins> and
|
||||||
and Tabs appear on the Search and Device pages in the order listed, and so on.
|
C<collector_plugins> settings.
|
||||||
|
|
||||||
Finally, you can also prepend module names with "C<X::>", to support the
|
Finally, you can also prepend module names with "C<X::>", to support the
|
||||||
"Netdisco extension" namespace. For example, "C<X::Observium>" will load the
|
"Netdisco extension" namespace. For example,
|
||||||
L<App::NetdiscoX::Web::Plugin::Observium> module.
|
"C<X::Macsuck::WirelessNodes::UniFi>" will load the
|
||||||
|
L<App::NetdiscoX::Core::Plugin::Macsuck::WirelessNodes::UniFi> module.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
|
|||||||
@@ -279,16 +279,16 @@ collector_plugins:
|
|||||||
- Arpnip::Subnets::RFC
|
- Arpnip::Subnets::RFC
|
||||||
- NetBIOS::Nbtstat::RFC
|
- NetBIOS::Nbtstat::RFC
|
||||||
|
|
||||||
#core_phases:
|
core_phases:
|
||||||
# - discover_properties
|
- discover_properties
|
||||||
# - discover_interfaces
|
- discover_interfaces
|
||||||
# - discover_vlans
|
- discover_vlans
|
||||||
# - discover_wireless
|
- discover_wireless
|
||||||
# - discover_entities
|
- discover_entities
|
||||||
# - macsuck_nodes
|
- macsuck_nodes
|
||||||
# - arpnip_nodes
|
- arpnip_nodes
|
||||||
# - arpnip_subnets
|
- arpnip_subnets
|
||||||
# - netbios_stat
|
- netbios_stat
|
||||||
|
|
||||||
# ---------------
|
# ---------------
|
||||||
# GraphViz Export
|
# GraphViz Export
|
||||||
|
|||||||
Reference in New Issue
Block a user