Files
netdisco/Netdisco/lib/App/Netdisco/DB/Result/DevicePort.pm
Oliver Gorwits d21f9e8e19 add discover/refresh, scheduler jobs, netdisco-do
New Poller daemon worker can discover and refresh devices.
  New Scheduler daemon worker replaces the cron jobs with config.
  New netdisco-do script allows running a job one-off from CLI.

Squashed commit of the following:

commit fa25f36e14
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Apr 10 22:43:47 2013 +0100

    fix HTTP port at 5000

commit 202ea4a84c
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Apr 10 22:33:03 2013 +0100

    bug fixes in discover

commit 925d9e4d6b
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Apr 10 21:51:44 2013 +0100

    add mini app for one-time jobs

commit d3a6c08a9d
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Apr 10 21:46:55 2013 +0100

    better name for subaction

commit 4adf473b20
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Apr 10 20:15:18 2013 +0100

    add logging of db add/del

commit 8aacafedaa
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Apr 10 19:49:00 2013 +0100

    copy all remaining messages from netdisco 1

commit 3e1156df1f
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Apr 8 22:09:40 2013 +0100

    alter some log levels and messages

commit e7ea92920f
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Apr 8 20:32:33 2013 +0100

    store wireless ssid and port info to DB

commit d1d16938a1
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Fri Apr 5 08:52:59 2013 +0100

    update packaging for new files and deps

commit 965990786f
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Apr 4 22:22:50 2013 +0100

    implementation of find_neighbors

commit 03c4d8ef09
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Apr 4 20:42:11 2013 +0100

    add discoverall and discover_neighbors poller jobs

commit df68ff0890
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Apr 4 19:52:37 2013 +0100

    implementation of store_modules

commit c2ac19e647
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Apr 4 19:32:14 2013 +0100

    implementation of store_power

commit b7fb8c64a0
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Apr 4 18:48:09 2013 +0100

    implementation of store_vlans

commit b8ddbd1eca
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Apr 4 17:08:06 2013 +0100

    implementation of store_wireless (without storing, yet)

commit 2a14057481
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Apr 4 16:47:21 2013 +0100

    implementation of store_interfaces (without wireless)

commit d5b2b71d34
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Apr 4 15:12:19 2013 +0100

    only start Manager if there are pollers or interactives

commit f4a3dac760
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Apr 4 15:03:10 2013 +0100

    change sub names so as not to collide with Dancer

commit a8f0894986
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Apr 4 14:47:28 2013 +0100

    implementation of refresh, discover, and store_device

commit 4c2e3cf82d
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Apr 4 11:38:15 2013 +0100

    make get_device return a new result object

commit e6ac131658
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Apr 4 10:38:22 2013 +0100

    better POD section name

commit 6c5b6bbbee
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Apr 4 10:37:46 2013 +0100

    implement separate snmp_connect and snmp_connect_rw methods

commit 62c8e19063
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Apr 1 20:06:29 2013 +0100

    fix for unique constraint on job queue for locally queued jobs

commit ebb65996e6
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Apr 1 20:00:36 2013 +0100

    add refresh poller job

commit 05928e8cf6
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Apr 1 19:31:39 2013 +0100

    Refactor Util namespace

    Squashed commit of the following:

    commit 789c528fcf
    Author: Oliver Gorwits <oliver@cpan.org>
    Date:   Mon Apr 1 19:31:07 2013 +0100

        update manifest and fix typo

    commit b95d0951f2
    Author: Oliver Gorwits <oliver@cpan.org>
    Date:   Mon Apr 1 19:22:41 2013 +0100

        refactor ::Util namespace

    commit a8dde50343
    Author: Oliver Gorwits <oliver@cpan.org>
    Date:   Sun Mar 31 13:45:27 2013 +0100

        no need to search for device - IP should already be exact

commit b42daee4c1
Merge: 6e52762 95bb8fc
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Mar 27 21:00:09 2013 +0000

    Merge branch 'master' into og-poller

commit 6e527629a2
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Tue Mar 26 23:39:23 2013 +0000

    fixes and log messages

commit cfcb7a956f
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Tue Mar 26 22:57:06 2013 +0000

    bug fixes

