Squashed commit of the following: commit86d0f61d0bAuthor: Oliver Gorwits <oliver@cpan.org> Date: Thu Nov 16 22:26:32 2017 +0000 fix typo commit5aff19621cAuthor: Oliver Gorwits <oliver@cpan.org> Date: Thu Nov 16 22:10:18 2017 +0000 fix use of snmp_connect_ip which does not work for SNMPv3 commit68a56d35bbAuthor: Oliver Gorwits <oliver@cpan.org> Date: Thu Nov 16 20:50:16 2017 +0000 no need for Array::Iterator even though it was cute commit71ee869c02Author: Oliver Gorwits <oliver@cpan.org> Date: Wed Nov 15 22:14:47 2017 +0000 additional doc examples commit620b3fe544Author: Oliver Gorwits <oliver@cpan.org> Date: Wed Nov 15 22:09:05 2017 +0000 stash workers within poller instance, and load plugins explicitly commit2431365583Author: Oliver Gorwits <oliver@cpan.org> Date: Mon Nov 13 22:17:11 2017 +0000 better fix for duplicate module entity index commita400b26704Author: Oliver Gorwits <oliver@cpan.org> Date: Mon Nov 13 22:14:42 2017 +0000 add ignore interfaces for HPE routers commit1502ec1966Author: Oliver Gorwits <oliver@cpan.org> Date: Mon Nov 13 22:08:02 2017 +0000 bug fixes after testing on a real network commit840b6b4069Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Nov 12 20:38:35 2017 +0000 add tests commit2de36c69baAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sun Nov 12 00:14:21 2017 +0000 some reengineering to support proper testing commitc5f138fe62Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Nov 11 14:43:53 2017 +0000 correct algorithm on finalise status, correct logging commit98442a2308Author: Oliver Gorwits <oliver@cpan.org> Date: Thu Nov 9 21:49:45 2017 +0000 bug fixes commite0c6615c87Author: Oliver Gorwits <oliver@cpan.org> Date: Wed Nov 8 20:29:33 2017 +0000 fix bugs commit1eeaba441dAuthor: Oliver Gorwits <oliver@cpan.org> Date: Tue Nov 7 22:30:55 2017 +0000 finish refactor to new desired behaviour (buggy?) commit7edfe88f25Author: Oliver Gorwits <oliver@cpan.org> Date: Mon Nov 6 22:50:51 2017 +0000 fix to work, and correct namespace check commit25907d3544Author: Oliver Gorwits <oliver@cpan.org> Date: Mon Nov 6 21:26:01 2017 +0000 move status tracking and checking inside job instance commit4436150bf4Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Nov 5 20:54:28 2017 +0000 remove global rubbish commit28b016e713Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Nov 4 23:31:51 2017 +0000 fix docs commit650f6c719bAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat Nov 4 23:22:12 2017 +0000 tidy line commit10f78d5dbeAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat Nov 4 23:06:20 2017 +0000 add priority and namespace to support fancy worker overrides commitb9f9816d09Author: Oliver Gorwits <oliver@cpan.org> Date: Wed Oct 11 18:33:46 2017 +0100 release 2.036012_001 commitc33bf204a4Merge:5b7ce3f7d3d81eb6Author: Oliver Gorwits <oliver@cpan.org> Date: Wed Oct 11 18:30:23 2017 +0100 Merge branch 'master' into og-coreplugins commit5b7ce3f797Author: Oliver Gorwits <oliver@cpan.org> Date: Mon Oct 9 15:46:09 2017 +0100 cannot Sereal::Encode DBIC row commit0a575f02baAuthor: Oliver Gorwits <oliver@cpan.org> Date: Mon Oct 9 14:07:56 2017 +0100 fix bug in job->device init commit207476950dAuthor: Oliver Gorwits <oliver@cpan.org> Date: Mon Oct 9 14:03:37 2017 +0100 default causes no attr to be created?! commit912f2fa91fAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sun Oct 8 18:43:51 2017 +0100 better debug logging commitdfeb9d9ddcAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sun Oct 8 18:40:02 2017 +0100 make device_auth have driver setting for snmp entries commit460c0c0ee9Merge:3ccd107b98423445Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Oct 8 18:08:58 2017 +0100 Merge branch 'master' into og-coreplugins commit3ccd107bd4Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Oct 7 14:13:58 2017 +0100 fix bug in device->has_layer commita4b9bf2036Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Oct 7 13:58:52 2017 +0100 netdisco-do show takes a param for method in -p commit4389cd0459Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Oct 7 13:36:06 2017 +0100 fix to only check last poll on devices in storage commit58d0fbdddaAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat Oct 7 13:21:13 2017 +0100 do not run discover parts if properties failed to complete commitb52aaaf1a1Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Oct 7 13:08:46 2017 +0100 fix typo commit41be926921Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Oct 7 13:04:45 2017 +0100 run all check workers commita41d114965Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Oct 7 13:02:46 2017 +0100 fix driver config commitb10908a138Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Oct 7 12:43:50 2017 +0100 use vars() cache between phases commit08b34e083dAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat Oct 7 11:39:17 2017 +0100 remove die() calls commitb8108986fbAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat Oct 7 11:31:59 2017 +0100 phase fixups commit273cbbc11bAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat Oct 7 09:42:41 2017 +0100 change stage to phase commit256c10bae5Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Oct 7 09:35:14 2017 +0100 multi worker actions need not return done from all workers commitee38bae48aAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat Oct 7 09:05:25 2017 +0100 store result of worker if best for this phase so far commit5bddfc73baAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat Oct 7 08:50:31 2017 +0100 auto debug-log worker return messages commit8b660a89c0Author: Oliver Gorwits <oliver@cpan.org> Date: Fri Oct 6 07:48:58 2017 +0100 bug fixes commitb58a5816a9Author: Oliver Gorwits <oliver@cpan.org> Date: Fri Oct 6 07:44:20 2017 +0100 remove unnecessary check phases commite44f06364aAuthor: Oliver Gorwits <oliver@cpan.org> Date: Fri Oct 6 07:18:03 2017 +0100 fix unknown command check in netdisco-do commit3af13f0dfeAuthor: Oliver Gorwits <oliver@cpan.org> Date: Fri Oct 6 07:15:59 2017 +0100 introduce noop and refactor checks in all workers commit98463c8cadAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sun Oct 1 10:49:12 2017 +0100 no need to debug log if there are no hooks in phase commit3b32e84312Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Oct 1 08:18:13 2017 +0100 fiddle about with runner logic to fix exit states commit8fdba38ee0Author: Oliver Gorwits <oliver@cpan.org> Date: Fri Sep 29 08:01:42 2017 +0100 cannot reuse a worker as the job will be already set and the wrong plugins loaded commita155d9cb77Author: Oliver Gorwits <oliver@cpan.org> Date: Fri Sep 29 08:01:06 2017 +0100 should defer when we cannot connect to device commit10b5f6cbc4Author: Oliver Gorwits <oliver@cpan.org> Date: Fri Sep 29 08:00:32 2017 +0100 fix bug in where workerconf acls are checked commit2a74e0befaAuthor: Oliver Gorwits <oliver@cpan.org> Date: Fri Sep 29 07:38:05 2017 +0100 can pass device instance to check_* commit4256b117dfAuthor: Oliver Gorwits <oliver@cpan.org> Date: Fri Sep 29 07:27:14 2017 +0100 move device_auth build to be with community defaults setting commita2de2c1616Merge:32be11c38dc4b9bcAuthor: Oliver Gorwits <oliver@cpan.org> Date: Fri Sep 29 07:21:03 2017 +0100 Merge branch 'master' into og-coreplugins commit32be11c3ffAuthor: Oliver Gorwits <oliver@cpan.org> Date: Thu Sep 21 00:09:29 2017 +0100 move remaining interactive actions to be plugins commit3e41c93f5aAuthor: Oliver Gorwits <oliver@cpan.org> Date: Wed Sep 20 21:47:50 2017 +0100 clean snmp handling commit30a2d5dd86Author: Oliver Gorwits <oliver@cpan.org> Date: Wed Sep 20 21:00:29 2017 +0100 make sure check plugins are loaded/run before phases commit3454d95a84Author: Oliver Gorwits <oliver@cpan.org> Date: Wed Sep 20 20:53:52 2017 +0100 capture result on main phase as well commit559fa4f93fAuthor: Oliver Gorwits <oliver@cpan.org> Date: Mon Sep 18 22:46:35 2017 +0100 build device_auth from communities commit1969291719Author: Oliver Gorwits <oliver@cpan.org> Date: Mon Sep 18 22:04:22 2017 +0100 simplify to remove phases and fewer hooks commit6f78032e28Author: Oliver Gorwits <oliver@cpan.org> Date: Thu Sep 14 21:30:03 2017 +0100 add phase to test worker commit6edd2dc879Author: Oliver Gorwits <oliver@cpan.org> Date: Wed Sep 13 21:51:40 2017 +0100 no need to list all plugins commitdfaeb34d8cAuthor: Oliver Gorwits <oliver@cpan.org> Date: Wed Sep 13 20:42:41 2017 +0100 add reset after messing with snmp context or community index commit09214dce92Author: Oliver Gorwits <oliver@cpan.org> Date: Wed Sep 13 20:29:21 2017 +0100 no need to pass $snmp around commit58cd488cccAuthor: Oliver Gorwits <oliver@cpan.org> Date: Wed Sep 13 19:22:40 2017 +0100 refactor layer and pseudo checks commit753acc607fAuthor: Oliver Gorwits <oliver@cpan.org> Date: Wed Sep 13 10:53:12 2017 +0100 use overloaded $device commitd5d39289d6Author: Oliver Gorwits <oliver@cpan.org> Date: Wed Sep 13 10:44:31 2017 +0100 rename init stage to check commit1fdb086183Author: Oliver Gorwits <oliver@cpan.org> Date: Tue Sep 12 08:12:12 2017 +0100 refactor to remove second loop commit64a9491115Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Sep 10 16:09:45 2017 +0100 change to init, first, second stages commit5f2da69697Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Sep 9 22:26:04 2017 +0100 move discover and discoverall to worker plugins commitc6ebb7cf07Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Sep 9 16:44:32 2017 +0100 move arpnip and arpwalk to worker plugins commit16a79463cbAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat Sep 9 16:27:58 2017 +0100 set snmp driver on macsuck phase workers commit9167e02de5Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Sep 9 15:55:53 2017 +0100 move macsuck and macwalk to worker plugins (macsuck needs snmp scope guard) commit68ca85643bAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat Sep 9 14:56:15 2017 +0100 move expire and expirenodes to worker plugins commit271ef1a25cAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat Sep 9 14:46:00 2017 +0100 move nbtstat and nbtwalk to worker plugins commite7508a9ecaAuthor: Oliver Gorwits <oliver@cpan.org> Date: Wed Sep 6 21:23:54 2017 +0100 move all netdisco-do action to worker plugins commit707fc82b99Author: Oliver Gorwits <oliver@cpan.org> Date: Wed Sep 6 21:01:37 2017 +0100 remove psql code from netdisco-do and fix detection of misspelled action commit411918e3f8Author: Oliver Gorwits <oliver@cpan.org> Date: Wed Sep 6 20:56:26 2017 +0100 only load worker plugins for the action commit1f9740c0e2Author: Oliver Gorwits <oliver@cpan.org> Date: Wed Sep 6 18:30:43 2017 +0100 shorten hook names commita59c23de79Author: Oliver Gorwits <oliver@cpan.org> Date: Wed Sep 6 18:27:34 2017 +0100 make psql worker primary, add hook debug log commit36c70220a2Author: Oliver Gorwits <oliver@cpan.org> Date: Tue Sep 5 22:39:22 2017 +0100 allow two forms of worker declaration, and update docs commita79cb9a9e4Author: Oliver Gorwits <oliver@cpan.org> Date: Tue Sep 5 22:10:53 2017 +0100 all the bug fixes and a working plugin!!!!!!!!! :-D commit04896202e0Author: Oliver Gorwits <oliver@cpan.org> Date: Tue Sep 5 21:39:41 2017 +0100 refine runner commit547fce2f3cAuthor: Oliver Gorwits <oliver@cpan.org> Date: Tue Sep 5 20:56:21 2017 +0100 hack the status class to regen if needed commitcd71a0b7a8Author: Oliver Gorwits <oliver@cpan.org> Date: Tue Sep 5 20:41:05 2017 +0100 move status update to job class commitc8e5cea4edAuthor: Oliver Gorwits <oliver@cpan.org> Date: Tue Sep 5 20:37:13 2017 +0100 objectify the running commitf48004fffaAuthor: Oliver Gorwits <oliver@cpan.org> Date: Tue Sep 5 19:58:28 2017 +0100 bug squish commit46ece568f6Author: Oliver Gorwits <oliver@cpan.org> Date: Tue Sep 5 19:54:57 2017 +0100 implement runner?! commitfc9c60f707Author: Oliver Gorwits <oliver@cpan.org> Date: Tue Sep 5 19:28:38 2017 +0100 rename ok to is_ok and change slot names to avoid conflict with creators commit3ee85383abAuthor: Oliver Gorwits <oliver@cpan.org> Date: Tue Sep 5 19:25:41 2017 +0100 skip worker when action is per-device but no creds commit75abdad812Author: Oliver Gorwits <oliver@cpan.org> Date: Mon Sep 4 21:54:37 2017 +0100 further work on retval handling from workers commit4c1fdf4f92Author: Oliver Gorwits <oliver@cpan.org> Date: Mon Sep 4 20:37:53 2017 +0100 move worker plugin loader to Worker.pm commitbe0c5181a3Author: Oliver Gorwits <oliver@cpan.org> Date: Mon Sep 4 20:35:42 2017 +0100 move Runner to Worker namespace commit1c2cf924bcAuthor: Oliver Gorwits <oliver@cpan.org> Date: Mon Sep 4 20:33:20 2017 +0100 worker roles in Role namespace commit3099eda393Author: Oliver Gorwits <oliver@cpan.org> Date: Mon Sep 4 20:30:58 2017 +0100 load workers when runner role is loaded commita8c58a7b05Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Sep 3 22:30:28 2017 +0100 initial broken implementation of the runner commit49b5274c33Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Sep 3 19:04:20 2017 +0100 use run() mixin to exec action commite0a666668aAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sun Sep 3 18:54:44 2017 +0100 fix pod; set status defaults; stub runner mixin commit8eaa33770cAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sun Sep 3 18:45:00 2017 +0100 rename Core to Worker and move other packages around commit4def0af0b0Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Sep 3 17:58:03 2017 +0100 better use of new status class commit8675bf62c6Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Sep 3 17:27:38 2017 +0100 fix hook naming and implement primary workers commitef1bb81f2bAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sun Sep 3 17:26:27 2017 +0100 new backend status class commit5f50dfadf1Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Sep 3 16:51:55 2017 +0100 new Backend package to load core plugins commit3baa7a818aAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sun Sep 3 16:22:29 2017 +0100 remove unnecessary Worker::Common role commit36b4adcc06Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Sep 3 16:17:29 2017 +0100 disambiguate util/backend package and remove backend prelaod commit98bff731bdAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat Sep 2 08:25:06 2017 +0100 settle on a design for hook override, I think commitfe5c16a16dAuthor: Oliver Gorwits <oliver@cpan.org> Date: Wed Aug 30 20:37:36 2017 +0100 rework docs to be more clear and reflect new operation commitb34ba1977cMerge:31d1977fc34ed61dAuthor: Oliver Gorwits <oliver@cpan.org> Date: Mon Aug 21 21:17:46 2017 +0100 Merge branch 'master' into og-coreplugins commit31d1977f1eAuthor: Oliver Gorwits <oliver@cpan.org> Date: Mon Aug 14 18:11:42 2017 +0100 Revert "move expire code to be initial plugin pilot (broken)" I think we'll only do the new backend code for jobs with a device. This reverts commit07998b72d9. commit61dc80aff8Merge:07998b72ade02db1Author: Oliver Gorwits <oliver@cpan.org> Date: Mon Aug 14 18:10:29 2017 +0100 Merge branch 'master' into og-coreplugins commit07998b72d9Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Aug 5 22:15:00 2017 +0100 move expire code to be initial plugin pilot (broken) commit685ec02108Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Aug 5 22:10:58 2017 +0100 pass $job to the core worker commitd6523fe543Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Aug 5 22:01:49 2017 +0100 $job->device is always a DBIC row commitee6deea01bAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat Aug 5 18:12:34 2017 +0100 load plugins commitfd80096ca2Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Aug 5 16:53:16 2017 +0100 rename all the things commit464c42d1f5Author: Oliver Gorwits <oliver@cpan.org> Date: Wed Aug 2 10:19:16 2017 +0100 use Scope::Guard to reduce device_auth commitec041dafd2Author: Oliver Gorwits <oliver@cpan.org> Date: Tue Aug 1 15:34:37 2017 +0100 the other way around commit33d2fe13bdAuthor: Oliver Gorwits <oliver@cpan.org> Date: Mon Jul 31 17:57:29 2017 +0100 fix pod commit3faee1cf16Author: Oliver Gorwits <oliver@cpan.org> Date: Mon Jul 31 17:55:10 2017 +0100 remove need for instance() call commitc6d0f1c035Author: Oliver Gorwits <oliver@cpan.org> Date: Wed Jul 26 13:51:23 2017 +0100 add doc note on accessing transports commitdca4b4fc03Author: Oliver Gorwits <oliver@cpan.org> Date: Wed Jul 26 11:50:10 2017 +0100 add backend driver documentation commit052a2acd79Author: Oliver Gorwits <oliver@cpan.org> Date: Wed Jul 26 10:16:58 2017 +0100 rename web plugins doc commit69c9a6393aAuthor: Oliver Gorwits <oliver@cpan.org> Date: Wed Jul 26 10:12:42 2017 +0100 rename args to driverconf commit2586a36f8cAuthor: Oliver Gorwits <oliver@cpan.org> Date: Tue Jul 25 22:41:10 2017 +0100 new version of core plugin manager with better config and filters commit4056831f99Author: Oliver Gorwits <oliver@cpan.org> Date: Tue Jul 25 20:53:56 2017 +0100 change SNMP to be a cached transport singleton commitc31030ef70Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Jul 23 13:46:27 2017 +0100 fixes because Dancer docs are a mess! commitf65ef90b86Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Jul 22 08:11:36 2017 +0100 rename snmp_auth to device_auth and include a little doc on transports commitd61556e1cfAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat Jul 22 07:54:26 2017 +0100 plugin config added commitde8de56308Author: Oliver Gorwits <oliver@cpan.org> Date: Wed Jul 12 21:38:31 2017 +0100 initial core plugin implementation
522 lines
17 KiB
Plaintext
522 lines
17 KiB
Plaintext
=head1 NAME
|
||
|
||
App::Netdisco::Manual::WritingWebPlugins - Documentation on Web Plugins for Developers
|
||
|
||
=head1 Introduction
|
||
|
||
L<App::Netdisco>'s plugin subsystem allows developers to write and test web
|
||
user interface (UI) components without needing to patch the main Netdisco
|
||
application. It also allows the end-user more control over the UI components
|
||
displayed in their browser.
|
||
|
||
See L<App::Netdisco::Web::Plugin> for more general information about plugins.
|
||
|
||
=head1 Developing Plugins
|
||
|
||
A plugin is simply a Perl module which is loaded. Therefore it can do anything
|
||
you like, but most usefully for the App::Netdisco web application the module
|
||
will install a L<Dancer> route handler subroutine, and link this to a web user
|
||
interface (UI) component.
|
||
|
||
Explaining how to write Dancer route handlers is beyond the scope of this
|
||
document, but by examining the source to the plugins in App::Netdisco you'll
|
||
probably get enough of an idea to begin on your own.
|
||
|
||
App::Netdisco plugins should load the L<App::Netdisco::Web::Plugin> module.
|
||
This exports a set of helper subroutines to register the new UI components.
|
||
Here's the boilerplate code for our example plugin module:
|
||
|
||
package App::Netdisco::Web::Plugin::MyNewFeature;
|
||
|
||
use Dancer ':syntax';
|
||
use Dancer::Plugin::DBIC;
|
||
use Dancer::Plugin::Auth::Extensible;
|
||
|
||
use App::Netdisco::Web::Plugin;
|
||
|
||
# plugin registration code goes here, ** see below **
|
||
|
||
# your Dancer route handler
|
||
get '/mynewfeature' => require_login sub {
|
||
# ...lorem ipsum...
|
||
};
|
||
|
||
true;
|
||
|
||
=head1 Navigation Bar items
|
||
|
||
These components appear in the black navigation bar at the top of each page,
|
||
as individual items (i.e. not in a menu). The canonical example of this is the
|
||
Inventory link.
|
||
|
||
To register an item for display in the navigation bar, use the following code:
|
||
|
||
register_navbar_item({
|
||
tag => 'newfeature',
|
||
path => '/mynewfeature',
|
||
label => 'My New Feature',
|
||
});
|
||
|
||
This causes an item to appear in the Navigation Bar with a visible text of "My
|
||
New Feature" which when clicked sends the user to the C</mynewfeature> page.
|
||
Note that this won't work for any target link - the path must be an
|
||
App::Netdisco Dancer route handler. Please bug the App::Netdisco devs if you
|
||
want arbitrary links supported.
|
||
|
||
=head1 Search and Device page Tabs
|
||
|
||
These components appear as tabs in the interface when the user reaches the
|
||
Search page or Device details page. Note that Tab plugins usually live in
|
||
the C<App::Netdisco::Web::Plugin::Device> or
|
||
C<App::Netdisco::Web::Plugin::Search> namespace.
|
||
|
||
To register a handler for display as a Search page Tab, use the following
|
||
code:
|
||
|
||
register_search_tab({tag => 'newfeature', label => 'My New Feature'});
|
||
|
||
This causes a tab to appear with the label "My New Feature". So how does
|
||
App::Netdisco know what the link should be? Well, as the
|
||
L<App::Netdisco::Developing> documentation says, tab content is retrieved by
|
||
an AJAX call back to the web server. This uses a predictable URL path format:
|
||
|
||
/ajax/content/<search or device>/<feature tag>
|
||
|
||
For example:
|
||
|
||
/ajax/content/search/newfeature
|
||
|
||
Therefore your plugin module should look like the following:
|
||
|
||
package App::Netdisco::Web::Plugin::Search::MyNewFeature
|
||
|
||
use Dancer ':syntax';
|
||
use Dancer::Plugin::DBIC;
|
||
use Dancer::Plugin::Auth::Extensible;
|
||
|
||
use App::Netdisco::Web::Plugin;
|
||
|
||
register_search_tab({tag => 'newfeature', label => 'My New Feature'});
|
||
|
||
get '/ajax/content/search/newfeature' => require_login sub {
|
||
# ...lorem ipsum...
|
||
|
||
# return some HTML content here, probably using a template
|
||
};
|
||
|
||
true;
|
||
|
||
If this all sounds a bit daunting, take a look at the
|
||
L<App::Netdisco::Web::Plugin::Search::Port> module which is fairly
|
||
straightforward.
|
||
|
||
To register a handler for display as a Device page Tab, the only difference is
|
||
the name of the registration helper sub:
|
||
|
||
register_device_tab({tag => 'newfeature', label => 'My New Feature'});
|
||
|
||
=head1 Reports
|
||
|
||
Report components contain pre-canned searches which the user community have
|
||
found to be useful. Before you go further, it might be the case that Netdisco
|
||
can generate the report for you without any Perl or HTML: see the L<Reports
|
||
Configuration|App::Netdisco::Manual::Configuration/reports> for details.
|
||
|
||
Otherwise, the typical implementation is very similar to one of the Search
|
||
and Device page Tabs, so please read that documentation above, first.
|
||
|
||
Report plugins usually live in the C<App::Netdisco::Web::Plugin::Report>
|
||
namespace. To register a handler for display as a Report, you need to pick the
|
||
I<category> of the report. Here are the pre-defined categories:
|
||
|
||
=over 4
|
||
|
||
=item *
|
||
|
||
Device
|
||
|
||
=item *
|
||
|
||
Port
|
||
|
||
=item *
|
||
|
||
IP
|
||
|
||
=item *
|
||
|
||
Node
|
||
|
||
=item *
|
||
|
||
VLAN
|
||
|
||
=item *
|
||
|
||
Network
|
||
|
||
=item *
|
||
|
||
Wireless
|
||
|
||
=back
|
||
|
||
Once your category is selected, use the following registration code:
|
||
|
||
register_report({
|
||
category => 'Port', # pick one from the list
|
||
tag => 'newreport',
|
||
label => 'My New Report',
|
||
});
|
||
|
||
You will note that like Device and Search page Tabs, there's no path
|
||
specified in the registration. The reports engine will make an AJAX request to
|
||
the following URL:
|
||
|
||
/ajax/content/report/<report tag>
|
||
|
||
Therefore you should implement in your plugin a route handler for this path.
|
||
The handler must return the HTML content for the report. It can also process
|
||
any query parameters which might customize the report search.
|
||
|
||
See the L<App::Netdisco::Web::Plugin::Report::DuplexMismatch> module for a
|
||
simple example of how to implement the handler.
|
||
|
||
An additional feature allows you to create Reports which do not appear in the
|
||
Navbar menu. This is useful if the page is only linked directly from another
|
||
(for example Port Log). To enable this feature add the C<hidden> key:
|
||
|
||
register_report({
|
||
tag => 'newfeature',
|
||
label => 'My New Feature',
|
||
hidden => true,
|
||
});
|
||
|
||
=head1 CSV Response
|
||
|
||
Most pages in Netdisco are a table with data. It's possible to have the
|
||
application add a link to download a CSV version of the same data. To do this,
|
||
include the following option in your call to C<register_search_tab>,
|
||
C<register_device_tab>, or C<register_report>:
|
||
|
||
provides_csv => 1
|
||
|
||
The other thing you need to do is adjust your Dancer route handler to return
|
||
either HTML or CSV data. Here's the typical way to do it:
|
||
|
||
get '/ajax/content/search/newfeature' => require_login sub {
|
||
# build some kind of dataset here (e.g. a DBIx::Class query)
|
||
|
||
if (request->is_ajax) {
|
||
template 'mytemplate', { data => $mydataset }, { layout => undef };
|
||
}
|
||
else {
|
||
header( 'Content-Type' => 'text/comma-separated-values' );
|
||
template 'mytemplate_csv', { data => $mydataset }, { layout => undef };
|
||
}
|
||
};
|
||
|
||
Note that the C<is_ajax> call is part of the standard Dancer featureset.
|
||
|
||
=head1 Admin Tasks
|
||
|
||
These components appear in the black navigation bar under an Admin menu, but only
|
||
if the logged in user has Administrator rights in Netdisco.
|
||
|
||
To register an item for display in the Admin menu, use the following code:
|
||
|
||
register_admin_task({
|
||
tag => 'newfeature',
|
||
label => 'My New Feature',
|
||
});
|
||
|
||
This causes an item to appear in the Admin menu with a visible text of "My New
|
||
Feature" which when clicked sends the user to the C</admin/mynewfeature> page.
|
||
Note that this won't work for any target link - the path must be an
|
||
App::Netdisco Dancer route handler. Please bug the App::Netdisco devs if you
|
||
want arbitrary links supported.
|
||
|
||
An additional feature allows you to create Admin Tasks which do not appear in
|
||
the Navbar menu. This is useful if the page is only linked directly from
|
||
another. To enable this feature add the C<hidden> key:
|
||
|
||
register_admin_task({
|
||
tag => 'newfeature',
|
||
label => 'My New Feature',
|
||
hidden => true,
|
||
});
|
||
|
||
=head1 Device Port Columns
|
||
|
||
You can also add columns to the Device Ports page. The canonical example of
|
||
this is to add hyperlinks (or embedded images) of traffic graphs for each
|
||
port, however the plugin is a regular Template::Toolkit template so can be any
|
||
HTML output.
|
||
|
||
The column plugin has a name (used internally to locate files on disk), label
|
||
(the heading for the column in the table or CSV output), position in the table
|
||
(three options: left, mid, right), and finally a flag for whether the column
|
||
is displayed by default.
|
||
|
||
To register the column call the following helper routine:
|
||
|
||
register_device_port_column({
|
||
name => 'myportcolumnplugin',
|
||
label => 'My Port Column Heading',
|
||
position => 'left', # or "mid" or "right"
|
||
default => 'on', # or undef
|
||
});
|
||
|
||
App::Netdisco searches for Template::Toolkit files in the regular template
|
||
include paths: either its internal locations, or those configured with the
|
||
C<site_local_files> setting or the C<register_template_path> helper (see
|
||
below). The template must be called "C<device_port_column.tt>" on disk and
|
||
live in the directory:
|
||
|
||
plugin/myportcolumnplugin/device_port_column.tt
|
||
|
||
For a good example of this, see the L<App::NetdiscoX::Web::Plugin::Observium>
|
||
distribution.
|
||
|
||
=head1 Device Details
|
||
|
||
You can add items to the Device Details tab as well. A good example of this is
|
||
to add a link to the RANCID backup of the device in a WebSVN app somewhere.
|
||
Like Device Port Columns plugins, the plugin is a regular Template::Toolkit
|
||
snippet so can be any HTML output.
|
||
|
||
The details plugin has a name (used internally to locate files on disk) and
|
||
label (the heading for the row in the table).
|
||
|
||
To register the column call the following helper routine:
|
||
|
||
register_device_details({
|
||
name => 'mydevicedetailsplugin',
|
||
label => 'My Device Details Heading',
|
||
});
|
||
|
||
App::Netdisco searches for Template::Toolkit files in the regular template
|
||
include paths: either its internal locations, or those configured with the
|
||
C<site_local_files> setting or the C<register_template_path> helper (see
|
||
below). The template must be called "C<device_port_column.tt>" on disk and
|
||
live in the directory:
|
||
|
||
plugin/mydevicedetailsplugin/device_details.tt
|
||
|
||
For a good example of this, see the L<App::NetdiscoX::Web::Plugin::RANCID>
|
||
distribution.
|
||
|
||
=head1 User Authorization
|
||
|
||
All Dancer route handlers must have proper authorization configured. This is
|
||
not difficult. Make sure that your module loads the
|
||
L<Dancer::Plugin::Auth::Extensible> module (as shown above).
|
||
|
||
For each route handler you either simply require that a user be logged in, or
|
||
that the user is an administrator.
|
||
|
||
To require a logged in user, include the C<require_login> wrapper:
|
||
|
||
get '/ajax/content/search/newfeature' => require_login sub {
|
||
# etc .....
|
||
|
||
To require an administrator, specify their role:
|
||
|
||
get '/ajax/control/admin/newfeature' => require_role admin => sub {
|
||
# etc .....
|
||
|
||
Finally in case you need it, the other role a user can have is
|
||
C<port_control>:
|
||
|
||
ajax '/ajax/portcontrol' => require_role port_control => sub {
|
||
# etc .....
|
||
|
||
Take care over the subtle differences in syntax, especially the placement of
|
||
the fat comma ("C<< => >>").
|
||
|
||
=head1 Database Connections
|
||
|
||
The Netdisco database is available via the C<netdisco> schema key, as below.
|
||
You can also use the C<external_databases> configuration item to set up
|
||
connections to other databases.
|
||
|
||
# possibly install another database driver
|
||
~netdisco/bin/localenv cpanm --notest DBD::mysql
|
||
|
||
# deployment.yml
|
||
external_databases:
|
||
- tag: externaldb
|
||
dsn: 'dbi:mysql:dbname=myexternaldb;host=192.0.2.1'
|
||
user: oliver
|
||
password: letmein
|
||
|
||
# plugin code
|
||
use Dancer::Plugin::DBIC;
|
||
|
||
schema('netdisco')->resultset('Devices')->search({vendor => 'cisco'});
|
||
schema('externaldb')->resultset('MyTable')->search({field => 'foobar'});
|
||
|
||
You'll need to install a L<DBIx::Class> Schema and also set C<schema_class> to
|
||
its name within the C<external_databases> setting, for the second example
|
||
above.
|
||
|
||
=head1 Templates
|
||
|
||
All of Netdisco's web page templates are stashed away in its distribution,
|
||
probably installed in your system's or user's Perl directory. It's not
|
||
recommended that you mess about with those files.
|
||
|
||
So in order to replace a template with your own version, or to reference a
|
||
template file of your own in your plugin, you need a new path.
|
||
|
||
If you don't plan on redistributing the plugin via CPAN, then configuring the
|
||
"C<site_local_files>" setting to be true will enable "C</nd-site-local/lib>"
|
||
for Perl code and "C</nd-site-local/share>" for tmplates in your Netdisco home
|
||
location. You will need to create these directories.
|
||
|
||
Alternatively, shipping templates within a CPAN distribution, the following
|
||
code would be appropriate:
|
||
|
||
package App::Netdisco::Web::Plugin::Search::MyNewFeature
|
||
|
||
use File::ShareDir 'dist_dir';
|
||
register_template_path(
|
||
dist_dir( 'App-Netdisco-Web-Plugin-Search-MyNewFeature' ));
|
||
|
||
The "C<views>" subdirectory of the registered path will be searched before the
|
||
built-in C<App::Netdisco> path. We recommend use of the L<File::ShareDir>
|
||
module to package and ship templates along with your plugin, as shown.
|
||
|
||
Each path added using C<register_template_path> is searched I<before> any
|
||
existing paths in the template config. See the
|
||
L<App::NetdiscoX::Web::Plugin::Observium> distribution for a working example.
|
||
|
||
=head2 Template Variables
|
||
|
||
Some useful variables are made available in your templates automatically by
|
||
App::Netdisco:
|
||
|
||
=over 4
|
||
|
||
=item C<search_node>
|
||
|
||
A path and query string which links to the Node tab of the Search page,
|
||
together with the correct default search options set.
|
||
|
||
=item C<search_device>
|
||
|
||
A path and query string which links to the Device tab of the Search page,
|
||
together with the correct default search options set.
|
||
|
||
=item C<device_ports>
|
||
|
||
A path and query sting which links to the Ports tab of the Device page,
|
||
together with the correct default column view options set.
|
||
|
||
=item C<uri_base>
|
||
|
||
Used for linking to static content within App::Netdisco safely if the base of
|
||
the app is relocated, for example:
|
||
|
||
<link rel="stylesheet" href="[% uri_base %]/css/toastr.css"/>
|
||
|
||
=item C<uri_for>
|
||
|
||
Simply the Dancer C<uri_for> method. Allows you to do things like this in the
|
||
template safely if the base of the app is relocated:
|
||
|
||
<a href="[% uri_for('/search') %]" ...>
|
||
|
||
=item C<self_options>
|
||
|
||
Available in the Device tabs, use this if you need to refer back to the
|
||
current page with some additional parameters, for example:
|
||
|
||
<a href="[% uri_for('/device', self_options) %]&foo=bar" ...>
|
||
|
||
=back
|
||
|
||
=head1 Javascript and Stylesheets
|
||
|
||
A simple mechanism exists for loading additional Javascript and CSS documents.
|
||
This is done in the C<< <head> >> section of the web page.
|
||
|
||
Netdisco searches all template include paths, both those built into the
|
||
application and those configured in your plugin(s) with "C<site_local_files>"
|
||
or C<register_template_path>.
|
||
|
||
Within the template location, create a directory called "C<plugin>" and within
|
||
that another directory named after your plugin (e.g. "C<mynewfeature>"). The
|
||
Javascript and/or CSS files must then be named "C<mynewfeature.js>" and
|
||
"C<mynewfeature.css>" respectively. For example:
|
||
|
||
plugin/mynewfeature/mynewfeature.js
|
||
plugin/mynewfeature/mynewfeature.css
|
||
|
||
Tell App::Netdisco that you wish to load one or the other using the following
|
||
helper routines:
|
||
|
||
register_javascript('mynewfeature');
|
||
register_css('mynewfeature');
|
||
|
||
=head1 Naming and File Location
|
||
|
||
There are several options for how you name, distribute and install your
|
||
App::Netdisco plugin.
|
||
|
||
=head2 Namespaces
|
||
|
||
As mentioned in L<App::Netdisco::Web::Plugin>, official Netdisco plugins live
|
||
in the C<App::Netdisco::Web::Plugin::> namespace. You can use this namespace
|
||
and submit the product to the Netdisco developer team for consideration for
|
||
inclusion in the official distribution.
|
||
|
||
Alternatively you can release the plugin to CPAN under your own account. In
|
||
that case we request that you instead use the C<App::NetdiscoX::Web::Plugin::>
|
||
namespace (note the "X"). Users can load such modules by using the
|
||
abbreviated form "X::MyPluginName" which is then expanded to the full package.
|
||
|
||
=head2 File Location
|
||
|
||
If writing your own plugins that are not for redistribution or packaging on
|
||
CPAN, Netdisco can enable local include paths for Perl, templates, and static
|
||
content such as javascript and images.
|
||
|
||
Configuring the "C<site_local_files>" to be "true" enables:
|
||
|
||
# perl code
|
||
$ENV{NETDISCO_HOME}/nd-site-local/lib
|
||
|
||
# templates and static content
|
||
$ENV{NETDISCO_HOME}/nd-site-local/share
|
||
|
||
Note that you still need to create the directories yourself, and templates may
|
||
need to have a further "C<views>" subdirectory created within "C<share>".
|
||
|
||
As an example, if your plugin is called
|
||
"App::NetdiscoX::Web::Plugin::MyPluginName" then it could live at:
|
||
|
||
~netdisco/nd-site-local/lib/App/NetdiscoX/Web/Plugin/MyPluginName.pm
|
||
|
||
=head1 Plugin Configuration
|
||
|
||
You can support new configuration items which the user should add to their
|
||
C<~/environments/deployment.yml> file. Please use a single Hash-Ref option
|
||
named "C<plugin_mypluginname>" (if your plugin's called C<mypluginname>). For
|
||
example:
|
||
|
||
plugin_observium:
|
||
webhost: "web-server.example.com"
|
||
open_in_new_window: true
|
||
|
||
You can then refer to this configuration in your plugin module:
|
||
|
||
my $webhost = setting('plugin_observium')->{'webhost'};
|
||
|
||
Or in templates via Dancer's C<settings> key:
|
||
|
||
<a href="http://[% settings.plugin_observium.webhost | uri %]/>Observium</a>
|
||
|
||
=cut
|
||
|