Files
netdisco/Netdisco/lib/App/Netdisco.pm
Oliver Gorwits 86d74b0100 release 2.011000
Squashed commit of the following:

commit 3f1730957b6accbc11737e46c201453d7219d03e
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Jul 29 08:01:59 2013 +0100

    ready for 2.011000

commit e1873ca58375b458d9543576951f1003e1c28d35
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Jul 28 00:02:20 2013 +0100

    Find the RW snmp community string correctly now

commit 039780bc66ca0d8b19767c38a21aa208feafeaf7
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Jul 27 23:07:05 2013 +0100

    User Management (for admins only)

commit 213352d54ee8e71cbca5ae2c1c75696800c4216b
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Jul 27 21:17:57 2013 +0100

    Table headers float on the page when scrolling

commit 598960e9141b0d9fc4f9a234a7d8fe02a81ba0f9
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Jul 27 18:05:00 2013 +0100

    Port Utilization report

commit d25e41894476c74bee747e38960a277e2f5b2072
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Jul 27 15:20:23 2013 +0100

    Button to empty the job queue, and improve display when the queue is empty

commit 18125d1a758b5707ab4c0ff8b65dfdd90dc32664
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Jul 27 14:23:48 2013 +0100

    Swap play/pause icons in jobqueue

commit 9eead5328a127689701ac28d5bcf1cfa39edaf99
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Jul 25 23:11:17 2013 +0100

    Revert "No longer depend on Moo"

    This reverts commit 0a87ad4b410fa784bfbe823f3e6ede7c979144f3.

    Conflicts:

    	Netdisco/Changes

commit d0c31effa834201f1592c1fc3da9a6a689a3a43c
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Jul 25 23:01:32 2013 +0100

    REMOTE_USER is an env var, not an HTTP Header

commit 0a87ad4b410fa784bfbe823f3e6ede7c979144f3
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Jul 25 22:35:05 2013 +0100

    No longer depend on Moo

commit 7ccbb04e6f7c1701194d996baa557affcda48103
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Jul 24 23:44:42 2013 +0100

    ready for 2.010004

commit 6314c5a054d56d7829797d37c6627b2cbccde4ab
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Jul 24 23:41:51 2013 +0100

    Navbar query box was being cleared sometimes under admin task panels

commit 271a5d9db17b288aeff43ee29a6bbf753bf823de
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Jul 24 00:03:05 2013 +0100

    update TODO

commit 3103f968a9fb128726ed929589137cb6011e2591
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Tue Jul 23 23:58:19 2013 +0100

    ready for 2.010002

commit 0368df1dbdfe6d764eec05f2bf37587fff795995
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Tue Jul 23 23:17:17 2013 +0100

    fix bugs in topo update code

commit 43b7203ca3270dc2e02a097472179517087522d2
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Tue Jul 23 23:12:36 2013 +0100

    fix FF bug with forms embedded in tables

commit f86c5d7d3d8d293a781c2ec7dc7a18bfb3c8bf78
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Tue Jul 23 17:15:35 2013 +0100

    Nullify unused schema changes

commit 649e4c471d524013f87257e11fffa7789dccd01d
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Jun 20 13:48:20 2013 +0100

    version bump

commit ac6ce399b2bd596444a629f24ddea5eca0fff56a
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Jun 20 13:41:08 2013 +0100

    Handle UTF-8 data in the device port remote_id

commit c73b86c0204ddd98e9d27437028a7000d70338bf
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Jun 20 13:35:32 2013 +0100

    revert bytea conversion on remote_id

commit a144f42cf93803882bb8492cd3ce3a8e5679d383
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Jun 17 23:09:50 2013 +0100

    bump version for beta release

commit 3b791c93d7d9b7358bf46f31e322a9b807823d9d
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Jun 17 22:57:59 2013 +0100

    Pass event param to all js functions which require it

commit da38badef893fc1503a797a99c34504db71e7c20
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Jun 17 22:35:48 2013 +0100

    Change data type on device_port remote_id to bytea

commit 727237951a5576b476dee127b3cef777afb51df8
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Jun 17 10:52:28 2013 +0100

    fix help message in netdisco-web-fg

commit 25bc026dc5e0177cd3aa81c11cdace091eb68f36
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Jun 17 08:16:56 2013 +0100

    bump version for new release