commit 48f779a8d0
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Tue Mar 26 22:42:16 2013 +0000

    add config for scheduled tasks

commit 2f6efcb312
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Tue Mar 26 22:15:04 2013 +0000

    create poller worker and add poller type stubs

commit 52b28b0ab8
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Tue Mar 26 22:04:00 2013 +0000

    code tidy

commit 96db66739f
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Mar 25 22:35:11 2013 +0000

    more insane but more working version of the job queue constraint

commit cb25216f40
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Mar 24 20:22:11 2013 +0000

    make scheduler start automatic based on housekeeping setting existing

commit 0acbe8abd3
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Mar 24 19:45:24 2013 +0000

    add scheduler based on Algorithm::Cron

commit 49d136b57a
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Mar 24 18:48:10 2013 +0000

    add unique constraint on admin/job queue
2013-04-10 22:55:49 +01:00

266 lines
6.8 KiB
Perl

use utf8;
package App::Netdisco::DB::Result::DevicePort;
# Created by DBIx::Class::Schema::Loader
# DO NOT MODIFY THE FIRST PART OF THIS FILE
use strict;
use warnings;
use base 'DBIx::Class::Core';
__PACKAGE__->table("device_port");
__PACKAGE__->add_columns(
"ip",
{ data_type => "inet", is_nullable => 0 },
"port",
{ data_type => "text", is_nullable => 0 },
"creation",
{
data_type => "timestamp",
default_value => \"current_timestamp",
is_nullable => 1,
original => { default_value => \"now()" },
},
"descr",
{ data_type => "text", is_nullable => 1 },
"up",
{ data_type => "text", is_nullable => 1 },
"up_admin",
{ data_type => "text", is_nullable => 1 },
"type",
{ data_type => "text", is_nullable => 1 },
"duplex",
{ data_type => "text", is_nullable => 1 },
"duplex_admin",
{ data_type => "text", is_nullable => 1 },
"speed",
{ data_type => "text", is_nullable => 1 },
"name",
{ data_type => "text", is_nullable => 1 },
"mac",
{ data_type => "macaddr", is_nullable => 1 },
"mtu",
{ data_type => "integer", is_nullable => 1 },
"stp",
{ data_type => "text", is_nullable => 1 },
"remote_ip",
{ data_type => "inet", is_nullable => 1 },
"remote_port",
{ data_type => "text", is_nullable => 1 },
"remote_type",
{ data_type => "text", is_nullable => 1 },
"remote_id",
{ data_type => "text", is_nullable => 1 },
"vlan",
{ data_type => "text", is_nullable => 1 },
"pvid",
{ data_type => "integer", is_nullable => 1 },
"lastchange",
{ data_type => "bigint", is_nullable => 1 },
);
__PACKAGE__->set_primary_key("port", "ip");
# Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:lcbweb0loNwHoWUuxTN/hA
=head1 RELATIONSHIPS
=head2 device
Returns the Device table entry to which the given Port is related.
=cut
__PACKAGE__->belongs_to( device => 'App::Netdisco::DB::Result::Device', 'ip' );
=head2 vlans
Returns the set of C<device_port_vlan> entries associated with this Port.
These will be both native and non-native (tagged). See also
C<port_vlans_tagged> and C<tagged_vlans>.
=cut
__PACKAGE__->has_many( vlans => 'App::Netdisco::DB::Result::DevicePortVlan',
{ 'foreign.ip' => 'self.ip', 'foreign.port' => 'self.port' } );
=head2 nodes / active_nodes / nodes_with_age / active_nodes_with_age
Returns the set of Nodes whose MAC addresses are associated with this Device
Port.
The C<active> variants return only the subset of nodes currently in the switch
MAC address table, that is the active ones.
The C<with_age> variants add an additional column C<time_last_age>, a
preformatted value for the Node's C<time_last> field, which reads as "X
days/weeks/months/years".
=cut
__PACKAGE__->has_many( nodes => 'App::Netdisco::DB::Result::Node',
{
'foreign.switch' => 'self.ip',
'foreign.port' => 'self.port',
},
{ join_type => 'LEFT' },
);
__PACKAGE__->has_many( nodes_with_age => 'App::Netdisco::DB::Result::Virtual::NodeWithAge',
{
'foreign.switch' => 'self.ip',
'foreign.port' => 'self.port',
},
{ join_type => 'LEFT' },
);
__PACKAGE__->has_many( active_nodes => 'App::Netdisco::DB::Result::Virtual::ActiveNode',
{
'foreign.switch' => 'self.ip',
'foreign.port' => 'self.port',
},
{ join_type => 'LEFT' },
);
__PACKAGE__->has_many( active_nodes_with_age => 'App::Netdisco::DB::Result::Virtual::ActiveNodeWithAge',
{
'foreign.switch' => 'self.ip',
'foreign.port' => 'self.port',
},
{ join_type => 'LEFT' },
);
=head2 neighbor_alias
When a device port has an attached neighbor device, this relationship will
return the IP address of the neighbor. See the C<neighbor> helper method if
what you really want is to retrieve the Device entry for that neighbor.
The JOIN is of type "LEFT" in case the neighbor device is known but has not
been fully discovered by Netdisco and so does not exist itself in the
database.
=cut
__PACKAGE__->belongs_to( neighbor_alias => 'App::Netdisco::DB::Result::DeviceIp',
{ 'foreign.alias' => 'self.remote_ip' },
{ join_type => 'LEFT' },
);
=head2 power
Returns a row from the C<device_port_power> table if one refers to this
device port.
=cut
__PACKAGE__->might_have( power => 'App::Netdisco::DB::Result::DevicePortPower', {
'foreign.ip' => 'self.ip', 'foreign.port' => 'self.port',
});
=head2 port_vlans_tagged
Returns a set of rows from the C<device_port_vlan> table relating to this
port, where the VLANs are all tagged.
=cut
__PACKAGE__->has_many( port_vlans_tagged => 'App::Netdisco::DB::Result::Virtual::DevicePortVlanTagged',
{
'foreign.ip' => 'self.ip',
'foreign.port' => 'self.port',
},
{ join_type => 'LEFT' },
);
=head2 tagged_vlans
As compared to C<port_vlans_tagged>, this relationship returns a set of VLAN
row objects for the VLANs on the given port, which might be more useful if you
want to find out details such as the VLAN name.
See also C<tagged_vlans_count>.
=cut
__PACKAGE__->many_to_many( tagged_vlans => 'port_vlans_tagged', 'vlan' );
=head2 oui
Returns the C<oui> table entry matching this Port. You can then join on this
relation and retrieve the Company name from the related table.
The JOIN is of type LEFT, in case the OUI table has not been populated.
=cut
__PACKAGE__->belongs_to( oui => 'App::Netdisco::DB::Result::Oui',
sub {
my $args = shift;
return {
"$args->{foreign_alias}.oui" =>
{ '=' => \"substring(cast($args->{self_alias}.mac as varchar) for 8)" }
};
},
{ join_type => 'LEFT' }
);
=head1 ADDITIONAL METHODS
=head2
Returns the Device entry for the neighbour Device on the given port.
Might return an undefined value if there is no neighbor on the port, or if the
neighbor has not been fully discovered by Netdisco and so does not exist in
the database.
=cut
sub neighbor {
my $row = shift;
return eval { $row->neighbor_alias->device || undef };
}
=head1 ADDITIONAL COLUMNS
=head2 tagged_vlans_count
Returns the number of tagged VLANs active on this device port. Enable this
column by applying the C<with_vlan_count()> modifier to C<search()>.
=cut
sub tagged_vlans_count { return (shift)->get_column('tagged_vlans_count') }
=head2 lastchange_stamp
Formatted version of the C<lastchange> field, accurate to the minute. Enable
this column by applying the C<with_vlan_count()> modifier to C<search()>.
The format is somewhat like ISO 8601 or RFC3339 but without the middle C<T>
between the date stamp and time stamp. That is:
2012-02-06 12:49
=cut
sub lastchange_stamp { return (shift)->get_column('lastchange_stamp') }
=head2 is_free
This method can be used to evaluate whether a device port could be considered
unused, based on the last time it changed from the "up" state to a "down"
state.
See the C<with_is_free> and C<only_free_ports> modifiers to C<search()>.
=cut
sub is_free { return (shift)->get_column('is_free') }
1;