commit d4042f6e8db42c7a85df4dcf9690fec72ad2db69
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Jun 16 18:27:52 2013 +0100

    Job Queue page play/pause/refresh controls

commit b6c9152516d7800409b7a73c5d0cdce6dd405492
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Jun 16 17:50:06 2013 +0100

    limit size of job queue table

commit ac9e5feb8b774071fcf4423dd862dced74dee9e6
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Jun 16 17:47:55 2013 +0100

    update bugs link

commit 9c0fb0e9aedc6297f4462c3cf88343f6d0df40b6
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Jun 16 17:41:29 2013 +0100

    update MANIFEST

commit 7aaa2fff91ed2b1839bdbb79081d90ad3e144f47
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Jun 16 17:40:35 2013 +0100

    Fix Plack middleware config for Expiry

commit 313e2cf014cf0da7cf85074e390ad394b28bf42d
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Jun 16 17:23:00 2013 +0100

    Support for delegated authentication with REMOTE_USER and X-REMOTE_USER

commit 85e21f2bf296c4a5ca6b5afb5091694e56e3031f
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Jun 16 14:24:08 2013 +0100

    Add tooltip showing the job queue item logged status message

commit 9b14f53ebed51eb46ea278807cfe8a2fbd28743c
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Jun 16 13:43:26 2013 +0100

    Increase default frequency of job queue polling to 2 seconds

commit 6ba46818d8ab2100c652c8eb8e98bc6f5a54e273
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Jun 16 12:57:43 2013 +0100

    workaround for https://github.com/PerlDancer/Dancer/issues/935

commit c7a2d8a9d45716959bedbbb8db4cdd82a5950642
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Jun 16 11:54:18 2013 +0100

    Fix hyperlinks when running behind reverse proxy on custom path

commit 0620efa404bc25cb0a9ada5aa6f1b092d5c4d482
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Jun 15 18:31:19 2013 +0100

    update deploy docs

commit 857b1c7aa0fe832f8948349eda5211eb38ba3099
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Jun 15 18:16:50 2013 +0100

    add note about compiler dependency

commit 02a2ad6b2c52db9fbc1e24bc8888f658dc7084ad
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Jun 15 17:44:29 2013 +0100

    sort vlans, macs, ips in device port view

commit 097bad77310728a98b261a2cfca4de7ab50be94b
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Jun 15 16:32:20 2013 +0100

    hint when calling web in fg without starman

commit 6425d89ddb2b56129c610482134482d8f9455d40
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Jun 15 15:53:26 2013 +0100

    macwalk and arpwalk refactored

commit d527b9d05addc82fb38c84f6fea1aa5818fc68d5
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Jun 13 22:27:34 2013 +0100

    implement is_macsuckable and is_arpnipable

commit 7af10ed313e25f5d99a22b53ba438225c2259069
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Jun 13 22:17:39 2013 +0100

    version bump

commit 8ace3bf8fa48cf3e14bdf86fad5a4862aad50a4b
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Jun 13 22:14:05 2013 +0100

    tidy up user menu

commit e6eef605c248471dbfe7ec62cd04d73d653523ca
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Jun 13 22:02:52 2013 +0100

    Add discoverall, macwalk, arpwalk items to the Admin Tasks menu

commit 2631fabd1eccd8a3971e4762eebe57f406623bee
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Jun 13 21:21:50 2013 +0100

    remove length() which only became sane in 5.12

commit a7b7169070a58685cacde26a3b6d462e74be9928
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Jun 13 19:07:56 2013 +0100

    Use DBIx::Class new collapsed query support when we can

commit 77cddab8ba7033ccb1ecae257bafa4eef8f99f47
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Jun 12 17:26:47 2013 +0100

    Database config simplified to only four essential settings

commit 6ed0802bf2ab0fd898ce6945451b8ca6566ae551
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Jun 12 13:03:20 2013 +0100

    Ask to set up guest user for Admin/Port Control rights in deploy script
2013-07-29 08:03:07 +01:00

311 lines
11 KiB
Perl

package App::Netdisco;
use strict;
use warnings FATAL => 'all';
use 5.010_000;
use File::ShareDir 'dist_dir';
use Path::Class;
our $VERSION = '2.011000';
BEGIN {
if (not ($ENV{DANCER_APPDIR} || '')
or not -f file($ENV{DANCER_APPDIR}, 'config.yml')) {
my $auto = dir(dist_dir('App-Netdisco'))->absolute;
my $home = ($ENV{NETDISCO_HOME} || $ENV{HOME});
$ENV{DANCER_APPDIR} ||= $auto->stringify;
$ENV{DANCER_CONFDIR} ||= $auto->stringify;
my $test_envdir = dir($home, 'environments')->stringify;
$ENV{DANCER_ENVDIR} ||= (-d $test_envdir
? $test_envdir : $auto->subdir('environments')->stringify);
$ENV{DANCER_ENVIRONMENT} ||= 'deployment';
$ENV{PLACK_ENV} ||= $ENV{DANCER_ENVIRONMENT};
$ENV{DANCER_PUBLIC} ||= $auto->subdir('public')->stringify;
$ENV{DANCER_VIEWS} ||= $auto->subdir('views')->stringify;
}
{
# Dancer 1 uses the broken YAML.pm module
# This is a global sledgehammer - could just apply to Dancer::Config
use YAML;
use YAML::XS;
no warnings 'redefine';
*YAML::LoadFile = sub { goto \&YAML::XS::LoadFile };
}
}
# set up database schema config from simple config vars
use Dancer ':script';
if (ref {} eq ref setting('database')) {
my $name = (setting('database')->{name} || 'netdisco');
my $host = (setting('database')->{host} || 'localhost');
my $user = (setting('database')->{user});
my $pass = (setting('database')->{pass});
# set up the netdisco schema now we have access to the config
# but only if it doesn't exist from an earlier config style
setting('plugins')->{DBIC}->{netdisco} ||= {
dsn => (sprintf 'dbi:Pg:dbname=%s;host=%s', $name, $host),
user => $user,
pass => $pass,
options => {
AutoCommit => 1,
RaiseError => 1,
},
schema_class => 'App::Netdisco::DB',
};
}
# static configuration for the in-memory local job queue
setting('plugins')->{DBIC}->{daemon} = {
dsn => 'dbi:SQLite:dbname=:memory:',
options => {
AutoCommit => 1,
RaiseError => 1,
sqlite_use_immediate_transaction => 1,
},
schema_class => 'App::Netdisco::Daemon::DB',
};
=head1 NAME
App::Netdisco - An open source web-based network management tool.
=head1 Introduction
The content of this distribution is the next major version of the Netdisco
network management tool. Pieces are still missing however, so if you're a new
user please see L<http://netdisco.org/> for further information on the project
and how to download the current official release.
L<App::Netdisco> provides a web frontend with built-in web server, and a
backend daemon to handle interactive requests such as changing port or device
properties.
If you have any trouble getting the frontend running, speak to someone in the
C<#netdisco> IRC channel (on freenode). Before installing or upgrading please
review the latest L<Release Notes|App::Netdisco::Manual::ReleaseNotes>.
=head1 Dependencies
Netdisco has several Perl library dependencies which will be automatically
installed. However it's I<strongly> recommended that you first install
L<DBD::Pg> and L<SNMP> using your operating system packages. The following
commands will test for the existence of them on your system:
perl -MDBD::Pg\ 999
perl -MSNMP\ 999
You'll also need a compiler for some of the other Perl dependencies. For
example on Ubuntu/Debian, install the C<build-essential> package. On
Fedora/Red-Hat, install C<make>, C<automake>, and C<gcc>.
With those installed, we can proceed...
Create a user on your system called C<netdisco> if one does not already exist.
We'll install Netdisco and its dependencies into this user's home area, which
will take about 250MB including MIB files.
root:~# useradd -m -p x -s /bin/bash netdisco
Netdisco uses the PostgreSQL database server. Install PostgreSQL and then change
to the PostgreSQL superuser (usually C<postgres>). Create a new database and
PostgreSQL user for the Netdisco application:
root:~# su - postgres
postgres:~$ createuser -DRSP netdisco
Enter password for new role:
Enter it again:
postgres:~$ createdb -O netdisco netdisco
=head1 Installation
The following is a general guide which works well in most circumstances. It
assumes you have a user C<netdisco> on your system, that you want to perform
an on-line installation, and have the application run self-contained from
within that user's home. There are alternatives: see the
L<Deployment|App::Netdisco::Manual::Deployment> documentation for further
details.
To avoid muddying your system, use the following script to download and
install Netdisco and its dependencies into the C<netdisco> user's home area
(C<~netdisco/perl5>):
su - netdisco
curl -L http://cpanmin.us/ | perl - --notest --verbose --local-lib ~/perl5 App::Netdisco
Link some of the newly installed apps into a handy location:
mkdir ~/bin
ln -s ~/perl5/bin/{localenv,netdisco-*} ~/bin/
Test the installation by running the following command, which should only
produce a status message (and throw up no errors):
~/bin/netdisco-daemon status
=head1 Configuration
Make a directory for your local configuration and copy the configuration
template from this distribution:
mkdir ~/environments
cp ~/perl5/lib/perl5/auto/share/dist/App-Netdisco/environments/deployment.yml ~/environments
chmod +w ~/environments/deployment.yml
Edit the file and change the database connection parameters to match those for
your local system (that is, the C<name>, C<host>, C<user> and C<pass>).
In the same file uncomment and edit the C<domain_suffix> setting to be
appropriate for your local site. Optionally, set the C<no_auth> value to true
if you wish to skip user authentication in the web interface.
=head1 Bootstrap
The database either needs configuring if new, or updating from the current
release of Netdisco (1.x). You also need vendor MAC address prefixes (OUI
data) and some MIBs if you want to run the daemon. The following script will
take care of all this for you:
~/bin/netdisco-deploy
Answer yes to all questions, if this is a new installation of Netdisco 2.
=head1 Startup
Run the following command to start the web-app server as a backgrounded daemon
(listening on port 5000):
~/bin/netdisco-web start
If the Inventory is empty because this is a new installation, you probably
want to either run some polling jobs from the command-line, or give a web user
some admin rights (TODO: user rights management).
Run the following command to start the job control daemon (port control, etc):
~/bin/netdisco-daemon start
You should take care not to run this Netdisco daemon and the legacy daemon at
the same time. Similarly, if you use the device discovery with Netdisco 2,
disable your system's cron jobs for the Netdisco 1 poller.
=head1 Upgrading
Before upgrading please review the latest L<Release
Notes|App::Netdisco::Manual::ReleaseNotes>. Then, the process is as follows:
# upgrade Netdisco
~/bin/localenv cpanm --notest App::Netdisco
# apply database schema updates
~/bin/netdisco-deploy
# restart web service
~/bin/netdisco-web restart
# restart job daemon (if you use it)
~/bin/netdisco-daemon restart
=head1 Tips and Tricks
=head2 Searching
The main black navigation bar has a search box which is smart enough to work
out what you're looking for in most cases. For example device names, node IP
or MAC addreses, VLAN numbers, and so on.
=head2 Command-Line Device and Port Actions
To run a device (discover, etc) or port control job from the command-line, use
the bundled L<netdisco-do> program. For example:
~/bin/netdisco-do -D discover -d 192.0.2.1
=head2 Import Topology
Netdisco 1.x had support for a topology information file to fill in device
port relations which could not be discovered. This is now stored in the
database (and edited in the web interface). To import a legacy topology file,
run:
~/bin/localenv nd-import-topology /path/to/netdisco-topology.txt
=head2 Deployment Scenarios
More documentation on how to deploy the application in other scenarios, for
example behind a web proxy, is in the
L<Deployment|App::Netdisco::Manual::Deployment> documentation.
=head2 Database API
Bundled with this distribution is a L<DBIx::Class> layer for the Netdisco
database. This abstracts away all the SQL into an elegant, re-usable OO
interface. See the L<Developer|App::Netdisco::Manual::Developing>
documentation for further information.
=head2 Plugins
Netdisco includes a Plugin subsystem for customizing the web user interface.
See L<App::Netdisco::Web::Plugin> for further information.
=head2 Developing
Lots of information about the architecture of this application is contained
within the L<Developer|App::Netdisco::Manual::Developing> documentation.
=head1 Caveats
Some sections are not yet implemented, e.g. the I<Device Module> tab.
Some menu items on the main black navigation bar go nowhere.
None of the Reports yet exist (e.g. searching for wireless devices, or duplex
mismatches). These will be implemented as a plugin bundle.
The Wireless, IP Phone and NetBIOS Node properies are not yet shown.
=head1 AUTHOR
Oliver Gorwits <oliver@cpan.org>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2012, 2013 by The Netdisco Developer Team.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Netdisco Project nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE NETDISCO DEVELOPER TEAM BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=cut
1;