relocate repo files so ND2 is the only code
This commit is contained in:
165
lib/App/Netdisco/DB/ExplicitLocking.pm
Normal file
165
lib/App/Netdisco/DB/ExplicitLocking.pm
Normal file
@@ -0,0 +1,165 @@
|
||||
package App::Netdisco::DB::ExplicitLocking;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
our %lock_modes;
|
||||
|
||||
BEGIN {
|
||||
%lock_modes = (
|
||||
ACCESS_SHARE => 'ACCESS SHARE',
|
||||
ROW_SHARE => 'ROW SHARE',
|
||||
ROW_EXCLUSIVE => 'ROW EXCLUSIVE',
|
||||
SHARE_UPDATE_EXCLUSIVE => 'SHARE UPDATE EXCLUSIVE',
|
||||
SHARE => 'SHARE',
|
||||
SHARE_ROW_EXCLUSIVE => 'SHARE ROW EXCLUSIVE',
|
||||
EXCLUSIVE => 'EXCLUSIVE',
|
||||
ACCESS_EXCLUSIVE => 'ACCESS EXCLUSIVE',
|
||||
);
|
||||
}
|
||||
|
||||
use constant \%lock_modes;
|
||||
|
||||
use base 'Exporter';
|
||||
our @EXPORT = ();
|
||||
our @EXPORT_OK = (keys %lock_modes);
|
||||
our %EXPORT_TAGS = (modes => \@EXPORT_OK);
|
||||
|
||||
sub txn_do_locked {
|
||||
my ($self, $table, $mode, $sub) = @_;
|
||||
my $sql_fmt = q{LOCK TABLE %s IN %%s MODE};
|
||||
my $schema = $self;
|
||||
|
||||
if ($self->can('result_source')) {
|
||||
# ResultSet component
|
||||
$sub = $mode;
|
||||
$mode = $table;
|
||||
$table = $self->result_source->from;
|
||||
$schema = $self->result_source->schema;
|
||||
}
|
||||
|
||||
$schema->throw_exception('missing Table name to txn_do_locked()')
|
||||
unless $table;
|
||||
|
||||
$table = [$table] if ref '' eq ref $table;
|
||||
my $table_fmt = join ', ', ('%s' x scalar @$table);
|
||||
my $sql = sprintf $sql_fmt, $table_fmt;
|
||||
|
||||
if (ref '' eq ref $mode and $mode) {
|
||||
scalar grep {$_ eq $mode} values %lock_modes
|
||||
or $schema->throw_exception('bad LOCK_MODE to txn_do_locked()');
|
||||
}
|
||||
else {
|
||||
$sub = $mode;
|
||||
$mode = 'ACCESS EXCLUSIVE';
|
||||
}
|
||||
|
||||
$schema->txn_do(sub {
|
||||
my @params = map {$schema->storage->dbh->quote_identifier($_)} @$table;
|
||||
$schema->storage->dbh->do(sprintf $sql, @params, $mode);
|
||||
$sub->();
|
||||
});
|
||||
}
|
||||
|
||||
=head1 NAME
|
||||
|
||||
App::Netdisco::DB::ExplicitLocking - Support for PostgreSQL Lock Modes
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
In your L<DBIx::Class> schema:
|
||||
|
||||
package My::Schema;
|
||||
__PACKAGE__->load_components('+App::Netdisco::DB::ExplicitLocking');
|
||||
|
||||
Then, in your application code:
|
||||
|
||||
use App::Netdisco::DB::ExplicitLocking ':modes';
|
||||
$schema->txn_do_locked($table, MODE_NAME, sub { ... });
|
||||
|
||||
This also works for the ResultSet:
|
||||
|
||||
package My::Schema::ResultSet::TableName;
|
||||
__PACKAGE__->load_components('+App::Netdisco::DB::ExplicitLocking');
|
||||
|
||||
Then, in your application code:
|
||||
|
||||
use App::Netdisco::DB::ExplicitLocking ':modes';
|
||||
$schema->resultset('TableName')->txn_do_locked(MODE_NAME, sub { ... });
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This L<DBIx::Class> component provides an easy way to execute PostgreSQL table
|
||||
locks before a transaction block.
|
||||
|
||||
You can load the component in either the Schema class or ResultSet class (or
|
||||
both) and then use an interface very similar to C<DBIx::Class>'s C<txn_do()>.
|
||||
|
||||
The package also exports constants for each of the table lock modes supported
|
||||
by PostgreSQL, which must be used if specifying the mode (default mode is
|
||||
C<ACCESS EXCLUSIVE>).
|
||||
|
||||
=head1 EXPORTS
|
||||
|
||||
With the C<:modes> tag (as in SYNOPSIS above) the following constants are
|
||||
exported and must be used if specifying the lock mode:
|
||||
|
||||
=over 4
|
||||
|
||||
=item * C<ACCESS_SHARE>
|
||||
|
||||
=item * C<ROW_SHARE>
|
||||
|
||||
=item * C<ROW_EXCLUSIVE>
|
||||
|
||||
=item * C<SHARE_UPDATE_EXCLUSIVE>
|
||||
|
||||
=item * C<SHARE>
|
||||
|
||||
=item * C<SHARE_ROW_EXCLUSIVE>
|
||||
|
||||
=item * C<EXCLUSIVE>
|
||||
|
||||
=item * C<ACCESS_EXCLUSIVE>
|
||||
|
||||
=back
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 C<< $schema->txn_do_locked($table|\@tables, MODE_NAME?, $subref) >>
|
||||
|
||||
This is the method signature used when the component is loaded into your
|
||||
Schema class. The reason you might want to use this over the ResultSet version
|
||||
(below) is to specify multiple tables to be locked before the transaction.
|
||||
|
||||
The first argument is one or more tables, and is required. Note that these are
|
||||
the real table names in PostgreSQL, and not C<DBIx::Class> ResultSet aliases
|
||||
or anything like that.
|
||||
|
||||
The mode name is optional, and defaults to C<ACCESS EXCLUSIVE>. You must use
|
||||
one of the exported constants in this parameter.
|
||||
|
||||
Finally pass a subroutine reference, just as you would to the normal
|
||||
C<DBIx::Class> C<txn_do()> method. Note that additional arguments are not
|
||||
supported.
|
||||
|
||||
=head2 C<< $resultset->txn_do_locked(MODE_NAME?, $subref) >>
|
||||
|
||||
This is the method signature used when the component is loaded into your
|
||||
ResultSet class. If you don't yet have a ResultSet class (which is the default
|
||||
- normally only Result classes are created) then you can create a stub which
|
||||
simply loads this component (and inherits from C<DBIx::Class::ResultSet>).
|
||||
|
||||
This is the simplest way to use this module if you only want to lock one table
|
||||
before your transaction block.
|
||||
|
||||
The first argument is the optional mode name, which defaults to C<ACCESS
|
||||
EXCLUSIVE>. You must use one of the exported constants in this parameter.
|
||||
|
||||
The second argument is a subroutine reference, just as you would pass to the
|
||||
normal C<DBIx::Class> C<txn_do()> method. Note that additional arguments are
|
||||
not supported.
|
||||
|
||||
=cut
|
||||
|
||||
1;
|
||||
117
lib/App/Netdisco/DB/Result/Admin.pm
Normal file
117
lib/App/Netdisco/DB/Result/Admin.pm
Normal file
@@ -0,0 +1,117 @@
|
||||
use utf8;
|
||||
package App::Netdisco::DB::Result::Admin;
|
||||
|
||||
# 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("admin");
|
||||
__PACKAGE__->add_columns(
|
||||
"job",
|
||||
{
|
||||
data_type => "integer",
|
||||
is_auto_increment => 1,
|
||||
is_nullable => 0,
|
||||
sequence => "admin_job_seq",
|
||||
},
|
||||
"entered",
|
||||
{
|
||||
data_type => "timestamp",
|
||||
default_value => \"current_timestamp",
|
||||
is_nullable => 1,
|
||||
original => { default_value => \"now()" },
|
||||
},
|
||||
"started",
|
||||
{ data_type => "timestamp", is_nullable => 1 },
|
||||
"finished",
|
||||
{ data_type => "timestamp", is_nullable => 1 },
|
||||
"device",
|
||||
{ data_type => "inet", is_nullable => 1 },
|
||||
"port",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"action",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"subaction",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"status",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"username",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"userip",
|
||||
{ data_type => "inet", is_nullable => 1 },
|
||||
"log",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"debug",
|
||||
{ data_type => "boolean", is_nullable => 1 },
|
||||
);
|
||||
|
||||
|
||||
# Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:gW4JW4pMgrufFIxFeYPYpw
|
||||
|
||||
__PACKAGE__->set_primary_key("job");
|
||||
|
||||
# You can replace this text with custom code or comments, and it will be preserved on regeneration
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 summary
|
||||
|
||||
An attempt to make a meaningful statement about the job.
|
||||
|
||||
=cut
|
||||
|
||||
sub summary {
|
||||
my $job = shift;
|
||||
return join ' ',
|
||||
$job->action,
|
||||
($job->device || ''),
|
||||
($job->port || '');
|
||||
# ($job->subaction ? (q{'}. $job->subaction .q{'}) : '');
|
||||
}
|
||||
|
||||
=head1 ADDITIONAL COLUMNS
|
||||
|
||||
=head2 entererd_stamp
|
||||
|
||||
Formatted version of the C<entered> field, accurate to the minute.
|
||||
|
||||
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 entered_stamp { return (shift)->get_column('entered_stamp') }
|
||||
|
||||
=head2 started_stamp
|
||||
|
||||
Formatted version of the C<started> field, accurate to the minute.
|
||||
|
||||
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 started_stamp { return (shift)->get_column('started_stamp') }
|
||||
|
||||
=head2 finished_stamp
|
||||
|
||||
Formatted version of the C<finished> field, accurate to the minute.
|
||||
|
||||
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 finished_stamp { return (shift)->get_column('finished_stamp') }
|
||||
|
||||
1;
|
||||
21
lib/App/Netdisco/DB/Result/Community.pm
Normal file
21
lib/App/Netdisco/DB/Result/Community.pm
Normal file
@@ -0,0 +1,21 @@
|
||||
use utf8;
|
||||
package App::Netdisco::DB::Result::Community;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use base 'DBIx::Class::Core';
|
||||
__PACKAGE__->table("community");
|
||||
__PACKAGE__->add_columns(
|
||||
"ip",
|
||||
{ data_type => "inet", is_nullable => 0 },
|
||||
"snmp_comm_rw",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"snmp_auth_tag_read",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"snmp_auth_tag_write",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
);
|
||||
__PACKAGE__->set_primary_key("ip");
|
||||
|
||||
1;
|
||||
357
lib/App/Netdisco/DB/Result/Device.pm
Normal file
357
lib/App/Netdisco/DB/Result/Device.pm
Normal file
@@ -0,0 +1,357 @@
|
||||
use utf8;
|
||||
package App::Netdisco::DB::Result::Device;
|
||||
|
||||
# Created by DBIx::Class::Schema::Loader
|
||||
# DO NOT MODIFY THE FIRST PART OF THIS FILE
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use NetAddr::IP::Lite ':lower';
|
||||
use App::Netdisco::Util::DNS 'hostname_from_ip';
|
||||
|
||||
use base 'DBIx::Class::Core';
|
||||
__PACKAGE__->table("device");
|
||||
__PACKAGE__->add_columns(
|
||||
"ip",
|
||||
{ data_type => "inet", is_nullable => 0 },
|
||||
"creation",
|
||||
{
|
||||
data_type => "timestamp",
|
||||
default_value => \"current_timestamp",
|
||||
is_nullable => 1,
|
||||
original => { default_value => \"now()" },
|
||||
},
|
||||
"dns",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"description",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"uptime",
|
||||
{ data_type => "bigint", is_nullable => 1 },
|
||||
"contact",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"name",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"location",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"layers",
|
||||
{ data_type => "varchar", is_nullable => 1, size => 8 },
|
||||
"ports",
|
||||
{ data_type => "integer", is_nullable => 1 },
|
||||
"mac",
|
||||
{ data_type => "macaddr", is_nullable => 1 },
|
||||
"serial",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"model",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"ps1_type",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"ps2_type",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"ps1_status",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"ps2_status",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"fan",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"slots",
|
||||
{ data_type => "integer", is_nullable => 1 },
|
||||
"vendor",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"os",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"os_ver",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"log",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"snmp_ver",
|
||||
{ data_type => "integer", is_nullable => 1 },
|
||||
"snmp_comm",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"snmp_class",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"vtp_domain",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"last_discover",
|
||||
{ data_type => "timestamp", is_nullable => 1 },
|
||||
"last_macsuck",
|
||||
{ data_type => "timestamp", is_nullable => 1 },
|
||||
"last_arpnip",
|
||||
{ data_type => "timestamp", is_nullable => 1 },
|
||||
);
|
||||
__PACKAGE__->set_primary_key("ip");
|
||||
|
||||
# Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:671/XuuvsO2aMB1+IRWFjg
|
||||
|
||||
=head1 RELATIONSHIPS
|
||||
|
||||
=head2 device_ips
|
||||
|
||||
Returns rows from the C<device_ip> table which relate to this Device. That is,
|
||||
all the interface IP aliases configured on the Device.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->has_many( device_ips => 'App::Netdisco::DB::Result::DeviceIp', 'ip' );
|
||||
|
||||
=head2 vlans
|
||||
|
||||
Returns the C<device_vlan> entries for this Device. That is, the list of VLANs
|
||||
configured on or known by this Device.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->has_many( vlans => 'App::Netdisco::DB::Result::DeviceVlan', 'ip' );
|
||||
|
||||
=head2 ports
|
||||
|
||||
Returns the set of ports on this Device.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->has_many( ports => 'App::Netdisco::DB::Result::DevicePort', 'ip' );
|
||||
|
||||
=head2 modules
|
||||
|
||||
Returns the set chassis modules on this Device.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->has_many( modules => 'App::Netdisco::DB::Result::DeviceModule', 'ip' );
|
||||
|
||||
=head2 power_modules
|
||||
|
||||
Returns the set of power modules on this Device.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->has_many( power_modules => 'App::Netdisco::DB::Result::DevicePower', 'ip' );
|
||||
|
||||
=head2 port_vlans
|
||||
|
||||
Returns the set of VLANs known to be configured on Ports on this Device,
|
||||
either tagged or untagged.
|
||||
|
||||
The JOIN is of type "RIGHT" meaning that the results are constrained to VLANs
|
||||
only on Ports on this Device.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->has_many(
|
||||
port_vlans => 'App::Netdisco::DB::Result::DevicePortVlan',
|
||||
'ip', { join_type => 'RIGHT' }
|
||||
);
|
||||
|
||||
# helper which assumes we've just RIGHT JOINed to Vlans table
|
||||
sub vlan { return (shift)->vlans->first }
|
||||
|
||||
=head2 wireless_ports
|
||||
|
||||
Returns the set of wireless IDs known to be configured on Ports on this
|
||||
Device.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->has_many(
|
||||
wireless_ports => 'App::Netdisco::DB::Result::DevicePortWireless',
|
||||
'ip', { join_type => 'RIGHT' }
|
||||
);
|
||||
|
||||
=head2 ssids
|
||||
|
||||
Returns the set of SSIDs known to be configured on Ports on this Device.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->has_many(
|
||||
ssids => 'App::Netdisco::DB::Result::DevicePortSsid',
|
||||
'ip', { join_type => 'RIGHT' }
|
||||
);
|
||||
|
||||
=head2 powered_ports
|
||||
|
||||
Returns the set of ports known to have PoE capability
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->has_many(
|
||||
powered_ports => 'App::Netdisco::DB::Result::DevicePortPower',
|
||||
'ip', { join_type => 'RIGHT' }
|
||||
);
|
||||
|
||||
=head2 community
|
||||
|
||||
Returns the row from the community string table, if one exists.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->might_have(
|
||||
community => 'App::Netdisco::DB::Result::Community', 'ip');
|
||||
|
||||
=head1 ADDITIONAL METHODS
|
||||
|
||||
=head2 renumber( $new_ip )
|
||||
|
||||
Will update this device and all related database records to use the new IP
|
||||
C<$new_ip>. Returns C<undef> if $new_ip seems invalid, otherwise returns the
|
||||
Device row object.
|
||||
|
||||
=cut
|
||||
|
||||
sub renumber {
|
||||
my ($device, $ip) = @_;
|
||||
my $schema = $device->result_source->schema;
|
||||
|
||||
my $new_addr = NetAddr::IP::Lite->new($ip)
|
||||
or return;
|
||||
|
||||
my $old_ip = $device->ip;
|
||||
my $new_ip = $new_addr->addr;
|
||||
|
||||
return
|
||||
if $new_ip eq '0.0.0.0'
|
||||
or $new_ip eq '127.0.0.1';
|
||||
|
||||
foreach my $set (qw/
|
||||
DeviceIp
|
||||
DeviceModule
|
||||
DevicePower
|
||||
DeviceVlan
|
||||
DevicePort
|
||||
DevicePortLog
|
||||
DevicePortPower
|
||||
DevicePortSsid
|
||||
DevicePortVlan
|
||||
DevicePortWireless
|
||||
Community
|
||||
/) {
|
||||
$schema->resultset($set)
|
||||
->search({ip => $old_ip})
|
||||
->update({ip => $new_ip});
|
||||
}
|
||||
|
||||
$schema->resultset('DevicePort')
|
||||
->search({remote_ip => $old_ip})
|
||||
->update({remote_ip => $new_ip});
|
||||
|
||||
$schema->resultset('Admin')
|
||||
->search({device => $old_ip})
|
||||
->update({device => $new_ip});
|
||||
|
||||
$schema->resultset('Node')
|
||||
->search({switch => $old_ip})
|
||||
->update({switch => $new_ip});
|
||||
|
||||
$schema->resultset('Topology')
|
||||
->search({dev1 => $old_ip})
|
||||
->update({dev1 => $new_ip});
|
||||
|
||||
$schema->resultset('Topology')
|
||||
->search({dev2 => $old_ip})
|
||||
->update({dev2 => $new_ip});
|
||||
|
||||
$device->update({
|
||||
ip => $new_ip,
|
||||
dns => hostname_from_ip($new_ip),
|
||||
});
|
||||
|
||||
return $device;
|
||||
}
|
||||
|
||||
=head1 ADDITIONAL COLUMNS
|
||||
|
||||
=head2 oui
|
||||
|
||||
Returns the first half of the device MAC address.
|
||||
|
||||
=cut
|
||||
|
||||
sub oui { return substr( ((shift)->mac || ''), 0, 8 ) }
|
||||
|
||||
=head2 port_count
|
||||
|
||||
Returns the number of ports on this device. Enable this
|
||||
column by applying the C<with_port_count()> modifier to C<search()>.
|
||||
|
||||
=cut
|
||||
|
||||
sub port_count { return (shift)->get_column('port_count') }
|
||||
|
||||
|
||||
=head2 uptime_age
|
||||
|
||||
Formatted version of the C<uptime> field.
|
||||
|
||||
The format is in "X days/months/years" style, similar to:
|
||||
|
||||
1 year 4 months 05:46:00
|
||||
|
||||
=cut
|
||||
|
||||
sub uptime_age { return (shift)->get_column('uptime_age') }
|
||||
|
||||
=head2 last_discover_stamp
|
||||
|
||||
Formatted version of the C<last_discover> field, accurate to the minute.
|
||||
|
||||
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 last_discover_stamp { return (shift)->get_column('last_discover_stamp') }
|
||||
|
||||
=head2 last_macsuck_stamp
|
||||
|
||||
Formatted version of the C<last_macsuck> field, accurate to the minute.
|
||||
|
||||
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 last_macsuck_stamp { return (shift)->get_column('last_macsuck_stamp') }
|
||||
|
||||
=head2 last_arpnip_stamp
|
||||
|
||||
Formatted version of the C<last_arpnip> field, accurate to the minute.
|
||||
|
||||
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 last_arpnip_stamp { return (shift)->get_column('last_arpnip_stamp') }
|
||||
|
||||
=head2 since_last_discover
|
||||
|
||||
Number of seconds which have elapsed since the value of C<last_discover>.
|
||||
|
||||
=cut
|
||||
|
||||
sub since_last_discover { return (shift)->get_column('since_last_discover') }
|
||||
|
||||
=head2 since_last_macsuck
|
||||
|
||||
Number of seconds which have elapsed since the value of C<last_macsuck>.
|
||||
|
||||
=cut
|
||||
|
||||
sub since_last_macsuck { return (shift)->get_column('since_last_macsuck') }
|
||||
|
||||
=head2 since_last_arpnip
|
||||
|
||||
Number of seconds which have elapsed since the value of C<last_arpnip>.
|
||||
|
||||
=cut
|
||||
|
||||
sub since_last_arpnip { return (shift)->get_column('since_last_arpnip') }
|
||||
|
||||
1;
|
||||
59
lib/App/Netdisco/DB/Result/DeviceIp.pm
Normal file
59
lib/App/Netdisco/DB/Result/DeviceIp.pm
Normal file
@@ -0,0 +1,59 @@
|
||||
use utf8;
|
||||
package App::Netdisco::DB::Result::DeviceIp;
|
||||
|
||||
# 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_ip");
|
||||
__PACKAGE__->add_columns(
|
||||
"ip",
|
||||
{ data_type => "inet", is_nullable => 0 },
|
||||
"alias",
|
||||
{ data_type => "inet", is_nullable => 0 },
|
||||
"subnet",
|
||||
{ data_type => "cidr", is_nullable => 1 },
|
||||
"port",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"dns",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"creation",
|
||||
{
|
||||
data_type => "timestamp",
|
||||
default_value => \"current_timestamp",
|
||||
is_nullable => 1,
|
||||
original => { default_value => \"now()" },
|
||||
},
|
||||
);
|
||||
__PACKAGE__->set_primary_key("ip", "alias");
|
||||
|
||||
|
||||
# Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:/ugGtBSGyrJ7s6yqJ9bclQ
|
||||
|
||||
=head1 RELATIONSHIPS
|
||||
|
||||
=head2 device
|
||||
|
||||
Returns the entry from the C<device> table to which this IP alias relates.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->belongs_to( device => 'App::Netdisco::DB::Result::Device', 'ip' );
|
||||
|
||||
=head2 device_port
|
||||
|
||||
Returns the Port on which this IP address is configured (typically a loopback,
|
||||
routed port or virtual interface).
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->add_unique_constraint(['alias']);
|
||||
|
||||
__PACKAGE__->belongs_to( device_port => 'App::Netdisco::DB::Result::DevicePort',
|
||||
{ 'foreign.port' => 'self.port', 'foreign.ip' => 'self.ip' } );
|
||||
|
||||
1;
|
||||
68
lib/App/Netdisco/DB/Result/DeviceModule.pm
Normal file
68
lib/App/Netdisco/DB/Result/DeviceModule.pm
Normal file
@@ -0,0 +1,68 @@
|
||||
use utf8;
|
||||
package App::Netdisco::DB::Result::DeviceModule;
|
||||
|
||||
# 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_module");
|
||||
__PACKAGE__->add_columns(
|
||||
"ip",
|
||||
{ data_type => "inet", is_nullable => 0 },
|
||||
"index",
|
||||
{ data_type => "integer", is_nullable => 0 },
|
||||
"description",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"type",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"parent",
|
||||
{ data_type => "integer", is_nullable => 1 },
|
||||
"name",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"class",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"pos",
|
||||
{ data_type => "integer", is_nullable => 1 },
|
||||
"hw_ver",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"fw_ver",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"sw_ver",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"serial",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"model",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"fru",
|
||||
{ data_type => "boolean", is_nullable => 1 },
|
||||
"creation",
|
||||
{
|
||||
data_type => "timestamp",
|
||||
default_value => \"current_timestamp",
|
||||
is_nullable => 1,
|
||||
original => { default_value => \"now()" },
|
||||
},
|
||||
"last_discover",
|
||||
{ data_type => "timestamp", is_nullable => 1 },
|
||||
);
|
||||
__PACKAGE__->set_primary_key("ip", "index");
|
||||
|
||||
|
||||
# Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:nuwxZBoiip9trdJFmgk3Fw
|
||||
|
||||
=head1 RELATIONSHIPS
|
||||
|
||||
=head2 device
|
||||
|
||||
Returns the entry from the C<device> table on which this VLAN entry was discovered.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->belongs_to( device => 'App::Netdisco::DB::Result::Device', 'ip' );
|
||||
|
||||
# You can replace this text with custom code or comments, and it will be preserved on regeneration
|
||||
1;
|
||||
378
lib/App/Netdisco/DB/Result/DevicePort.pm
Normal file
378
lib/App/Netdisco/DB/Result/DevicePort.pm
Normal file
@@ -0,0 +1,378 @@
|
||||
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 NetAddr::MAC;
|
||||
|
||||
use MIME::Base64 'encode_base64url';
|
||||
|
||||
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 },
|
||||
"is_master",
|
||||
{ data_type => "bool", is_nullable => 0, default_value => \"false" },
|
||||
"slave_of",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"manual_topo",
|
||||
{ data_type => "bool", is_nullable => 0, default_value => \"false" },
|
||||
"is_uplink",
|
||||
{ data_type => "bool", 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 port_vlans
|
||||
|
||||
Returns the set of C<device_port_vlan> entries associated with this Port.
|
||||
These will be both tagged and untagged. Use this relation in search conditions.
|
||||
|
||||
See also C<all_port_vlans>.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->has_many( port_vlans => 'App::Netdisco::DB::Result::DevicePortVlan',
|
||||
{ 'foreign.ip' => 'self.ip', 'foreign.port' => 'self.port' } );
|
||||
|
||||
=head2 all_port_vlans
|
||||
|
||||
Returns the set of C<device_port_vlan> entries associated with this Port.
|
||||
These will be both tagged and untagged. Use this relation when prefetching related
|
||||
C<device_port_vlan> rows.
|
||||
|
||||
See also C<port_vlans>.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->has_many( all_port_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',
|
||||
cascade_copy => 0, cascade_update => 0, cascade_delete => 0 },
|
||||
);
|
||||
|
||||
__PACKAGE__->has_many( active_nodes => 'App::Netdisco::DB::Result::Virtual::ActiveNode',
|
||||
{
|
||||
'foreign.switch' => 'self.ip',
|
||||
'foreign.port' => 'self.port',
|
||||
},
|
||||
{ join_type => 'LEFT',
|
||||
cascade_copy => 0, cascade_update => 0, cascade_delete => 0 },
|
||||
);
|
||||
|
||||
__PACKAGE__->has_many( active_nodes_with_age => 'App::Netdisco::DB::Result::Virtual::ActiveNodeWithAge',
|
||||
{
|
||||
'foreign.switch' => 'self.ip',
|
||||
'foreign.port' => 'self.port',
|
||||
},
|
||||
{ join_type => 'LEFT',
|
||||
cascade_copy => 0, cascade_update => 0, cascade_delete => 0 },
|
||||
);
|
||||
|
||||
=head2 logs
|
||||
|
||||
Returns the set of C<device_port_log> entries associated with this Port.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->has_many( logs => 'App::Netdisco::DB::Result::DevicePortLog',
|
||||
{ 'foreign.ip' => 'self.ip', 'foreign.port' => 'self.port' },
|
||||
);
|
||||
|
||||
=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 ssid
|
||||
|
||||
Returns a row from the C<device_port_ssid> table if one refers to this
|
||||
device port.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->might_have(
|
||||
ssid => 'App::Netdisco::DB::Result::DevicePortSsid',
|
||||
{ 'foreign.ip' => 'self.ip',
|
||||
'foreign.port' => 'self.port',
|
||||
}
|
||||
);
|
||||
|
||||
=head2 wireless
|
||||
|
||||
Returns a row from the C<device_port_wireless> table if one refers to this
|
||||
device port.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->might_have(
|
||||
wireless => 'App::Netdisco::DB::Result::DevicePortWireless',
|
||||
{ 'foreign.ip' => 'self.ip',
|
||||
'foreign.port' => 'self.port',
|
||||
}
|
||||
);
|
||||
|
||||
=head2 agg_master
|
||||
|
||||
Returns another row from the C<device_port> table if this port is slave
|
||||
to another in a link aggregate.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->belongs_to(
|
||||
agg_master => 'App::Netdisco::DB::Result::DevicePort', {
|
||||
'foreign.ip' => 'self.ip',
|
||||
'foreign.port' => 'self.slave_of',
|
||||
}, {
|
||||
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',
|
||||
sub {
|
||||
my $args = shift;
|
||||
return {
|
||||
"$args->{foreign_alias}.ip" => { '=' =>
|
||||
$args->{self_resultsource}->schema->resultset('DeviceIp')
|
||||
->search({alias => { -ident => "$args->{self_alias}.remote_ip"}},
|
||||
{rows => 1, columns => 'ip', alias => 'devipsub'})->as_query }
|
||||
};
|
||||
},
|
||||
{ join_type => 'LEFT' },
|
||||
);
|
||||
|
||||
=head2 vlans
|
||||
|
||||
As compared to C<port_vlans>, 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<vlan_count>.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->many_to_many( vlans => 'all_port_vlans', '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 neighbor
|
||||
|
||||
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 native
|
||||
|
||||
An alias for the C<vlan> column, which stores the PVID (that is, the VLAN
|
||||
ID assigned to untagged frames received on the port).
|
||||
|
||||
=cut
|
||||
|
||||
sub native { return (shift)->vlan }
|
||||
|
||||
=head2 vlan_count
|
||||
|
||||
Returns the number of VLANs active on this device port. Enable this column by
|
||||
applying the C<with_vlan_count()> modifier to C<search()>.
|
||||
|
||||
=cut
|
||||
|
||||
sub vlan_count { return (shift)->get_column('vlan_count') }
|
||||
|
||||
=head2 lastchange_stamp
|
||||
|
||||
Formatted version of the C<lastchange> field, accurate to the minute. Enable
|
||||
this column by applying the C<with_times()> 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') }
|
||||
|
||||
=head2 base64url_port
|
||||
|
||||
Returns a Base64 encoded version of the C<port> column value suitable for use
|
||||
in a URL.
|
||||
|
||||
=cut
|
||||
|
||||
sub base64url_port { return encode_base64url((shift)->port) }
|
||||
|
||||
=head2 net_mac
|
||||
|
||||
Returns the C<mac> column instantiated into a L<NetAddr::MAC> object.
|
||||
|
||||
=cut
|
||||
|
||||
sub net_mac { return NetAddr::MAC->new(mac => (shift)->mac) }
|
||||
|
||||
=head2 last_comment
|
||||
|
||||
Returns the most recent comment from the logs for this device port.
|
||||
|
||||
=cut
|
||||
|
||||
sub last_comment {
|
||||
my $row = (shift)->logs->search(undef,
|
||||
{ order_by => { -desc => 'creation' }, rows => 1 })->first;
|
||||
return ($row ? $row->log : '');
|
||||
}
|
||||
|
||||
1;
|
||||
60
lib/App/Netdisco/DB/Result/DevicePortLog.pm
Normal file
60
lib/App/Netdisco/DB/Result/DevicePortLog.pm
Normal file
@@ -0,0 +1,60 @@
|
||||
use utf8;
|
||||
package App::Netdisco::DB::Result::DevicePortLog;
|
||||
|
||||
# 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_log");
|
||||
__PACKAGE__->add_columns(
|
||||
"id",
|
||||
{
|
||||
data_type => "integer",
|
||||
is_auto_increment => 1,
|
||||
is_nullable => 0,
|
||||
sequence => "device_port_log_id_seq",
|
||||
},
|
||||
"ip",
|
||||
{ data_type => "inet", is_nullable => 1 },
|
||||
"port",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"reason",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"log",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"username",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"userip",
|
||||
{ data_type => "inet", is_nullable => 1 },
|
||||
"action",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"creation",
|
||||
{
|
||||
data_type => "timestamp",
|
||||
default_value => \"current_timestamp",
|
||||
is_nullable => 1,
|
||||
original => { default_value => \"now()" },
|
||||
},
|
||||
);
|
||||
|
||||
__PACKAGE__->set_primary_key("id");
|
||||
|
||||
=head1 ADDITIONAL COLUMNS
|
||||
|
||||
=head2 creation_stamp
|
||||
|
||||
Formatted version of the C<creation> field, accurate to the second.
|
||||
|
||||
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:23
|
||||
|
||||
=cut
|
||||
|
||||
sub creation_stamp { return (shift)->get_column('creation_stamp') }
|
||||
|
||||
1;
|
||||
57
lib/App/Netdisco/DB/Result/DevicePortPower.pm
Normal file
57
lib/App/Netdisco/DB/Result/DevicePortPower.pm
Normal file
@@ -0,0 +1,57 @@
|
||||
use utf8;
|
||||
package App::Netdisco::DB::Result::DevicePortPower;
|
||||
|
||||
# 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_power");
|
||||
__PACKAGE__->add_columns(
|
||||
"ip",
|
||||
{ data_type => "inet", is_nullable => 0 },
|
||||
"port",
|
||||
{ data_type => "text", is_nullable => 0 },
|
||||
"module",
|
||||
{ data_type => "integer", is_nullable => 1 },
|
||||
"admin",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"status",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"class",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"power",
|
||||
{ data_type => "integer", 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:sHcdItRUFUOAtIZQjdWbcg
|
||||
|
||||
=head1 RELATIONSHIPS
|
||||
|
||||
=head2 port
|
||||
|
||||
Returns the entry from the C<port> table for which this Power entry applies.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->belongs_to( port => 'App::Netdisco::DB::Result::DevicePort', {
|
||||
'foreign.ip' => 'self.ip', 'foreign.port' => 'self.port',
|
||||
});
|
||||
|
||||
=head2 device_module
|
||||
|
||||
Returns the entry from the C<device_power> table for which this Power entry
|
||||
applies.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->belongs_to( device_module => 'App::Netdisco::DB::Result::DevicePower', {
|
||||
'foreign.ip' => 'self.ip', 'foreign.module' => 'self.module',
|
||||
});
|
||||
|
||||
1;
|
||||
67
lib/App/Netdisco/DB/Result/DevicePortSsid.pm
Normal file
67
lib/App/Netdisco/DB/Result/DevicePortSsid.pm
Normal file
@@ -0,0 +1,67 @@
|
||||
use utf8;
|
||||
package App::Netdisco::DB::Result::DevicePortSsid;
|
||||
|
||||
# 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_ssid");
|
||||
__PACKAGE__->add_columns(
|
||||
"ip",
|
||||
{ data_type => "inet", is_nullable => 0 },
|
||||
"port",
|
||||
{ data_type => "text", is_nullable => 0 },
|
||||
"ssid",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"broadcast",
|
||||
{ data_type => "boolean", is_nullable => 1 },
|
||||
"bssid",
|
||||
{ data_type => "macaddr", 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:zvgylKzUQtizJZCe1rEdUg
|
||||
|
||||
=head1 RELATIONSHIPS
|
||||
|
||||
=head2 device
|
||||
|
||||
Returns the entry from the C<device> table which hosts this SSID.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->belongs_to( device => 'App::Netdisco::DB::Result::Device', 'ip' );
|
||||
|
||||
=head2 port
|
||||
|
||||
Returns the entry from the C<port> table which corresponds to this SSID.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->belongs_to( port => 'App::Netdisco::DB::Result::DevicePort', {
|
||||
'foreign.ip' => 'self.ip', 'foreign.port' => 'self.port',
|
||||
});
|
||||
|
||||
=head2 nodes
|
||||
|
||||
Returns the set of Nodes whose MAC addresses are associated with this Device
|
||||
Port SSID.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->has_many( nodes => 'App::Netdisco::DB::Result::Node',
|
||||
{
|
||||
'foreign.switch' => 'self.ip',
|
||||
'foreign.port' => 'self.port',
|
||||
},
|
||||
{ join_type => 'LEFT',
|
||||
cascade_copy => 0, cascade_update => 0, cascade_delete => 0 },
|
||||
);
|
||||
|
||||
# You can replace this text with custom code or comments, and it will be preserved on regeneration
|
||||
1;
|
||||
76
lib/App/Netdisco/DB/Result/DevicePortVlan.pm
Normal file
76
lib/App/Netdisco/DB/Result/DevicePortVlan.pm
Normal file
@@ -0,0 +1,76 @@
|
||||
use utf8;
|
||||
package App::Netdisco::DB::Result::DevicePortVlan;
|
||||
|
||||
# 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_vlan");
|
||||
__PACKAGE__->add_columns(
|
||||
"ip",
|
||||
{ data_type => "inet", is_nullable => 0 },
|
||||
"port",
|
||||
{ data_type => "text", is_nullable => 0 },
|
||||
"vlan",
|
||||
{ data_type => "integer", is_nullable => 0 },
|
||||
"native",
|
||||
{ data_type => "boolean", default_value => \"false", is_nullable => 0 },
|
||||
"creation",
|
||||
{
|
||||
data_type => "timestamp",
|
||||
default_value => \"current_timestamp",
|
||||
is_nullable => 1,
|
||||
original => { default_value => \"now()" },
|
||||
},
|
||||
"last_discover",
|
||||
{
|
||||
data_type => "timestamp",
|
||||
default_value => \"current_timestamp",
|
||||
is_nullable => 1,
|
||||
original => { default_value => \"now()" },
|
||||
},
|
||||
"vlantype",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
);
|
||||
__PACKAGE__->set_primary_key("ip", "port", "vlan", "native");
|
||||
|
||||
|
||||
# Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:/3KLjJ3D18pGaPEaw9EU5w
|
||||
|
||||
=head1 RELATIONSHIPS
|
||||
|
||||
=head2 device
|
||||
|
||||
Returns the entry from the C<device> table which hosts the Port on which this
|
||||
VLAN is configured.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->belongs_to( device => 'App::Netdisco::DB::Result::Device', 'ip' );
|
||||
|
||||
=head2 port
|
||||
|
||||
Returns the entry from the C<port> table on which this VLAN is configured.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->belongs_to( port => 'App::Netdisco::DB::Result::DevicePort', {
|
||||
'foreign.ip' => 'self.ip', 'foreign.port' => 'self.port',
|
||||
});
|
||||
|
||||
=head2 vlan
|
||||
|
||||
Returns the entry from the C<device_vlan> table describing this VLAN in
|
||||
detail, typically in order that the C<name> can be retrieved.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->belongs_to( vlan => 'App::Netdisco::DB::Result::DeviceVlan', {
|
||||
'foreign.ip' => 'self.ip', 'foreign.vlan' => 'self.vlan',
|
||||
});
|
||||
|
||||
1;
|
||||
66
lib/App/Netdisco/DB/Result/DevicePortWireless.pm
Normal file
66
lib/App/Netdisco/DB/Result/DevicePortWireless.pm
Normal file
@@ -0,0 +1,66 @@
|
||||
use utf8;
|
||||
package App::Netdisco::DB::Result::DevicePortWireless;
|
||||
|
||||
# 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_wireless");
|
||||
__PACKAGE__->add_columns(
|
||||
"ip",
|
||||
{ data_type => "inet", is_nullable => 0 },
|
||||
"port",
|
||||
{ data_type => "text", is_nullable => 0 },
|
||||
"channel",
|
||||
{ data_type => "integer", is_nullable => 1 },
|
||||
"power",
|
||||
{ data_type => "integer", 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:T5GmnCj/9BB7meiGZ3xN7g
|
||||
|
||||
=head1 RELATIONSHIPS
|
||||
|
||||
=head2 device
|
||||
|
||||
Returns the entry from the C<device> table which hosts this wireless port.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->belongs_to( device => 'App::Netdisco::DB::Result::Device', 'ip' );
|
||||
|
||||
=head2 port
|
||||
|
||||
Returns the entry from the C<port> table which corresponds to this wireless
|
||||
interface.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->belongs_to( port => 'App::Netdisco::DB::Result::DevicePort', {
|
||||
'foreign.ip' => 'self.ip', 'foreign.port' => 'self.port',
|
||||
});
|
||||
|
||||
=head2 nodes
|
||||
|
||||
Returns the set of Nodes whose MAC addresses are associated with this Device
|
||||
Port Wireless.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->has_many( nodes => 'App::Netdisco::DB::Result::Node',
|
||||
{
|
||||
'foreign.switch' => 'self.ip',
|
||||
'foreign.port' => 'self.port',
|
||||
},
|
||||
{ join_type => 'LEFT',
|
||||
cascade_copy => 0, cascade_update => 0, cascade_delete => 0 },
|
||||
);
|
||||
|
||||
# You can replace this text with custom code or comments, and it will be preserved on regeneration
|
||||
1;
|
||||
49
lib/App/Netdisco/DB/Result/DevicePower.pm
Normal file
49
lib/App/Netdisco/DB/Result/DevicePower.pm
Normal file
@@ -0,0 +1,49 @@
|
||||
use utf8;
|
||||
package App::Netdisco::DB::Result::DevicePower;
|
||||
|
||||
# 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_power");
|
||||
__PACKAGE__->add_columns(
|
||||
"ip",
|
||||
{ data_type => "inet", is_nullable => 0 },
|
||||
"module",
|
||||
{ data_type => "integer", is_nullable => 0 },
|
||||
"power",
|
||||
{ data_type => "integer", is_nullable => 1 },
|
||||
"status",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
);
|
||||
__PACKAGE__->set_primary_key("ip", "module");
|
||||
|
||||
|
||||
# Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:awZRI/IH2VewzGlxISsr7w
|
||||
|
||||
=head1 RELATIONSHIPS
|
||||
|
||||
=head2 device
|
||||
|
||||
Returns the entry from the C<device> table on which this power module was discovered.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->belongs_to( device => 'App::Netdisco::DB::Result::Device', 'ip' );
|
||||
|
||||
=head2 ports
|
||||
|
||||
Returns the set of PoE ports associated with a power module.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->has_many( ports => 'App::Netdisco::DB::Result::DevicePortPower', {
|
||||
'foreign.ip' => 'self.ip', 'foreign.module' => 'self.module',
|
||||
} );
|
||||
|
||||
# You can replace this text with custom code or comments, and it will be preserved on regeneration
|
||||
1;
|
||||
42
lib/App/Netdisco/DB/Result/DeviceRoute.pm
Normal file
42
lib/App/Netdisco/DB/Result/DeviceRoute.pm
Normal file
@@ -0,0 +1,42 @@
|
||||
use utf8;
|
||||
package App::Netdisco::DB::Result::DeviceRoute;
|
||||
|
||||
# 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_route");
|
||||
__PACKAGE__->add_columns(
|
||||
"ip",
|
||||
{ data_type => "inet", is_nullable => 0 },
|
||||
"network",
|
||||
{ data_type => "cidr", is_nullable => 0 },
|
||||
"creation",
|
||||
{
|
||||
data_type => "timestamp",
|
||||
default_value => \"current_timestamp",
|
||||
is_nullable => 1,
|
||||
original => { default_value => \"now()" },
|
||||
},
|
||||
"dest",
|
||||
{ data_type => "inet", is_nullable => 0 },
|
||||
"last_discover",
|
||||
{
|
||||
data_type => "timestamp",
|
||||
default_value => \"current_timestamp",
|
||||
is_nullable => 1,
|
||||
original => { default_value => \"now()" },
|
||||
},
|
||||
);
|
||||
__PACKAGE__->set_primary_key("ip", "network", "dest");
|
||||
|
||||
|
||||
# Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:3jcvPP60E5BvwnUbXql7mQ
|
||||
|
||||
|
||||
# You can replace this text with custom code or comments, and it will be preserved on regeneration
|
||||
1;
|
||||
113
lib/App/Netdisco/DB/Result/DeviceVlan.pm
Normal file
113
lib/App/Netdisco/DB/Result/DeviceVlan.pm
Normal file
@@ -0,0 +1,113 @@
|
||||
use utf8;
|
||||
package App::Netdisco::DB::Result::DeviceVlan;
|
||||
|
||||
# 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_vlan");
|
||||
__PACKAGE__->add_columns(
|
||||
"ip",
|
||||
{ data_type => "inet", is_nullable => 0 },
|
||||
"vlan",
|
||||
{ data_type => "integer", is_nullable => 0 },
|
||||
"description",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"creation",
|
||||
{
|
||||
data_type => "timestamp",
|
||||
default_value => \"current_timestamp",
|
||||
is_nullable => 1,
|
||||
original => { default_value => \"now()" },
|
||||
},
|
||||
"last_discover",
|
||||
{
|
||||
data_type => "timestamp",
|
||||
default_value => \"current_timestamp",
|
||||
is_nullable => 1,
|
||||
original => { default_value => \"now()" },
|
||||
},
|
||||
);
|
||||
__PACKAGE__->set_primary_key("ip", "vlan");
|
||||
|
||||
|
||||
# Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:hBJRcdzOic4d3u4pD1m8iA
|
||||
|
||||
=head1 RELATIONSHIPS
|
||||
|
||||
=head2 device
|
||||
|
||||
Returns the entry from the C<device> table on which this VLAN entry was discovered.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->belongs_to( device => 'App::Netdisco::DB::Result::Device', 'ip' );
|
||||
|
||||
=head2 port_vlans_tagged
|
||||
|
||||
Link relationship for C<tagged_ports>, see below.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->has_many( port_vlans_tagged => 'App::Netdisco::DB::Result::DevicePortVlan',
|
||||
sub {
|
||||
my $args = shift;
|
||||
return {
|
||||
"$args->{foreign_alias}.ip" => { -ident => "$args->{self_alias}.ip" },
|
||||
"$args->{foreign_alias}.vlan" => { -ident => "$args->{self_alias}.vlan" },
|
||||
-not_bool => "$args->{foreign_alias}.native",
|
||||
};
|
||||
},
|
||||
{ cascade_copy => 0, cascade_update => 0, cascade_delete => 0 }
|
||||
);
|
||||
|
||||
=head2 port_vlans_untagged
|
||||
|
||||
Link relationship to support C<untagged_ports>, see below.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->has_many( port_vlans_untagged => 'App::Netdisco::DB::Result::DevicePortVlan',
|
||||
sub {
|
||||
my $args = shift;
|
||||
return {
|
||||
"$args->{foreign_alias}.ip" => { -ident => "$args->{self_alias}.ip" },
|
||||
"$args->{foreign_alias}.vlan" => { -ident => "$args->{self_alias}.vlan" },
|
||||
-bool => "$args->{foreign_alias}.native",
|
||||
};
|
||||
},
|
||||
{ cascade_copy => 0, cascade_update => 0, cascade_delete => 0 }
|
||||
);
|
||||
|
||||
=head2 ports
|
||||
|
||||
Link relationship to support C<ports>.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->has_many( ports => 'App::Netdisco::DB::Result::DevicePortVlan',
|
||||
{ 'foreign.ip' => 'self.ip', 'foreign.vlan' => 'self.vlan' },
|
||||
{ cascade_copy => 0, cascade_update => 0, cascade_delete => 0 }
|
||||
);
|
||||
|
||||
=head2 tagged_ports
|
||||
|
||||
Returns the set of Device Ports on which this VLAN is configured to be tagged.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->many_to_many( tagged_ports => 'port_vlans_tagged', 'port' );
|
||||
|
||||
=head2 untagged_ports
|
||||
|
||||
Returns the set of Device Ports on which this VLAN is an untagged VLAN.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->many_to_many( untagged_ports => 'port_vlans_untagged', 'port' );
|
||||
|
||||
1;
|
||||
41
lib/App/Netdisco/DB/Result/Log.pm
Normal file
41
lib/App/Netdisco/DB/Result/Log.pm
Normal file
@@ -0,0 +1,41 @@
|
||||
use utf8;
|
||||
package App::Netdisco::DB::Result::Log;
|
||||
|
||||
# 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("log");
|
||||
__PACKAGE__->add_columns(
|
||||
"id",
|
||||
{
|
||||
data_type => "integer",
|
||||
is_auto_increment => 1,
|
||||
is_nullable => 0,
|
||||
sequence => "log_id_seq",
|
||||
},
|
||||
"creation",
|
||||
{
|
||||
data_type => "timestamp",
|
||||
default_value => \"current_timestamp",
|
||||
is_nullable => 1,
|
||||
original => { default_value => \"now()" },
|
||||
},
|
||||
"class",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"entry",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"logfile",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
);
|
||||
|
||||
|
||||
# Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:eonwOHvvzWm88Ug+IGKuzg
|
||||
|
||||
|
||||
# You can replace this text with custom code or comments, and it will be preserved on regeneration
|
||||
1;
|
||||
202
lib/App/Netdisco/DB/Result/Node.pm
Normal file
202
lib/App/Netdisco/DB/Result/Node.pm
Normal file
@@ -0,0 +1,202 @@
|
||||
use utf8;
|
||||
package App::Netdisco::DB::Result::Node;
|
||||
|
||||
# Created by DBIx::Class::Schema::Loader
|
||||
# DO NOT MODIFY THE FIRST PART OF THIS FILE
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use NetAddr::MAC;
|
||||
|
||||
use base 'DBIx::Class::Core';
|
||||
__PACKAGE__->table("node");
|
||||
__PACKAGE__->add_columns(
|
||||
"mac",
|
||||
{ data_type => "macaddr", is_nullable => 0 },
|
||||
"switch",
|
||||
{ data_type => "inet", is_nullable => 0 },
|
||||
"port",
|
||||
{ data_type => "text", is_nullable => 0 },
|
||||
"active",
|
||||
{ data_type => "boolean", is_nullable => 1 },
|
||||
"oui",
|
||||
{ data_type => "varchar", is_nullable => 1, size => 8 },
|
||||
"time_first",
|
||||
{
|
||||
data_type => "timestamp",
|
||||
default_value => \"current_timestamp",
|
||||
is_nullable => 1,
|
||||
original => { default_value => \"now()" },
|
||||
},
|
||||
"time_recent",
|
||||
{
|
||||
data_type => "timestamp",
|
||||
default_value => \"current_timestamp",
|
||||
is_nullable => 1,
|
||||
original => { default_value => \"now()" },
|
||||
},
|
||||
"time_last",
|
||||
{
|
||||
data_type => "timestamp",
|
||||
default_value => \"current_timestamp",
|
||||
is_nullable => 1,
|
||||
original => { default_value => \"now()" },
|
||||
},
|
||||
"vlan",
|
||||
{ data_type => "text", is_nullable => 0, default_value => '0' },
|
||||
);
|
||||
__PACKAGE__->set_primary_key("mac", "switch", "port", "vlan");
|
||||
|
||||
|
||||
# Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:sGGyKEfUkoIFVtmj1wnH7A
|
||||
|
||||
=head1 RELATIONSHIPS
|
||||
|
||||
=head2 device
|
||||
|
||||
Returns the single C<device> to which this Node entry was associated at the
|
||||
time of discovery.
|
||||
|
||||
The JOIN is of type LEFT, in case the C<device> is no longer present in the
|
||||
database but the relation is being used in C<search()>.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->belongs_to( device => 'App::Netdisco::DB::Result::Device',
|
||||
{ 'foreign.ip' => 'self.switch' }, { join_type => 'LEFT' } );
|
||||
|
||||
=head2 device_port
|
||||
|
||||
Returns the single C<device_port> to which this Node entry was associated at
|
||||
the time of discovery.
|
||||
|
||||
The JOIN is of type LEFT, in case the C<device> is no longer present in the
|
||||
database but the relation is being used in C<search()>.
|
||||
|
||||
=cut
|
||||
|
||||
# device port may have been deleted (reconfigured modules?) but node remains
|
||||
__PACKAGE__->belongs_to( device_port => 'App::Netdisco::DB::Result::DevicePort',
|
||||
{ 'foreign.ip' => 'self.switch', 'foreign.port' => 'self.port' },
|
||||
{ join_type => 'LEFT' }
|
||||
);
|
||||
|
||||
=head2 wireless_port
|
||||
|
||||
Returns the single C<wireless_port> to which this Node entry was associated at
|
||||
the time of discovery.
|
||||
|
||||
The JOIN is of type LEFT, in case the C<device> is no longer present in the
|
||||
database but the relation is being used in C<search()>.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->belongs_to(
|
||||
wireless_port => 'App::Netdisco::DB::Result::DevicePortWireless',
|
||||
{ 'foreign.ip' => 'self.switch', 'foreign.port' => 'self.port' },
|
||||
{ join_type => 'LEFT' }
|
||||
);
|
||||
|
||||
=head2 ips
|
||||
|
||||
Returns the set of C<node_ip> entries associated with this Node. That is, the
|
||||
IP addresses which this MAC address was hosting at the time of discovery.
|
||||
|
||||
Note that the Active status of the returned IP entries will all be the same as
|
||||
the current Node's.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->has_many( ips => 'App::Netdisco::DB::Result::NodeIp',
|
||||
{ 'foreign.mac' => 'self.mac', 'foreign.active' => 'self.active' } );
|
||||
|
||||
=head2 ip4s
|
||||
|
||||
Same as C<ips> but for IPv4 only.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->has_many( ip4s => 'App::Netdisco::DB::Result::Virtual::NodeIp4',
|
||||
{ 'foreign.mac' => 'self.mac', 'foreign.active' => 'self.active' } );
|
||||
|
||||
=head2 ip6s
|
||||
|
||||
Same as C<ips> but for IPv6 only.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->has_many( ip6s => 'App::Netdisco::DB::Result::Virtual::NodeIp6',
|
||||
{ 'foreign.mac' => 'self.mac', 'foreign.active' => 'self.active' } );
|
||||
|
||||
=head2 netbios
|
||||
|
||||
Returns the C<node_nbt> entry associated with this Node if one exists. That
|
||||
is, the NetBIOS information of this MAC address at the time of discovery.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->might_have( netbios => 'App::Netdisco::DB::Result::NodeNbt',
|
||||
{ 'foreign.mac' => 'self.mac' } );
|
||||
|
||||
=head2 wireless
|
||||
|
||||
Returns the set of C<node_wireless> entries associated with this Node. That
|
||||
is, the SSIDs and wireless statistics associated with this MAC address
|
||||
at the time of discovery.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->has_many( wireless => 'App::Netdisco::DB::Result::NodeWireless',
|
||||
{ 'foreign.mac' => 'self.mac' } );
|
||||
|
||||
=head2 oui
|
||||
|
||||
Returns the C<oui> table entry matching this Node. 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', 'oui',
|
||||
{ join_type => 'LEFT' } );
|
||||
|
||||
=head1 ADDITIONAL COLUMNS
|
||||
|
||||
=head2 time_first_stamp
|
||||
|
||||
Formatted version of the C<time_first> field, accurate to the minute.
|
||||
|
||||
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 time_first_stamp { return (shift)->get_column('time_first_stamp') }
|
||||
|
||||
=head2 time_last_stamp
|
||||
|
||||
Formatted version of the C<time_last> field, accurate to the minute.
|
||||
|
||||
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 time_last_stamp { return (shift)->get_column('time_last_stamp') }
|
||||
|
||||
=head2 net_mac
|
||||
|
||||
Returns the C<mac> column instantiated into a L<NetAddr::MAC> object.
|
||||
|
||||
=cut
|
||||
|
||||
sub net_mac { return NetAddr::MAC->new(mac => (shift)->mac) }
|
||||
|
||||
1;
|
||||
230
lib/App/Netdisco/DB/Result/NodeIp.pm
Normal file
230
lib/App/Netdisco/DB/Result/NodeIp.pm
Normal file
@@ -0,0 +1,230 @@
|
||||
use utf8;
|
||||
package App::Netdisco::DB::Result::NodeIp;
|
||||
|
||||
# Created by DBIx::Class::Schema::Loader
|
||||
# DO NOT MODIFY THE FIRST PART OF THIS FILE
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use NetAddr::MAC;
|
||||
|
||||
use base 'DBIx::Class::Core';
|
||||
__PACKAGE__->table("node_ip");
|
||||
__PACKAGE__->add_columns(
|
||||
"mac",
|
||||
{ data_type => "macaddr", is_nullable => 0 },
|
||||
"ip",
|
||||
{ data_type => "inet", is_nullable => 0 },
|
||||
"dns",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"active",
|
||||
{ data_type => "boolean", is_nullable => 1 },
|
||||
"time_first",
|
||||
{
|
||||
data_type => "timestamp",
|
||||
default_value => \"current_timestamp",
|
||||
is_nullable => 1,
|
||||
original => { default_value => \"now()" },
|
||||
},
|
||||
"time_last",
|
||||
{
|
||||
data_type => "timestamp",
|
||||
default_value => \"current_timestamp",
|
||||
is_nullable => 1,
|
||||
original => { default_value => \"now()" },
|
||||
},
|
||||
);
|
||||
__PACKAGE__->set_primary_key("mac", "ip");
|
||||
|
||||
|
||||
# Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:9+CuvuVWH88WxAf6IBij8g
|
||||
|
||||
=head1 RELATIONSHIPS
|
||||
|
||||
=head2 oui
|
||||
|
||||
Returns the C<oui> table entry matching this Node. 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' }
|
||||
);
|
||||
|
||||
=head2 node_ips
|
||||
|
||||
Returns the set of all C<node_ip> entries which are associated together with
|
||||
this IP. That is, all the IP addresses hosted on the same interface (MAC
|
||||
address) as the current Node IP entry.
|
||||
|
||||
Note that the set will include the original Node IP object itself. If you wish
|
||||
to find the I<other> IPs excluding this one, see the C<ip_aliases> helper
|
||||
routine, below.
|
||||
|
||||
Remember you can pass a filter to this method to find only active or inactive
|
||||
nodes, but do take into account that both the C<node> and C<node_ip> tables
|
||||
include independent C<active> fields.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->has_many( node_ips => 'App::Netdisco::DB::Result::NodeIp',
|
||||
{ 'foreign.mac' => 'self.mac' } );
|
||||
|
||||
=head2 nodes
|
||||
|
||||
Returns the set of C<node> entries associated with this IP. That is, all the
|
||||
MAC addresses recorded which have ever hosted this IP Address.
|
||||
|
||||
Remember you can pass a filter to this method to find only active or inactive
|
||||
nodes, but do take into account that both the C<node> and C<node_ip> tables
|
||||
include independent C<active> fields.
|
||||
|
||||
See also the C<node_sightings> helper routine, below.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->has_many( nodes => 'App::Netdisco::DB::Result::Node',
|
||||
{ 'foreign.mac' => 'self.mac' } );
|
||||
|
||||
=head2 netbios
|
||||
|
||||
Returns the set of C<node_nbt> entries associated with the MAC of this IP.
|
||||
That is, all the NetBIOS entries recorded which shared the same MAC with this
|
||||
IP Address.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->has_many( netbios => 'App::Netdisco::DB::Result::NodeNbt',
|
||||
{ 'foreign.mac' => 'self.mac' } );
|
||||
|
||||
my $search_attr = {
|
||||
order_by => {'-desc' => 'time_last'},
|
||||
'+columns' => {
|
||||
time_first_stamp => \"to_char(time_first, 'YYYY-MM-DD HH24:MI')",
|
||||
time_last_stamp => \"to_char(time_last, 'YYYY-MM-DD HH24:MI')",
|
||||
},
|
||||
};
|
||||
|
||||
=head2 ip_aliases( \%cond, \%attrs? )
|
||||
|
||||
Returns the set of other C<node_ip> entries hosted on the same interface (MAC
|
||||
address) as the current Node IP, excluding the current IP itself.
|
||||
|
||||
Remember you can pass a filter to this method to find only active or inactive
|
||||
nodes, but do take into account that both the C<node> and C<node_ip> tables
|
||||
include independent C<active> fields.
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
Results are ordered by time last seen.
|
||||
|
||||
=item *
|
||||
|
||||
Additional columns C<time_first_stamp> and C<time_last_stamp> provide
|
||||
preformatted timestamps of the C<time_first> and C<time_last> fields.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub ip_aliases {
|
||||
my ($row, $cond, $attrs) = @_;
|
||||
|
||||
my $rs = $row->node_ips({ip => { '!=' => $row->ip }});
|
||||
|
||||
return $rs
|
||||
->search_rs({}, $search_attr)
|
||||
->search($cond, $attrs);
|
||||
}
|
||||
|
||||
=head2 node_sightings( \%cond, \%attrs? )
|
||||
|
||||
Returns the set of C<node> entries associated with this IP. That is, all the
|
||||
MAC addresses recorded which have ever hosted this IP Address.
|
||||
|
||||
Remember you can pass a filter to this method to find only active or inactive
|
||||
nodes, but do take into account that both the C<node> and C<node_ip> tables
|
||||
include independent C<active> fields.
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
Results are ordered by time last seen.
|
||||
|
||||
=item *
|
||||
|
||||
Additional columns C<time_first_stamp> and C<time_last_stamp> provide
|
||||
preformatted timestamps of the C<time_first> and C<time_last> fields.
|
||||
|
||||
=item *
|
||||
|
||||
A JOIN is performed on the Device table and the Device DNS column prefetched.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub node_sightings {
|
||||
my ($row, $cond, $attrs) = @_;
|
||||
|
||||
return $row
|
||||
->nodes({}, {
|
||||
'+columns' => [qw/ device.dns /],
|
||||
join => 'device',
|
||||
})
|
||||
->search_rs({}, $search_attr)
|
||||
->search($cond, $attrs);
|
||||
}
|
||||
|
||||
=head1 ADDITIONAL COLUMNS
|
||||
|
||||
=head2 time_first_stamp
|
||||
|
||||
Formatted version of the C<time_first> field, accurate to the minute.
|
||||
|
||||
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 time_first_stamp { return (shift)->get_column('time_first_stamp') }
|
||||
|
||||
=head2 time_last_stamp
|
||||
|
||||
Formatted version of the C<time_last> field, accurate to the minute.
|
||||
|
||||
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 time_last_stamp { return (shift)->get_column('time_last_stamp') }
|
||||
|
||||
=head2 net_mac
|
||||
|
||||
Returns the C<mac> column instantiated into a L<NetAddr::MAC> object.
|
||||
|
||||
=cut
|
||||
|
||||
sub net_mac { return NetAddr::MAC->new(mac => (shift)->mac) }
|
||||
|
||||
1;
|
||||
37
lib/App/Netdisco/DB/Result/NodeMonitor.pm
Normal file
37
lib/App/Netdisco/DB/Result/NodeMonitor.pm
Normal file
@@ -0,0 +1,37 @@
|
||||
use utf8;
|
||||
package App::Netdisco::DB::Result::NodeMonitor;
|
||||
|
||||
# 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("node_monitor");
|
||||
__PACKAGE__->add_columns(
|
||||
"mac",
|
||||
{ data_type => "macaddr", is_nullable => 0 },
|
||||
"active",
|
||||
{ data_type => "boolean", is_nullable => 1 },
|
||||
"why",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"cc",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"date",
|
||||
{
|
||||
data_type => "timestamp",
|
||||
default_value => \"current_timestamp",
|
||||
is_nullable => 1,
|
||||
original => { default_value => \"now()" },
|
||||
},
|
||||
);
|
||||
__PACKAGE__->set_primary_key("mac");
|
||||
|
||||
|
||||
# Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:0prRdz2XYlFuE+nahsI2Yg
|
||||
|
||||
|
||||
# You can replace this text with custom code or comments, and it will be preserved on regeneration
|
||||
1;
|
||||
187
lib/App/Netdisco/DB/Result/NodeNbt.pm
Normal file
187
lib/App/Netdisco/DB/Result/NodeNbt.pm
Normal file
@@ -0,0 +1,187 @@
|
||||
use utf8;
|
||||
package App::Netdisco::DB::Result::NodeNbt;
|
||||
|
||||
# Created by DBIx::Class::Schema::Loader
|
||||
# DO NOT MODIFY THE FIRST PART OF THIS FILE
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use NetAddr::MAC;
|
||||
|
||||
use base 'DBIx::Class::Core';
|
||||
__PACKAGE__->table("node_nbt");
|
||||
__PACKAGE__->add_columns(
|
||||
"mac",
|
||||
{ data_type => "macaddr", is_nullable => 0 },
|
||||
"ip",
|
||||
{ data_type => "inet", is_nullable => 1 },
|
||||
"nbname",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"domain",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"server",
|
||||
{ data_type => "boolean", is_nullable => 1 },
|
||||
"nbuser",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"active",
|
||||
{ data_type => "boolean", is_nullable => 1 },
|
||||
"time_first",
|
||||
{
|
||||
data_type => "timestamp",
|
||||
default_value => \"current_timestamp",
|
||||
is_nullable => 1,
|
||||
original => { default_value => \"now()" },
|
||||
},
|
||||
"time_last",
|
||||
{
|
||||
data_type => "timestamp",
|
||||
default_value => \"current_timestamp",
|
||||
is_nullable => 1,
|
||||
original => { default_value => \"now()" },
|
||||
},
|
||||
);
|
||||
__PACKAGE__->set_primary_key("mac");
|
||||
|
||||
|
||||
# Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:XFpxaGAWE13iizQIuVOP3g
|
||||
|
||||
=head1 RELATIONSHIPS
|
||||
|
||||
=head2 oui
|
||||
|
||||
Returns the C<oui> table entry matching this Node. 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' }
|
||||
);
|
||||
|
||||
=head2 nodes
|
||||
|
||||
Returns the set of C<node> entries associated with this IP. That is, all the
|
||||
MAC addresses recorded which have ever hosted this IP Address.
|
||||
|
||||
Remember you can pass a filter to this method to find only active or inactive
|
||||
nodes, but do take into account that both the C<node> and C<node_nbt> tables
|
||||
include independent C<active> fields.
|
||||
|
||||
See also the C<node_sightings> helper routine, below.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->has_many( nodes => 'App::Netdisco::DB::Result::Node',
|
||||
{ 'foreign.mac' => 'self.mac' } );
|
||||
|
||||
|
||||
=head2 nodeips
|
||||
|
||||
Returns the set of C<node_ip> entries associated with this NetBIOS entry.
|
||||
That is, the IP addresses which the same MAC address at the time of discovery.
|
||||
|
||||
Note that the Active status of the returned IP entries will all be the same
|
||||
as the current NetBIOS entry.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->has_many( nodeips => 'App::Netdisco::DB::Result::NodeIp',
|
||||
{ 'foreign.mac' => 'self.mac', 'foreign.active' => 'self.active' } );
|
||||
|
||||
|
||||
my $search_attr = {
|
||||
order_by => {'-desc' => 'time_last'},
|
||||
'+columns' => {
|
||||
time_first_stamp => \"to_char(time_first, 'YYYY-MM-DD HH24:MI')",
|
||||
time_last_stamp => \"to_char(time_last, 'YYYY-MM-DD HH24:MI')",
|
||||
},
|
||||
};
|
||||
|
||||
=head2 node_sightings( \%cond, \%attrs? )
|
||||
|
||||
Returns the set of C<node> entries associated with this IP. That is, all the
|
||||
MAC addresses recorded which have ever hosted this IP Address.
|
||||
|
||||
Remember you can pass a filter to this method to find only active or inactive
|
||||
nodes, but do take into account that both the C<node> and C<node_ip> tables
|
||||
include independent C<active> fields.
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
Results are ordered by time last seen.
|
||||
|
||||
=item *
|
||||
|
||||
Additional columns C<time_first_stamp> and C<time_last_stamp> provide
|
||||
preformatted timestamps of the C<time_first> and C<time_last> fields.
|
||||
|
||||
=item *
|
||||
|
||||
A JOIN is performed on the Device table and the Device DNS column prefetched.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub node_sightings {
|
||||
my ($row, $cond, $attrs) = @_;
|
||||
|
||||
return $row
|
||||
->nodes({}, {
|
||||
'+columns' => [qw/ device.dns /],
|
||||
join => 'device',
|
||||
})
|
||||
->search_rs({}, $search_attr)
|
||||
->search($cond, $attrs);
|
||||
}
|
||||
|
||||
=head1 ADDITIONAL COLUMNS
|
||||
|
||||
=head2 time_first_stamp
|
||||
|
||||
Formatted version of the C<time_first> field, accurate to the minute.
|
||||
|
||||
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 time_first_stamp { return (shift)->get_column('time_first_stamp') }
|
||||
|
||||
=head2 time_last_stamp
|
||||
|
||||
Formatted version of the C<time_last> field, accurate to the minute.
|
||||
|
||||
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 time_last_stamp { return (shift)->get_column('time_last_stamp') }
|
||||
|
||||
=head2 net_mac
|
||||
|
||||
Returns the C<mac> column instantiated into a L<NetAddr::MAC> object.
|
||||
|
||||
=cut
|
||||
|
||||
sub net_mac { return NetAddr::MAC->new(mac => (shift)->mac) }
|
||||
|
||||
1;
|
||||
96
lib/App/Netdisco/DB/Result/NodeWireless.pm
Normal file
96
lib/App/Netdisco/DB/Result/NodeWireless.pm
Normal file
@@ -0,0 +1,96 @@
|
||||
use utf8;
|
||||
package App::Netdisco::DB::Result::NodeWireless;
|
||||
|
||||
# Created by DBIx::Class::Schema::Loader
|
||||
# DO NOT MODIFY THE FIRST PART OF THIS FILE
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use NetAddr::MAC;
|
||||
|
||||
use base 'DBIx::Class::Core';
|
||||
__PACKAGE__->table("node_wireless");
|
||||
__PACKAGE__->add_columns(
|
||||
"mac",
|
||||
{ data_type => "macaddr", is_nullable => 0 },
|
||||
"uptime",
|
||||
{ data_type => "integer", is_nullable => 1 },
|
||||
"maxrate",
|
||||
{ data_type => "integer", is_nullable => 1 },
|
||||
"txrate",
|
||||
{ data_type => "integer", is_nullable => 1 },
|
||||
"sigstrength",
|
||||
{ data_type => "integer", is_nullable => 1 },
|
||||
"sigqual",
|
||||
{ data_type => "integer", is_nullable => 1 },
|
||||
"rxpkt",
|
||||
{ data_type => "integer", is_nullable => 1 },
|
||||
"txpkt",
|
||||
{ data_type => "integer", is_nullable => 1 },
|
||||
"rxbyte",
|
||||
{ data_type => "bigint", is_nullable => 1 },
|
||||
"txbyte",
|
||||
{ data_type => "bigint", is_nullable => 1 },
|
||||
"time_last",
|
||||
{
|
||||
data_type => "timestamp",
|
||||
default_value => \"current_timestamp",
|
||||
is_nullable => 1,
|
||||
original => { default_value => \"now()" },
|
||||
},
|
||||
"ssid",
|
||||
{ data_type => "text", is_nullable => 0, default_value => '' },
|
||||
);
|
||||
__PACKAGE__->set_primary_key("mac", "ssid");
|
||||
|
||||
|
||||
# Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:3xsSiWzL85ih3vhdews8Hg
|
||||
|
||||
=head1 RELATIONSHIPS
|
||||
|
||||
=head2 oui
|
||||
|
||||
Returns the C<oui> table entry matching this Node. 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' }
|
||||
);
|
||||
|
||||
=head2 node
|
||||
|
||||
Returns the C<node> table entry matching this wireless entry.
|
||||
|
||||
The JOIN is of type LEFT, in case the C<node> is no longer present in the
|
||||
database but the relation is being used in C<search()>.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->belongs_to( node => 'App::Netdisco::DB::Result::Node',
|
||||
{ 'foreign.mac' => 'self.mac' },
|
||||
{ join_type => 'LEFT' } );
|
||||
|
||||
=head1 ADDITIONAL COLUMNS
|
||||
|
||||
=head2 net_mac
|
||||
|
||||
Returns the C<mac> column instantiated into a L<NetAddr::MAC> object.
|
||||
|
||||
=cut
|
||||
|
||||
sub net_mac { return NetAddr::MAC->new(mac => (shift)->mac) }
|
||||
|
||||
1;
|
||||
28
lib/App/Netdisco/DB/Result/Oui.pm
Normal file
28
lib/App/Netdisco/DB/Result/Oui.pm
Normal file
@@ -0,0 +1,28 @@
|
||||
use utf8;
|
||||
package App::Netdisco::DB::Result::Oui;
|
||||
|
||||
# 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("oui");
|
||||
__PACKAGE__->add_columns(
|
||||
"oui",
|
||||
{ data_type => "varchar", is_nullable => 0, size => 8 },
|
||||
"company",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"abbrev",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
);
|
||||
__PACKAGE__->set_primary_key("oui");
|
||||
|
||||
|
||||
# Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:s51mj6SvstPd4GdNEy9SoA
|
||||
|
||||
|
||||
# You can replace this text with custom code or comments, and it will be preserved on regeneration
|
||||
1;
|
||||
38
lib/App/Netdisco/DB/Result/Process.pm
Normal file
38
lib/App/Netdisco/DB/Result/Process.pm
Normal file
@@ -0,0 +1,38 @@
|
||||
use utf8;
|
||||
package App::Netdisco::DB::Result::Process;
|
||||
|
||||
# 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("process");
|
||||
__PACKAGE__->add_columns(
|
||||
"controller",
|
||||
{ data_type => "integer", is_nullable => 0 },
|
||||
"device",
|
||||
{ data_type => "inet", is_nullable => 0 },
|
||||
"action",
|
||||
{ data_type => "text", is_nullable => 0 },
|
||||
"status",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"count",
|
||||
{ data_type => "integer", is_nullable => 1 },
|
||||
"creation",
|
||||
{
|
||||
data_type => "timestamp",
|
||||
default_value => \"current_timestamp",
|
||||
is_nullable => 1,
|
||||
original => { default_value => \"now()" },
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
# Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:28hTnOo4oNwJabiWWHBgCw
|
||||
|
||||
|
||||
# You can replace this text with custom code or comments, and it will be preserved on regeneration
|
||||
1;
|
||||
33
lib/App/Netdisco/DB/Result/Session.pm
Normal file
33
lib/App/Netdisco/DB/Result/Session.pm
Normal file
@@ -0,0 +1,33 @@
|
||||
use utf8;
|
||||
package App::Netdisco::DB::Result::Session;
|
||||
|
||||
# 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("sessions");
|
||||
__PACKAGE__->add_columns(
|
||||
"id",
|
||||
{ data_type => "char", is_nullable => 0, size => 32 },
|
||||
"creation",
|
||||
{
|
||||
data_type => "timestamp",
|
||||
default_value => \"current_timestamp",
|
||||
is_nullable => 1,
|
||||
original => { default_value => \"now()" },
|
||||
},
|
||||
"a_session",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
);
|
||||
__PACKAGE__->set_primary_key("id");
|
||||
|
||||
|
||||
# Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:khNPh72VjQh8QHayuW/p1w
|
||||
|
||||
|
||||
# You can replace this text with custom code or comments, and it will be preserved on regeneration
|
||||
1;
|
||||
38
lib/App/Netdisco/DB/Result/Subnet.pm
Normal file
38
lib/App/Netdisco/DB/Result/Subnet.pm
Normal file
@@ -0,0 +1,38 @@
|
||||
use utf8;
|
||||
package App::Netdisco::DB::Result::Subnet;
|
||||
|
||||
# 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("subnets");
|
||||
__PACKAGE__->add_columns(
|
||||
"net",
|
||||
{ data_type => "cidr", is_nullable => 0 },
|
||||
"creation",
|
||||
{
|
||||
data_type => "timestamp",
|
||||
default_value => \"current_timestamp",
|
||||
is_nullable => 1,
|
||||
original => { default_value => \"now()" },
|
||||
},
|
||||
"last_discover",
|
||||
{
|
||||
data_type => "timestamp",
|
||||
default_value => \"current_timestamp",
|
||||
is_nullable => 1,
|
||||
original => { default_value => \"now()" },
|
||||
},
|
||||
);
|
||||
__PACKAGE__->set_primary_key("net");
|
||||
|
||||
|
||||
# Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:1EHOfYx8PYOHoTkViZR6OA
|
||||
|
||||
|
||||
# You can replace this text with custom code or comments, and it will be preserved on regeneration
|
||||
1;
|
||||
35
lib/App/Netdisco/DB/Result/Topology.pm
Normal file
35
lib/App/Netdisco/DB/Result/Topology.pm
Normal file
@@ -0,0 +1,35 @@
|
||||
use utf8;
|
||||
package App::Netdisco::DB::Result::Topology;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use base 'DBIx::Class::Core';
|
||||
|
||||
__PACKAGE__->table("topology");
|
||||
|
||||
__PACKAGE__->add_columns(
|
||||
"dev1",
|
||||
{ data_type => "inet", is_nullable => 0 },
|
||||
"port1",
|
||||
{ data_type => "text", is_nullable => 0 },
|
||||
"dev2",
|
||||
{ data_type => "inet", is_nullable => 0 },
|
||||
"port2",
|
||||
{ data_type => "text", is_nullable => 0 },
|
||||
);
|
||||
|
||||
__PACKAGE__->add_unique_constraint(['dev1','port1']);
|
||||
__PACKAGE__->add_unique_constraint(['dev2','port2']);
|
||||
|
||||
__PACKAGE__->belongs_to(
|
||||
device1 => 'App::Netdisco::DB::Result::Device',
|
||||
{'foreign.ip' => 'self.dev1'}
|
||||
);
|
||||
|
||||
__PACKAGE__->belongs_to(
|
||||
device2 => 'App::Netdisco::DB::Result::Device',
|
||||
{'foreign.ip' => 'self.dev2'}
|
||||
);
|
||||
|
||||
1;
|
||||
45
lib/App/Netdisco/DB/Result/User.pm
Normal file
45
lib/App/Netdisco/DB/Result/User.pm
Normal file
@@ -0,0 +1,45 @@
|
||||
use utf8;
|
||||
package App::Netdisco::DB::Result::User;
|
||||
|
||||
# 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("users");
|
||||
__PACKAGE__->add_columns(
|
||||
"username",
|
||||
{ data_type => "varchar", is_nullable => 0, size => 50 },
|
||||
"password",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"creation",
|
||||
{
|
||||
data_type => "timestamp",
|
||||
default_value => \"current_timestamp",
|
||||
is_nullable => 1,
|
||||
original => { default_value => \"now()" },
|
||||
},
|
||||
"last_on",
|
||||
{ data_type => "timestamp", is_nullable => 1 },
|
||||
"port_control",
|
||||
{ data_type => "boolean", default_value => \"false", is_nullable => 1 },
|
||||
"ldap",
|
||||
{ data_type => "boolean", default_value => \"false", is_nullable => 1 },
|
||||
"admin",
|
||||
{ data_type => "boolean", default_value => \"false", is_nullable => 1 },
|
||||
"fullname",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"note",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
);
|
||||
__PACKAGE__->set_primary_key("username");
|
||||
|
||||
__PACKAGE__->has_many( roles => 'App::Netdisco::DB::Result::Virtual::UserRole',
|
||||
'username', { cascade_copy => 0, cascade_update => 0, cascade_delete => 0 } );
|
||||
|
||||
sub created { return (shift)->get_column('created') }
|
||||
sub last_seen { return (shift)->get_column('last_seen') }
|
||||
|
||||
1;
|
||||
43
lib/App/Netdisco/DB/Result/UserLog.pm
Normal file
43
lib/App/Netdisco/DB/Result/UserLog.pm
Normal file
@@ -0,0 +1,43 @@
|
||||
use utf8;
|
||||
package App::Netdisco::DB::Result::UserLog;
|
||||
|
||||
# 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("user_log");
|
||||
__PACKAGE__->add_columns(
|
||||
"entry",
|
||||
{
|
||||
data_type => "integer",
|
||||
is_auto_increment => 1,
|
||||
is_nullable => 0,
|
||||
sequence => "user_log_entry_seq",
|
||||
},
|
||||
"username",
|
||||
{ data_type => "varchar", is_nullable => 1, size => 50 },
|
||||
"userip",
|
||||
{ data_type => "inet", is_nullable => 1 },
|
||||
"event",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"details",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"creation",
|
||||
{
|
||||
data_type => "timestamp",
|
||||
default_value => \"current_timestamp",
|
||||
is_nullable => 1,
|
||||
original => { default_value => \"now()" },
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
# Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:BFrhjYJOhcLIHeWviu9rjw
|
||||
|
||||
|
||||
# You can replace this text with custom code or comments, and it will be preserved on regeneration
|
||||
1;
|
||||
19
lib/App/Netdisco/DB/Result/Virtual/ActiveNode.pm
Normal file
19
lib/App/Netdisco/DB/Result/Virtual/ActiveNode.pm
Normal file
@@ -0,0 +1,19 @@
|
||||
use utf8;
|
||||
package App::Netdisco::DB::Result::Virtual::ActiveNode;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use base 'App::Netdisco::DB::Result::Node';
|
||||
|
||||
__PACKAGE__->load_components('Helper::Row::SubClass');
|
||||
__PACKAGE__->subclass;
|
||||
|
||||
__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
|
||||
__PACKAGE__->table("active_node");
|
||||
__PACKAGE__->result_source_instance->is_virtual(1);
|
||||
__PACKAGE__->result_source_instance->view_definition(q{
|
||||
SELECT * FROM node WHERE active
|
||||
});
|
||||
|
||||
1;
|
||||
27
lib/App/Netdisco/DB/Result/Virtual/ActiveNodeWithAge.pm
Normal file
27
lib/App/Netdisco/DB/Result/Virtual/ActiveNodeWithAge.pm
Normal file
@@ -0,0 +1,27 @@
|
||||
use utf8;
|
||||
package App::Netdisco::DB::Result::Virtual::ActiveNodeWithAge;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use base 'App::Netdisco::DB::Result::Virtual::ActiveNode';
|
||||
|
||||
__PACKAGE__->load_components('Helper::Row::SubClass');
|
||||
__PACKAGE__->subclass;
|
||||
|
||||
__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
|
||||
__PACKAGE__->table("active_node_with_age");
|
||||
__PACKAGE__->result_source_instance->is_virtual(1);
|
||||
__PACKAGE__->result_source_instance->view_definition(q{
|
||||
SELECT *,
|
||||
replace( date_trunc( 'minute', age( now(), time_last + interval '30 second' ) ) ::text, 'mon', 'month')
|
||||
AS time_last_age
|
||||
FROM node WHERE active
|
||||
});
|
||||
|
||||
__PACKAGE__->add_columns(
|
||||
"time_last_age",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
);
|
||||
|
||||
1;
|
||||
71
lib/App/Netdisco/DB/Result/Virtual/ApRadioChannelPower.pm
Normal file
71
lib/App/Netdisco/DB/Result/Virtual/ApRadioChannelPower.pm
Normal file
@@ -0,0 +1,71 @@
|
||||
package App::Netdisco::DB::Result::Virtual::ApRadioChannelPower;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use base 'DBIx::Class::Core';
|
||||
|
||||
__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
|
||||
|
||||
__PACKAGE__->table('ap_radio_channel_power');
|
||||
__PACKAGE__->result_source_instance->is_virtual(1);
|
||||
__PACKAGE__->result_source_instance->view_definition(<<ENDSQL
|
||||
SELECT w.channel,
|
||||
w.power,
|
||||
w.ip,
|
||||
w.port,
|
||||
dp.name AS port_name,
|
||||
dp.descr,
|
||||
d.name AS device_name,
|
||||
d.dns,
|
||||
d.model,
|
||||
d.location,
|
||||
CASE
|
||||
WHEN w.power > 0 THEN round((10.0 * log(w.power) / log(10))::numeric, 1)
|
||||
ELSE NULL
|
||||
END AS power2
|
||||
FROM device_port_wireless AS w
|
||||
JOIN device_port AS dp ON dp.port = w.port
|
||||
AND dp.ip = w.ip
|
||||
JOIN device AS d ON d.ip = w.ip
|
||||
WHERE w.channel != '0'
|
||||
ENDSQL
|
||||
);
|
||||
|
||||
__PACKAGE__->add_columns(
|
||||
'channel' => {
|
||||
data_type => 'integer',
|
||||
},
|
||||
'power' => {
|
||||
data_type => 'integer',
|
||||
},
|
||||
'ip' => {
|
||||
data_type => 'inet',
|
||||
},
|
||||
'port' => {
|
||||
data_type => 'text',
|
||||
},
|
||||
'port_name' => {
|
||||
data_type => 'text',
|
||||
},
|
||||
'descr' => {
|
||||
data_type => 'text',
|
||||
},
|
||||
'device_name' => {
|
||||
data_type => 'text',
|
||||
},
|
||||
'dns' => {
|
||||
data_type => 'text',
|
||||
},
|
||||
'model' => {
|
||||
data_type => 'text',
|
||||
},
|
||||
'location' => {
|
||||
data_type => 'text',
|
||||
},
|
||||
'power2' => {
|
||||
data_type => 'numeric',
|
||||
},
|
||||
);
|
||||
|
||||
1;
|
||||
50
lib/App/Netdisco/DB/Result/Virtual/CidrIps.pm
Normal file
50
lib/App/Netdisco/DB/Result/Virtual/CidrIps.pm
Normal file
@@ -0,0 +1,50 @@
|
||||
package App::Netdisco::DB::Result::Virtual::CidrIps;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use utf8;
|
||||
use base 'DBIx::Class::Core';
|
||||
|
||||
__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
|
||||
|
||||
__PACKAGE__->table('cidr_ips');
|
||||
__PACKAGE__->result_source_instance->is_virtual(1);
|
||||
__PACKAGE__->result_source_instance->view_definition(<<'ENDSQL');
|
||||
SELECT host(network (prefix) + sub.int)::inet AS ip,
|
||||
NULL AS mac,
|
||||
NULL::text AS dns,
|
||||
NULL::timestamp AS time_first,
|
||||
NULL::timestamp AS time_last,
|
||||
false::boolean AS active
|
||||
FROM (
|
||||
SELECT prefix,
|
||||
generate_series(1, (broadcast(prefix) - network(prefix) - 1)) AS int
|
||||
FROM (
|
||||
SELECT ?::inet AS prefix
|
||||
) AS addr
|
||||
) AS sub
|
||||
ENDSQL
|
||||
|
||||
__PACKAGE__->add_columns(
|
||||
"ip",
|
||||
{ data_type => "inet", is_nullable => 0 },
|
||||
"mac",
|
||||
{ data_type => "macaddr", is_nullable => 1 },
|
||||
"dns",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"active",
|
||||
{ data_type => "boolean", is_nullable => 1 },
|
||||
"time_first",
|
||||
{
|
||||
data_type => "timestamp",
|
||||
is_nullable => 1,
|
||||
},
|
||||
"time_last",
|
||||
{
|
||||
data_type => "timestamp",
|
||||
is_nullable => 1,
|
||||
},
|
||||
);
|
||||
|
||||
1;
|
||||
24
lib/App/Netdisco/DB/Result/Virtual/DeviceDnsMismatch.pm
Normal file
24
lib/App/Netdisco/DB/Result/Virtual/DeviceDnsMismatch.pm
Normal file
@@ -0,0 +1,24 @@
|
||||
package App::Netdisco::DB::Result::Virtual::DeviceDnsMismatch;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use utf8;
|
||||
use base 'App::Netdisco::DB::Result::Device';
|
||||
|
||||
__PACKAGE__->load_components('Helper::Row::SubClass');
|
||||
__PACKAGE__->subclass;
|
||||
|
||||
__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
|
||||
__PACKAGE__->table('device_dns_mismatch');
|
||||
__PACKAGE__->result_source_instance->is_virtual(1);
|
||||
__PACKAGE__->result_source_instance->view_definition(<<'ENDSQL');
|
||||
SELECT *
|
||||
FROM device
|
||||
WHERE dns IS NULL
|
||||
OR name IS NULL
|
||||
OR regexp_replace(lower(dns), ? || '$', '')
|
||||
!= regexp_replace(lower(name), ? || '$', '')
|
||||
ENDSQL
|
||||
|
||||
1;
|
||||
48
lib/App/Netdisco/DB/Result/Virtual/DeviceLinks.pm
Normal file
48
lib/App/Netdisco/DB/Result/Virtual/DeviceLinks.pm
Normal file
@@ -0,0 +1,48 @@
|
||||
package App::Netdisco::DB::Result::Virtual::DeviceLinks;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use base 'DBIx::Class::Core';
|
||||
|
||||
__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
|
||||
|
||||
__PACKAGE__->table('device_links');
|
||||
__PACKAGE__->result_source_instance->is_virtual(1);
|
||||
__PACKAGE__->result_source_instance->view_definition(<<ENDSQL
|
||||
SELECT dp.ip AS left_ip, dp.port AS left_port, di.ip AS right_ip, dp.remote_port AS right_port
|
||||
FROM ( SELECT device_port.ip, device_port.port, device_port.remote_ip, device_port.remote_port
|
||||
FROM device_port
|
||||
WHERE device_port.remote_port IS NOT NULL
|
||||
GROUP BY device_port.ip, device_port.port, device_port.remote_ip, device_port.remote_port
|
||||
ORDER BY device_port.ip) dp
|
||||
LEFT JOIN device_ip di ON dp.remote_ip = di.alias
|
||||
WHERE di.ip IS NOT NULL
|
||||
ORDER BY dp.ip
|
||||
ENDSQL
|
||||
);
|
||||
|
||||
__PACKAGE__->add_columns(
|
||||
'left_ip' => {
|
||||
data_type => 'inet',
|
||||
},
|
||||
'left_port' => {
|
||||
data_type => 'text',
|
||||
},
|
||||
'right_ip' => {
|
||||
data_type => 'inet',
|
||||
},
|
||||
'right_port' => {
|
||||
data_type => 'text',
|
||||
},
|
||||
);
|
||||
|
||||
__PACKAGE__->has_many('left_vlans', 'App::Netdisco::DB::Result::DevicePortVlan',
|
||||
{ 'foreign.ip' => 'self.left_ip', 'foreign.port' => 'self.left_port' },
|
||||
{ join_type => 'INNER' } );
|
||||
|
||||
__PACKAGE__->has_many('right_vlans', 'App::Netdisco::DB::Result::DevicePortVlan',
|
||||
{ 'foreign.ip' => 'self.right_ip', 'foreign.port' => 'self.right_port' },
|
||||
{ join_type => 'INNER' } );
|
||||
|
||||
1;
|
||||
87
lib/App/Netdisco/DB/Result/Virtual/DevicePoeStatus.pm
Normal file
87
lib/App/Netdisco/DB/Result/Virtual/DevicePoeStatus.pm
Normal file
@@ -0,0 +1,87 @@
|
||||
package App::Netdisco::DB::Result::Virtual::DevicePoeStatus;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use base 'DBIx::Class::Core';
|
||||
|
||||
__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
|
||||
|
||||
__PACKAGE__->table('device_poe_status');
|
||||
__PACKAGE__->result_source_instance->is_virtual(1);
|
||||
__PACKAGE__->result_source_instance->view_definition(<<'ENDSQL');
|
||||
SELECT DISTINCT ON (dp.ip,dp.module)
|
||||
dp.ip,
|
||||
dp.module,
|
||||
dp.power::bigint,
|
||||
dp.status,
|
||||
d.dns,
|
||||
d.name,
|
||||
d.model,
|
||||
d.location,
|
||||
COUNT(dpp.port) OVER (PARTITION BY dp.ip, dp.module) AS poe_capable_ports,
|
||||
SUM(CASE WHEN dpp.status = 'deliveringPower' THEN 1 ELSE 0 END) OVER (PARTITION BY dp.ip, dp.module) AS poe_powered_ports,
|
||||
SUM(CASE WHEN dpp.admin = 'false' THEN 1 ELSE 0 END) OVER (PARTITION BY dp.ip, dp.module) AS poe_disabled_ports,
|
||||
SUM(CASE WHEN dpp.status ILIKE '%fault' THEN 1
|
||||
ELSE 0 END) OVER (PARTITION BY dp.ip, dp.module) AS poe_errored_ports,
|
||||
SUM(CASE WHEN dpp.status = 'deliveringPower' AND dpp.class = 'class4' THEN 30.0
|
||||
WHEN dpp.status = 'deliveringPower' AND dpp.class = 'class2' THEN 7.0
|
||||
WHEN dpp.status = 'deliveringPower' AND dpp.class = 'class1' THEN 4.0
|
||||
WHEN dpp.status = 'deliveringPower' AND dpp.class = 'class3' THEN 15.4
|
||||
WHEN dpp.status = 'deliveringPower' AND dpp.class = 'class0' THEN 15.4
|
||||
WHEN dpp.status = 'deliveringPower' AND dpp.class IS NULL THEN 15.4
|
||||
ELSE 0 END) OVER (PARTITION BY dp.ip, dp.module) AS poe_power_committed,
|
||||
SUM(CASE WHEN (dpp.power IS NULL OR dpp.power = '0') THEN 0
|
||||
ELSE round(dpp.power/1000.0, 1) END) OVER (PARTITION BY dp.ip, dp.module) AS poe_power_delivering
|
||||
FROM device_power dp
|
||||
JOIN device_port_power dpp ON dpp.ip = dp.ip
|
||||
AND dpp.module = dp.module
|
||||
JOIN device d ON dp.ip = d.ip
|
||||
ENDSQL
|
||||
|
||||
__PACKAGE__->add_columns(
|
||||
'ip' => {
|
||||
data_type => 'inet',
|
||||
},
|
||||
'module' => {
|
||||
data_type => 'integer',
|
||||
},
|
||||
'power' => {
|
||||
data_type => 'integer',
|
||||
},
|
||||
'status' => {
|
||||
data_type => 'text',
|
||||
},
|
||||
'dns' => {
|
||||
data_type => 'text',
|
||||
},
|
||||
'name' => {
|
||||
data_type => 'text',
|
||||
},
|
||||
'model' => {
|
||||
data_type => 'text',
|
||||
},
|
||||
'location' => {
|
||||
data_type => 'text',
|
||||
},
|
||||
'poe_capable_ports' => {
|
||||
data_type => 'bigint',
|
||||
},
|
||||
'poe_powered_ports' => {
|
||||
data_type => 'bigint',
|
||||
},
|
||||
'poe_disabled_ports' => {
|
||||
data_type => 'bigint',
|
||||
},
|
||||
'poe_errored_ports' => {
|
||||
data_type => 'bigint',
|
||||
},
|
||||
'poe_power_committed' => {
|
||||
data_type => 'numeric',
|
||||
},
|
||||
'poe_power_delivering' => {
|
||||
data_type => 'numeric',
|
||||
},
|
||||
);
|
||||
|
||||
1;
|
||||
61
lib/App/Netdisco/DB/Result/Virtual/DuplexMismatch.pm
Normal file
61
lib/App/Netdisco/DB/Result/Virtual/DuplexMismatch.pm
Normal file
@@ -0,0 +1,61 @@
|
||||
package App::Netdisco::DB::Result::Virtual::DuplexMismatch;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use base 'DBIx::Class::Core';
|
||||
|
||||
__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
|
||||
|
||||
__PACKAGE__->table('duplex_mismatch');
|
||||
__PACKAGE__->result_source_instance->is_virtual(1);
|
||||
__PACKAGE__->result_source_instance->view_definition(<<ENDSQL
|
||||
SELECT dp.ip AS left_ip, d1.dns AS left_dns, dp.port AS left_port, dp.duplex AS left_duplex,
|
||||
di.ip AS right_ip, d2.dns AS right_dns, dp.remote_port AS right_port, dp2.duplex AS right_duplex
|
||||
FROM ( SELECT device_port.ip, device_port.remote_ip, device_port.port, device_port.duplex, device_port.remote_port
|
||||
FROM device_port
|
||||
WHERE
|
||||
device_port.remote_port IS NOT NULL
|
||||
AND device_port.up NOT ILIKE '%down%'
|
||||
GROUP BY device_port.ip, device_port.remote_ip, device_port.port, device_port.duplex, device_port.remote_port
|
||||
ORDER BY device_port.ip) dp
|
||||
LEFT JOIN device_ip di ON dp.remote_ip = di.alias
|
||||
LEFT JOIN device d1 ON dp.ip = d1.ip
|
||||
LEFT JOIN device d2 ON di.ip = d2.ip
|
||||
LEFT JOIN device_port dp2 ON (di.ip = dp2.ip AND dp.remote_port = dp2.port)
|
||||
WHERE di.ip IS NOT NULL
|
||||
AND dp.duplex <> dp2.duplex
|
||||
AND dp.ip <= di.ip
|
||||
AND dp2.up NOT ILIKE '%down%'
|
||||
ORDER BY dp.ip
|
||||
ENDSQL
|
||||
);
|
||||
|
||||
__PACKAGE__->add_columns(
|
||||
'left_ip' => {
|
||||
data_type => 'inet',
|
||||
},
|
||||
'left_dns' => {
|
||||
data_type => 'text',
|
||||
},
|
||||
'left_port' => {
|
||||
data_type => 'text',
|
||||
},
|
||||
'left_duplex' => {
|
||||
data_type => 'text',
|
||||
},
|
||||
'right_ip' => {
|
||||
data_type => 'inet',
|
||||
},
|
||||
'right_dns' => {
|
||||
data_type => 'text',
|
||||
},
|
||||
'right_port' => {
|
||||
data_type => 'text',
|
||||
},
|
||||
'right_duplex' => {
|
||||
data_type => 'text',
|
||||
},
|
||||
);
|
||||
|
||||
1;
|
||||
13
lib/App/Netdisco/DB/Result/Virtual/GenericReport.pm
Normal file
13
lib/App/Netdisco/DB/Result/Virtual/GenericReport.pm
Normal file
@@ -0,0 +1,13 @@
|
||||
package App::Netdisco::DB::Result::Virtual::GenericReport;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use base 'DBIx::Class::Core';
|
||||
|
||||
__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
|
||||
__PACKAGE__->table("generic_report");
|
||||
__PACKAGE__->result_source_instance->is_virtual(1);
|
||||
__PACKAGE__->result_source_instance->view_definition(q{});
|
||||
|
||||
1;
|
||||
19
lib/App/Netdisco/DB/Result/Virtual/NodeIp4.pm
Normal file
19
lib/App/Netdisco/DB/Result/Virtual/NodeIp4.pm
Normal file
@@ -0,0 +1,19 @@
|
||||
use utf8;
|
||||
package App::Netdisco::DB::Result::Virtual::NodeIp4;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use base 'App::Netdisco::DB::Result::NodeIp';
|
||||
|
||||
__PACKAGE__->load_components('Helper::Row::SubClass');
|
||||
__PACKAGE__->subclass;
|
||||
|
||||
__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
|
||||
__PACKAGE__->table("node_ip4");
|
||||
__PACKAGE__->result_source_instance->is_virtual(1);
|
||||
__PACKAGE__->result_source_instance->view_definition(q{
|
||||
SELECT * FROM node_ip WHERE family(ip) = 4
|
||||
});
|
||||
|
||||
1;
|
||||
19
lib/App/Netdisco/DB/Result/Virtual/NodeIp6.pm
Normal file
19
lib/App/Netdisco/DB/Result/Virtual/NodeIp6.pm
Normal file
@@ -0,0 +1,19 @@
|
||||
use utf8;
|
||||
package App::Netdisco::DB::Result::Virtual::NodeIp6;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use base 'App::Netdisco::DB::Result::NodeIp';
|
||||
|
||||
__PACKAGE__->load_components('Helper::Row::SubClass');
|
||||
__PACKAGE__->subclass;
|
||||
|
||||
__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
|
||||
__PACKAGE__->table("node_ip6");
|
||||
__PACKAGE__->result_source_instance->is_virtual(1);
|
||||
__PACKAGE__->result_source_instance->view_definition(q{
|
||||
SELECT * FROM node_ip WHERE family(ip) = 6
|
||||
});
|
||||
|
||||
1;
|
||||
49
lib/App/Netdisco/DB/Result/Virtual/NodeMonitor.pm
Normal file
49
lib/App/Netdisco/DB/Result/Virtual/NodeMonitor.pm
Normal file
@@ -0,0 +1,49 @@
|
||||
package App::Netdisco::DB::Result::Virtual::NodeMonitor;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use utf8;
|
||||
use base 'DBIx::Class::Core';
|
||||
|
||||
__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
|
||||
|
||||
__PACKAGE__->table('node_monitor_virtual');
|
||||
__PACKAGE__->result_source_instance->is_virtual(1);
|
||||
__PACKAGE__->result_source_instance->view_definition(<<'ENDSQL');
|
||||
SELECT nm.why, nm.cc, trim(trailing '.' from trim(trailing '0123456789' from date::text)) as date,
|
||||
n.mac, n.switch, n.port,
|
||||
d.name, d.location,
|
||||
dp.name AS portname
|
||||
FROM node_monitor nm, node n, device d, device_port dp
|
||||
WHERE nm.mac = n.mac
|
||||
AND nm.active
|
||||
AND nm.cc IS NOT NULL
|
||||
AND d.ip = n.switch
|
||||
AND dp.ip = n.switch
|
||||
AND dp.port = n.port
|
||||
AND d.last_macsuck = n.time_last
|
||||
ENDSQL
|
||||
|
||||
__PACKAGE__->add_columns(
|
||||
"why",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"cc",
|
||||
{ data_type => "text", is_nullable => 0 },
|
||||
"date",
|
||||
{ data_type => "timestamp", is_nullable => 0 },
|
||||
"mac",
|
||||
{ data_type => "macaddr", is_nullable => 0 },
|
||||
"switch",
|
||||
{ data_type => "inet", is_nullable => 0 },
|
||||
"port",
|
||||
{ data_type => "text", is_nullable => 0 },
|
||||
"name",
|
||||
{ data_type => "text", is_nullable => 0 },
|
||||
"location",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"portname",
|
||||
{ data_type => "text", is_nullable => 0 },
|
||||
);
|
||||
|
||||
1;
|
||||
27
lib/App/Netdisco/DB/Result/Virtual/NodeWithAge.pm
Normal file
27
lib/App/Netdisco/DB/Result/Virtual/NodeWithAge.pm
Normal file
@@ -0,0 +1,27 @@
|
||||
use utf8;
|
||||
package App::Netdisco::DB::Result::Virtual::NodeWithAge;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use base 'App::Netdisco::DB::Result::Node';
|
||||
|
||||
__PACKAGE__->load_components('Helper::Row::SubClass');
|
||||
__PACKAGE__->subclass;
|
||||
|
||||
__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
|
||||
__PACKAGE__->table("node_with_age");
|
||||
__PACKAGE__->result_source_instance->is_virtual(1);
|
||||
__PACKAGE__->result_source_instance->view_definition(q{
|
||||
SELECT *,
|
||||
replace( date_trunc( 'minute', age( now(), time_last + interval '30 second' ) ) ::text, 'mon', 'month')
|
||||
AS time_last_age
|
||||
FROM node
|
||||
});
|
||||
|
||||
__PACKAGE__->add_columns(
|
||||
"time_last_age",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
);
|
||||
|
||||
1;
|
||||
68
lib/App/Netdisco/DB/Result/Virtual/NodesDiscovered.pm
Normal file
68
lib/App/Netdisco/DB/Result/Virtual/NodesDiscovered.pm
Normal file
@@ -0,0 +1,68 @@
|
||||
package App::Netdisco::DB::Result::Virtual::NodesDiscovered;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use base 'DBIx::Class::Core';
|
||||
|
||||
__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
|
||||
|
||||
__PACKAGE__->table('nodes_discovered');
|
||||
__PACKAGE__->result_source_instance->is_virtual(1);
|
||||
__PACKAGE__->result_source_instance->view_definition(<<ENDSQL
|
||||
SELECT d.ip,
|
||||
d.dns,
|
||||
d.name,
|
||||
p.port,
|
||||
p.remote_ip,
|
||||
p.remote_port,
|
||||
p.remote_type,
|
||||
p.remote_id
|
||||
FROM device_port p,
|
||||
device d
|
||||
WHERE d.ip = p.ip
|
||||
AND NOT EXISTS
|
||||
(SELECT 1
|
||||
FROM device_port q
|
||||
WHERE q.ip = p.remote_ip
|
||||
AND q.port = p.remote_port)
|
||||
AND NOT EXISTS
|
||||
(SELECT 1
|
||||
FROM device_ip a,
|
||||
device_port q
|
||||
WHERE a.alias = p.remote_ip
|
||||
AND q.ip = a.ip
|
||||
AND q.port = p.remote_port)
|
||||
AND (p.remote_id IS NOT NULL OR p.remote_type IS NOT NULL)
|
||||
ORDER BY d.name, p.port
|
||||
ENDSQL
|
||||
);
|
||||
|
||||
__PACKAGE__->add_columns(
|
||||
'ip' => {
|
||||
data_type => 'inet',
|
||||
},
|
||||
'dns' => {
|
||||
data_type => 'text',
|
||||
},
|
||||
'name' => {
|
||||
data_type => 'text',
|
||||
},
|
||||
'port' => {
|
||||
data_type => 'text',
|
||||
},
|
||||
'remote_ip' => {
|
||||
data_type => 'inet',
|
||||
},
|
||||
'remote_port' => {
|
||||
data_type => 'text',
|
||||
},
|
||||
'remote_type' => {
|
||||
data_type => 'text',
|
||||
},
|
||||
'remote_id' => {
|
||||
data_type => 'text',
|
||||
},
|
||||
);
|
||||
|
||||
1;
|
||||
32
lib/App/Netdisco/DB/Result/Virtual/OrphanedDevices.pm
Normal file
32
lib/App/Netdisco/DB/Result/Virtual/OrphanedDevices.pm
Normal file
@@ -0,0 +1,32 @@
|
||||
package App::Netdisco::DB::Result::Virtual::OrphanedDevices;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use utf8;
|
||||
use base 'App::Netdisco::DB::Result::Device';
|
||||
|
||||
__PACKAGE__->load_components('Helper::Row::SubClass');
|
||||
__PACKAGE__->subclass;
|
||||
|
||||
__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
|
||||
__PACKAGE__->table('orphaned_devices');
|
||||
__PACKAGE__->result_source_instance->is_virtual(1);
|
||||
__PACKAGE__->result_source_instance->view_definition(<<'ENDSQL');
|
||||
SELECT *
|
||||
FROM device
|
||||
WHERE ip NOT IN
|
||||
( SELECT DISTINCT dp.ip AS ip
|
||||
FROM
|
||||
(SELECT device_port.ip,
|
||||
device_port.remote_ip
|
||||
FROM device_port
|
||||
WHERE device_port.remote_port IS NOT NULL
|
||||
GROUP BY device_port.ip,
|
||||
device_port.remote_ip
|
||||
ORDER BY device_port.ip) dp
|
||||
LEFT JOIN device_ip di ON dp.remote_ip = di.alias
|
||||
WHERE di.ip IS NOT NULL)
|
||||
ENDSQL
|
||||
|
||||
1;
|
||||
42
lib/App/Netdisco/DB/Result/Virtual/PollerPerformance.pm
Normal file
42
lib/App/Netdisco/DB/Result/Virtual/PollerPerformance.pm
Normal file
@@ -0,0 +1,42 @@
|
||||
package App::Netdisco::DB::Result::Virtual::PollerPerformance;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use base 'DBIx::Class::Core';
|
||||
|
||||
__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
|
||||
|
||||
__PACKAGE__->table('poller_performance');
|
||||
__PACKAGE__->result_source_instance->is_virtual(1);
|
||||
__PACKAGE__->result_source_instance->view_definition(<<ENDSQL
|
||||
SELECT action, entered, to_char( entered, 'YYYY-MM-DD HH24:MI:SS' ) AS entered_stamp,
|
||||
COUNT( device ) AS number, MIN( started ) AS start, MAX( finished ) AS end,
|
||||
justify_interval( extract ( epoch FROM( max( finished ) - min( started ) ) ) * interval '1 second' ) AS elapsed
|
||||
FROM admin
|
||||
WHERE action IN ( 'discover', 'macsuck', 'arpnip', 'nbtstat' )
|
||||
GROUP BY action, entered
|
||||
HAVING count( device ) > 1
|
||||
ORDER BY entered DESC, elapsed DESC
|
||||
LIMIT 30
|
||||
ENDSQL
|
||||
);
|
||||
|
||||
__PACKAGE__->add_columns(
|
||||
"action",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"entered",
|
||||
{ data_type => "timestamp", is_nullable => 1 },
|
||||
"entered_stamp",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"number",
|
||||
{ data_type => "integer", is_nullable => 1 },
|
||||
"start",
|
||||
{ data_type => "timestamp", is_nullable => 1 },
|
||||
"end",
|
||||
{ data_type => "timestamp", is_nullable => 1 },
|
||||
"elapsed",
|
||||
{ data_type => "interval", is_nullable => 1 },
|
||||
);
|
||||
|
||||
1;
|
||||
46
lib/App/Netdisco/DB/Result/Virtual/PortUtilization.pm
Normal file
46
lib/App/Netdisco/DB/Result/Virtual/PortUtilization.pm
Normal file
@@ -0,0 +1,46 @@
|
||||
package App::Netdisco::DB::Result::Virtual::PortUtilization;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use base 'DBIx::Class::Core';
|
||||
|
||||
__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
|
||||
|
||||
__PACKAGE__->table('port_utilization');
|
||||
__PACKAGE__->result_source_instance->is_virtual(1);
|
||||
__PACKAGE__->result_source_instance->view_definition(<<ENDSQL
|
||||
SELECT d.dns AS dns, d.ip as ip,
|
||||
sum(CASE WHEN (dp.type != 'propVirtual') THEN 1 ELSE 0 END) as port_count,
|
||||
sum(CASE WHEN (dp.type != 'propVirtual' AND dp.up_admin = 'up' AND dp.up = 'up') THEN 1 ELSE 0 END) as ports_in_use,
|
||||
sum(CASE WHEN (dp.type != 'propVirtual' AND dp.up_admin != 'up') THEN 1 ELSE 0 END) as ports_shutdown,
|
||||
sum(CASE WHEN (dp.type != 'propVirtual' AND dp.up_admin = 'up' AND dp.up != 'up') THEN 1 ELSE 0 END) as ports_free
|
||||
FROM device d LEFT JOIN device_port dp
|
||||
ON d.ip = dp.ip
|
||||
GROUP BY d.dns, d.ip
|
||||
ORDER BY d.dns, d.ip
|
||||
ENDSQL
|
||||
);
|
||||
|
||||
__PACKAGE__->add_columns(
|
||||
'dns' => {
|
||||
data_type => 'text',
|
||||
},
|
||||
'ip' => {
|
||||
data_type => 'inet',
|
||||
},
|
||||
'port_count' => {
|
||||
data_type => 'integer',
|
||||
},
|
||||
'ports_in_use' => {
|
||||
data_type => 'integer',
|
||||
},
|
||||
'ports_shutdown' => {
|
||||
data_type => 'integer',
|
||||
},
|
||||
'ports_free' => {
|
||||
data_type => 'integer',
|
||||
},
|
||||
);
|
||||
|
||||
1;
|
||||
42
lib/App/Netdisco/DB/Result/Virtual/SlowDevices.pm
Normal file
42
lib/App/Netdisco/DB/Result/Virtual/SlowDevices.pm
Normal file
@@ -0,0 +1,42 @@
|
||||
package App::Netdisco::DB::Result::Virtual::SlowDevices;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use base 'DBIx::Class::Core';
|
||||
|
||||
__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
|
||||
|
||||
__PACKAGE__->table('slow_devices');
|
||||
__PACKAGE__->result_source_instance->is_virtual(1);
|
||||
__PACKAGE__->result_source_instance->view_definition(<<ENDSQL
|
||||
SELECT a.action, a.device, a.started, a.finished,
|
||||
justify_interval(extract(epoch FROM (a.finished - a.started)) * interval '1 second') AS elapsed
|
||||
FROM admin a
|
||||
INNER JOIN (
|
||||
SELECT device, action, max(started) AS started
|
||||
FROM admin
|
||||
WHERE status = 'done'
|
||||
AND action IN ('discover','macsuck','arpnip')
|
||||
GROUP BY action, device
|
||||
) b
|
||||
ON a.device = b.device AND a.started = b.started
|
||||
ORDER BY elapsed desc, action, device
|
||||
LIMIT 20
|
||||
ENDSQL
|
||||
);
|
||||
|
||||
__PACKAGE__->add_columns(
|
||||
"action",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"device",
|
||||
{ data_type => "inet", is_nullable => 1 },
|
||||
"started",
|
||||
{ data_type => "timestamp", is_nullable => 1 },
|
||||
"finished",
|
||||
{ data_type => "timestamp", is_nullable => 1 },
|
||||
"elapsed",
|
||||
{ data_type => "interval", is_nullable => 1 },
|
||||
);
|
||||
|
||||
1;
|
||||
54
lib/App/Netdisco/DB/Result/Virtual/SubnetUtilization.pm
Normal file
54
lib/App/Netdisco/DB/Result/Virtual/SubnetUtilization.pm
Normal file
@@ -0,0 +1,54 @@
|
||||
package App::Netdisco::DB::Result::Virtual::SubnetUtilization;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use utf8;
|
||||
use base 'DBIx::Class::Core';
|
||||
|
||||
__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
|
||||
|
||||
__PACKAGE__->table('cidr_ips');
|
||||
__PACKAGE__->result_source_instance->is_virtual(1);
|
||||
__PACKAGE__->result_source_instance->view_definition(<<'ENDSQL');
|
||||
SELECT net as subnet,
|
||||
power(2, (32 - masklen(net))) as subnet_size,
|
||||
count(DISTINCT ip) as active,
|
||||
round(100 * count(DISTINCT ip) / (power(2, (32 - masklen(net))))) as percent
|
||||
FROM (
|
||||
SELECT DISTINCT net, ni.ip
|
||||
FROM subnets s1, node_ip ni
|
||||
WHERE s1.net <<= ?::cidr
|
||||
AND ni.ip <<= s1.net
|
||||
AND ((
|
||||
ni.time_first IS null
|
||||
AND ni.time_last IS null
|
||||
) OR (
|
||||
ni.time_last >= ?
|
||||
AND ni.time_last <= ?
|
||||
))
|
||||
AND s1.last_discover >= ?
|
||||
UNION
|
||||
SELECT DISTINCT net, di.alias as ip
|
||||
FROM subnets s2, device_ip di JOIN device d USING (ip)
|
||||
WHERE s2.net <<= ?::cidr
|
||||
AND di.alias <<= s2.net
|
||||
AND s2.last_discover >= ?
|
||||
AND d.last_discover >= ?
|
||||
) as joined
|
||||
GROUP BY net
|
||||
ORDER BY percent ASC
|
||||
ENDSQL
|
||||
|
||||
__PACKAGE__->add_columns(
|
||||
"subnet",
|
||||
{ data_type => "cidr", is_nullable => 0 },
|
||||
"subnet_size",
|
||||
{ data_type => "integer", is_nullable => 0 },
|
||||
"active",
|
||||
{ data_type => "integer", is_nullable => 0 },
|
||||
"percent",
|
||||
{ data_type => "integer", is_nullable => 0 },
|
||||
);
|
||||
|
||||
1;
|
||||
54
lib/App/Netdisco/DB/Result/Virtual/UnDirEdgesAgg.pm
Normal file
54
lib/App/Netdisco/DB/Result/Virtual/UnDirEdgesAgg.pm
Normal file
@@ -0,0 +1,54 @@
|
||||
package App::Netdisco::DB::Result::Virtual::UnDirEdgesAgg;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use base 'DBIx::Class::Core';
|
||||
|
||||
__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
|
||||
|
||||
__PACKAGE__->table('undir_edges_agg');
|
||||
__PACKAGE__->result_source_instance->is_virtual(1);
|
||||
__PACKAGE__->result_source_instance->view_definition(<<'ENDSQL');
|
||||
SELECT left_ip,
|
||||
array_agg(right_ip) AS links
|
||||
FROM
|
||||
( SELECT dp.ip AS left_ip,
|
||||
di.ip AS right_ip
|
||||
FROM
|
||||
(SELECT device_port.ip,
|
||||
device_port.remote_ip
|
||||
FROM device_port
|
||||
WHERE device_port.remote_port IS NOT NULL
|
||||
GROUP BY device_port.ip,
|
||||
device_port.remote_ip) dp
|
||||
LEFT JOIN device_ip di ON dp.remote_ip = di.alias
|
||||
WHERE di.ip IS NOT NULL
|
||||
UNION SELECT di.ip AS left_ip,
|
||||
dp.ip AS right_ip
|
||||
FROM
|
||||
(SELECT device_port.ip,
|
||||
device_port.remote_ip
|
||||
FROM device_port
|
||||
WHERE device_port.remote_port IS NOT NULL
|
||||
GROUP BY device_port.ip,
|
||||
device_port.remote_ip) dp
|
||||
LEFT JOIN device_ip di ON dp.remote_ip = di.alias
|
||||
WHERE di.ip IS NOT NULL ) AS foo
|
||||
GROUP BY left_ip
|
||||
ORDER BY left_ip
|
||||
ENDSQL
|
||||
|
||||
__PACKAGE__->add_columns(
|
||||
'left_ip' => {
|
||||
data_type => 'inet',
|
||||
},
|
||||
'links' => {
|
||||
data_type => 'inet[]',
|
||||
}
|
||||
);
|
||||
|
||||
__PACKAGE__->belongs_to('device', 'App::Netdisco::DB::Result::Device',
|
||||
{ 'foreign.ip' => 'self.left_ip' });
|
||||
|
||||
1;
|
||||
61
lib/App/Netdisco/DB/Result/Virtual/UndiscoveredNeighbors.pm
Normal file
61
lib/App/Netdisco/DB/Result/Virtual/UndiscoveredNeighbors.pm
Normal file
@@ -0,0 +1,61 @@
|
||||
package App::Netdisco::DB::Result::Virtual::UndiscoveredNeighbors;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use utf8;
|
||||
use base 'DBIx::Class::Core';
|
||||
|
||||
__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
|
||||
|
||||
__PACKAGE__->table('undiscovered_neighbors');
|
||||
__PACKAGE__->result_source_instance->is_virtual(1);
|
||||
__PACKAGE__->result_source_instance->view_definition(<<'ENDSQL');
|
||||
SELECT DISTINCT ON (p.remote_ip) d.ip,
|
||||
d.name,
|
||||
d.dns,
|
||||
p.port,
|
||||
p.remote_ip,
|
||||
p.remote_id,
|
||||
p.remote_type,
|
||||
p.remote_port,
|
||||
a.log,
|
||||
a.finished
|
||||
FROM device_port p
|
||||
JOIN device d
|
||||
ON d.ip = p.ip
|
||||
LEFT JOIN admin a
|
||||
ON (p.remote_ip = a.device AND a.action = 'discover')
|
||||
WHERE
|
||||
(p.remote_ip NOT IN (SELECT alias FROM device_ip))
|
||||
OR
|
||||
((p.remote_ip IS NULL) AND p.is_uplink)
|
||||
ORDER BY
|
||||
p.remote_ip ASC,
|
||||
a.finished DESC
|
||||
ENDSQL
|
||||
|
||||
__PACKAGE__->add_columns(
|
||||
"ip",
|
||||
{ data_type => "inet", is_nullable => 0 },
|
||||
"name",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"dns",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"port",
|
||||
{ data_type => "text", is_nullable => 0 },
|
||||
"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 },
|
||||
"log",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"finished",
|
||||
{ data_type => "timestamp", is_nullable => 1 },
|
||||
);
|
||||
|
||||
1;
|
||||
30
lib/App/Netdisco/DB/Result/Virtual/UserRole.pm
Normal file
30
lib/App/Netdisco/DB/Result/Virtual/UserRole.pm
Normal file
@@ -0,0 +1,30 @@
|
||||
use utf8;
|
||||
package App::Netdisco::DB::Result::Virtual::UserRole;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use base 'DBIx::Class::Core';
|
||||
|
||||
__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
|
||||
|
||||
__PACKAGE__->table("user_role");
|
||||
__PACKAGE__->result_source_instance->is_virtual(1);
|
||||
__PACKAGE__->result_source_instance->view_definition(<<ENDSQL
|
||||
SELECT username, 'port_control' AS role FROM users
|
||||
WHERE port_control
|
||||
UNION
|
||||
SELECT username, 'admin' AS role FROM users
|
||||
WHERE admin
|
||||
UNION
|
||||
SELECT username, 'ldap' AS role FROM users
|
||||
WHERE ldap
|
||||
ENDSQL
|
||||
);
|
||||
|
||||
__PACKAGE__->add_columns(
|
||||
'username' => { data_type => 'text' },
|
||||
'role' => { data_type => 'text' },
|
||||
);
|
||||
|
||||
1;
|
||||
195
lib/App/Netdisco/DB/ResultSet.pm
Normal file
195
lib/App/Netdisco/DB/ResultSet.pm
Normal file
@@ -0,0 +1,195 @@
|
||||
package App::Netdisco::DB::ResultSet;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use base 'DBIx::Class::ResultSet';
|
||||
|
||||
__PACKAGE__->load_components(
|
||||
qw{Helper::ResultSet::SetOperations Helper::ResultSet::Shortcut});
|
||||
|
||||
=head1 ADDITIONAL METHODS
|
||||
|
||||
=head2 get_distinct_col( $column )
|
||||
|
||||
Returns an asciibetical sorted list of the distinct values in the given column
|
||||
of the Device table. This is useful for web forms when you want to provide a
|
||||
drop-down list of possible options.
|
||||
|
||||
=cut
|
||||
|
||||
sub get_distinct_col {
|
||||
my ( $rs, $col ) = @_;
|
||||
return $rs unless $col;
|
||||
|
||||
return $rs->search(
|
||||
{},
|
||||
{ columns => [$col],
|
||||
order_by => $col,
|
||||
distinct => 1
|
||||
}
|
||||
)->get_column($col)->all;
|
||||
}
|
||||
|
||||
=head2 get_datatables_data( $params )
|
||||
|
||||
Returns a ResultSet for DataTables Server-side processing which populates
|
||||
the displayed table. Evaluates the supplied query parameters for filtering,
|
||||
paging, and ordering information. Note: query paramters are expected to be
|
||||
passed as a reference to an expanded hash of hashes.
|
||||
|
||||
Filtering if present, will generate simple LIKE matching conditions for each
|
||||
searchable column (searchability indicated by query parameters) after each
|
||||
column is casted to text. Conditions are combined as disjunction (OR).
|
||||
Note: this does not match the built-in DataTables filtering which does it
|
||||
word by word on any field.
|
||||
|
||||
=cut
|
||||
|
||||
sub get_datatables_data {
|
||||
my $rs = shift;
|
||||
my $params = shift;
|
||||
my $attrs = shift;
|
||||
|
||||
die "condition parameter to search_by_field must be hashref\n"
|
||||
if ref {} ne ref $params
|
||||
or 0 == scalar keys %$params;
|
||||
|
||||
# -- Paging
|
||||
$rs = $rs->_with_datatables_paging($params);
|
||||
|
||||
# -- Ordering
|
||||
$rs = $rs->_with_datatables_order_clause($params);
|
||||
|
||||
# -- Filtering
|
||||
$rs = $rs->_with_datatables_where_clause($params);
|
||||
|
||||
return $rs;
|
||||
}
|
||||
|
||||
=head2 get_datatables_filtered_count( $params )
|
||||
|
||||
Returns the total records, after filtering (i.e. the total number of
|
||||
records after filtering has been applied - not just the number of records
|
||||
being returned for this page of data) for a datatables ResultSet and
|
||||
query parameters. Note: query paramters are expected to be passed as a
|
||||
reference to an expanded hash of hashes.
|
||||
|
||||
=cut
|
||||
|
||||
sub get_datatables_filtered_count {
|
||||
my $rs = shift;
|
||||
my $params = shift;
|
||||
|
||||
return $rs->_with_datatables_where_clause($params)->count;
|
||||
|
||||
}
|
||||
|
||||
sub _with_datatables_order_clause {
|
||||
my $rs = shift;
|
||||
my $params = shift;
|
||||
my $attrs = shift;
|
||||
|
||||
my @order = ();
|
||||
|
||||
if ( defined $params->{'order'}{0} ) {
|
||||
for ( my $i = 0; $i < (scalar keys %{$params->{'order'}}); $i++ ) {
|
||||
|
||||
# build direction, must be '-asc' or '-desc' (cf. SQL::Abstract)
|
||||
# we only get 'asc' or 'desc', so they have to be prefixed with '-'
|
||||
my $direction = '-' . $params->{'order'}{$i}{'dir'};
|
||||
|
||||
# We only get the column index (starting from 0), so we have to
|
||||
# translate the index into a column name.
|
||||
my $column_name = _datatables_index_to_column( $params,
|
||||
$params->{'order'}{$i}{'column'} );
|
||||
|
||||
# Prefix with table alias if no prefix
|
||||
my $csa = $rs->current_source_alias;
|
||||
$column_name =~ s/^(\w+)$/$csa\.$1/x;
|
||||
push @order, { $direction => $column_name };
|
||||
}
|
||||
}
|
||||
|
||||
$rs = $rs->order_by( \@order );
|
||||
return $rs;
|
||||
}
|
||||
|
||||
# NOTE this does not match the built-in DataTables filtering which does it
|
||||
# word by word on any field.
|
||||
#
|
||||
# General filtering using LIKE, this will not be efficient as is will not
|
||||
# be able to use indexes.
|
||||
|
||||
sub _with_datatables_where_clause {
|
||||
my $rs = shift;
|
||||
my $params = shift;
|
||||
my $attrs = shift;
|
||||
|
||||
my %where = ();
|
||||
|
||||
if ( defined $params->{'search'}{'value'}
|
||||
&& $params->{'search'}{'value'} )
|
||||
{
|
||||
my $search_string = $params->{'search'}{'value'};
|
||||
for ( my $i = 0; $i < (scalar keys %{$params->{'columns'}}); $i++ ) {
|
||||
|
||||
# Iterate over each column and check if it is searchable.
|
||||
# If so, add a constraint to the where clause restricting the given
|
||||
# column. In the query, the column is identified by it's index, we
|
||||
# need to translate the index to the column name.
|
||||
if ( $params->{'columns'}{$i}{'searchable'}
|
||||
and $params->{'columns'}{$i}{'searchable'} eq 'true' )
|
||||
{
|
||||
my $column = _datatables_index_to_column( $params, $i );
|
||||
my $csa = $rs->current_source_alias;
|
||||
$column =~ s/^(\w+)$/$csa\.$1/x;
|
||||
|
||||
# Cast everything to text for LIKE search
|
||||
$column = $column . '::text';
|
||||
push @{ $where{'-or'} },
|
||||
{ $column => { -like => '%' . $search_string . '%' } };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$rs = $rs->search( \%where, $attrs );
|
||||
return $rs;
|
||||
}
|
||||
|
||||
sub _with_datatables_paging {
|
||||
my $rs = shift;
|
||||
my $params = shift;
|
||||
my $attrs = shift;
|
||||
|
||||
my $limit = $params->{'length'};
|
||||
|
||||
my $offset = 0;
|
||||
if ( defined $params->{'start'} && $params->{'start'} ) {
|
||||
$offset = $params->{'start'};
|
||||
}
|
||||
$attrs->{'offset'} = $offset;
|
||||
|
||||
$rs = $rs->search( {}, $attrs );
|
||||
$rs = $rs->limit($limit) if ($limit and $limit > 0);
|
||||
|
||||
return $rs;
|
||||
}
|
||||
|
||||
# Use the DataTables columns.data definition to derive the column
|
||||
# name from the index.
|
||||
|
||||
sub _datatables_index_to_column {
|
||||
my $params = shift;
|
||||
my $i = shift;
|
||||
|
||||
my $field;
|
||||
|
||||
if ( !defined($i) ) {
|
||||
$i = 0;
|
||||
}
|
||||
$field = $params->{'columns'}{$i}{'data'};
|
||||
return $field;
|
||||
}
|
||||
|
||||
1;
|
||||
45
lib/App/Netdisco/DB/ResultSet/Admin.pm
Normal file
45
lib/App/Netdisco/DB/ResultSet/Admin.pm
Normal file
@@ -0,0 +1,45 @@
|
||||
package App::Netdisco::DB::ResultSet::Admin;
|
||||
use base 'App::Netdisco::DB::ResultSet';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
__PACKAGE__->load_components(qw/
|
||||
+App::Netdisco::DB::ExplicitLocking
|
||||
/);
|
||||
|
||||
=head1 ADDITIONAL METHODS
|
||||
|
||||
=head2 with_times
|
||||
|
||||
This is a modifier for any C<search()> (including the helpers below) which
|
||||
will add the following additional synthesized columns to the result set:
|
||||
|
||||
=over 4
|
||||
|
||||
=item entered_stamp
|
||||
|
||||
=item started_stamp
|
||||
|
||||
=item finished_stamp
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub with_times {
|
||||
my ($rs, $cond, $attrs) = @_;
|
||||
|
||||
return $rs
|
||||
->search_rs($cond, $attrs)
|
||||
->search({},
|
||||
{
|
||||
'+columns' => {
|
||||
entered_stamp => \"to_char(entered, 'YYYY-MM-DD HH24:MI')",
|
||||
started_stamp => \"to_char(started, 'YYYY-MM-DD HH24:MI')",
|
||||
finished_stamp => \"to_char(finished, 'YYYY-MM-DD HH24:MI')",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
1;
|
||||
612
lib/App/Netdisco/DB/ResultSet/Device.pm
Normal file
612
lib/App/Netdisco/DB/ResultSet/Device.pm
Normal file
@@ -0,0 +1,612 @@
|
||||
package App::Netdisco::DB::ResultSet::Device;
|
||||
use base 'App::Netdisco::DB::ResultSet';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use NetAddr::IP::Lite ':lower';
|
||||
|
||||
=head1 ADDITIONAL METHODS
|
||||
|
||||
=head2 with_times
|
||||
|
||||
This is a modifier for any C<search()> (including the helpers below) which
|
||||
will add the following additional synthesized columns to the result set:
|
||||
|
||||
=over 4
|
||||
|
||||
=item uptime_age
|
||||
|
||||
=item last_discover_stamp
|
||||
|
||||
=item last_macsuck_stamp
|
||||
|
||||
=item last_arpnip_stamp
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub with_times {
|
||||
my ($rs, $cond, $attrs) = @_;
|
||||
|
||||
return $rs
|
||||
->search_rs($cond, $attrs)
|
||||
->search({},
|
||||
{
|
||||
'+columns' => {
|
||||
uptime_age => \("replace(age(timestamp 'epoch' + uptime / 100 * interval '1 second', "
|
||||
."timestamp '1970-01-01 00:00:00-00')::text, 'mon', 'month')"),
|
||||
last_discover_stamp => \"to_char(last_discover, 'YYYY-MM-DD HH24:MI')",
|
||||
last_macsuck_stamp => \"to_char(last_macsuck, 'YYYY-MM-DD HH24:MI')",
|
||||
last_arpnip_stamp => \"to_char(last_arpnip, 'YYYY-MM-DD HH24:MI')",
|
||||
since_last_discover => \"extract(epoch from (age(now(), last_discover)))",
|
||||
since_last_macsuck => \"extract(epoch from (age(now(), last_macsuck)))",
|
||||
since_last_arpnip => \"extract(epoch from (age(now(), last_arpnip)))",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
=head2 search_aliases( {$name or $ip or $prefix}, \%options? )
|
||||
|
||||
Tries to find devices in Netdisco which have an identity corresponding to
|
||||
C<$name>, C<$ip> or C<$prefix>.
|
||||
|
||||
The search is across all aliases of the device, as well as its "root IP"
|
||||
identity. Note that this search will try B<not> to use DNS, in case the current
|
||||
name for an IP does not correspond to the data within Netdisco.
|
||||
|
||||
Passing a zero value to the C<partial> key of the C<options> hashref will
|
||||
prevent partial matching of a host name. Otherwise the default is to perform
|
||||
a partial, case-insensitive search on the host name fields.
|
||||
|
||||
=cut
|
||||
|
||||
sub search_aliases {
|
||||
my ($rs, $q, $options) = @_;
|
||||
$q ||= '255.255.255.255'; # hack to return empty resultset on error
|
||||
$options ||= {};
|
||||
$options->{partial} = 1 if !defined $options->{partial};
|
||||
|
||||
# rough approximation of IP addresses (v4 in v6 not supported).
|
||||
# this helps us avoid triggering any DNS.
|
||||
my $by_ip = ($q =~ m{^(?:[.0-9/]+|[:0-9a-f/]+)$}i) ? 1 : 0;
|
||||
|
||||
my $clause;
|
||||
if ($by_ip) {
|
||||
my $ip = NetAddr::IP::Lite->new($q)
|
||||
or return undef; # could be a MAC address!
|
||||
$clause = [
|
||||
'me.ip' => { '<<=' => $ip->cidr },
|
||||
'device_ips.alias' => { '<<=' => $ip->cidr },
|
||||
];
|
||||
}
|
||||
else {
|
||||
$q = "\%$q\%" if ($options->{partial} and $q !~ m/\%/);
|
||||
$clause = [
|
||||
'me.name' => { '-ilike' => $q },
|
||||
'me.dns' => { '-ilike' => $q },
|
||||
'device_ips.dns' => { '-ilike' => $q },
|
||||
];
|
||||
}
|
||||
|
||||
return $rs->search(
|
||||
{
|
||||
-or => $clause,
|
||||
},
|
||||
{
|
||||
order_by => [qw/ me.dns me.ip /],
|
||||
join => 'device_ips',
|
||||
distinct => 1,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
=head2 search_for_device( $name or $ip or $prefix )
|
||||
|
||||
This is a wrapper for C<search_aliases> which:
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
Disables partial matching on host names
|
||||
|
||||
=item *
|
||||
|
||||
Returns only the first result of any found devices
|
||||
|
||||
=back
|
||||
|
||||
If not matching devices are found, C<undef> is returned.
|
||||
|
||||
=cut
|
||||
|
||||
sub search_for_device {
|
||||
my ($rs, $q, $options) = @_;
|
||||
$options ||= {};
|
||||
$options->{partial} = 0;
|
||||
return $rs->search_aliases($q, $options)->first();
|
||||
}
|
||||
|
||||
=head2 search_by_field( \%cond, \%attrs? )
|
||||
|
||||
This variant of the standard C<search()> method returns a ResultSet of Device
|
||||
entries. It is written to support web forms which accept fields that match and
|
||||
locate Devices in the database.
|
||||
|
||||
The hashref parameter should contain fields from the Device table which will
|
||||
be intelligently used in a search query.
|
||||
|
||||
In addition, you can provide the key C<matchall> which, given a True or False
|
||||
value, controls whether fields must all match or whether any can match, to
|
||||
select a row.
|
||||
|
||||
Supported keys:
|
||||
|
||||
=over 4
|
||||
|
||||
=item matchall
|
||||
|
||||
If a True value, fields must all match to return a given row of the Device
|
||||
table, otherwise any field matching will cause the row to be included in
|
||||
results.
|
||||
|
||||
=item name
|
||||
|
||||
Can match the C<name> field as a substring.
|
||||
|
||||
=item location
|
||||
|
||||
Can match the C<location> field as a substring.
|
||||
|
||||
=item description
|
||||
|
||||
Can match the C<description> field as a substring (usually this field contains
|
||||
a description of the vendor operating system).
|
||||
|
||||
=item model
|
||||
|
||||
Will match exactly the C<model> field.
|
||||
|
||||
=item os
|
||||
|
||||
Will match exactly the C<os> field, which is the operating sytem.
|
||||
|
||||
=item os_ver
|
||||
|
||||
Will match exactly the C<os_ver> field, which is the operating sytem software version.
|
||||
|
||||
=item vendor
|
||||
|
||||
Will match exactly the C<vendor> (manufacturer).
|
||||
|
||||
=item dns
|
||||
|
||||
Can match any of the Device IP address aliases as a substring.
|
||||
|
||||
=item ip
|
||||
|
||||
Can be a string IP or a NetAddr::IP object, either way being treated as an
|
||||
IPv4 or IPv6 prefix within which the device must have one IP address alias.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub search_by_field {
|
||||
my ($rs, $p, $attrs) = @_;
|
||||
|
||||
die "condition parameter to search_by_field must be hashref\n"
|
||||
if ref {} ne ref $p or 0 == scalar keys %$p;
|
||||
|
||||
my $op = $p->{matchall} ? '-and' : '-or';
|
||||
|
||||
# this is a bit of an inelegant trick to catch junk data entry,
|
||||
# whilst avoiding returning *all* entries in the table
|
||||
if ($p->{ip} and 'NetAddr::IP::Lite' ne ref $p->{ip}) {
|
||||
$p->{ip} = ( NetAddr::IP::Lite->new($p->{ip})
|
||||
|| NetAddr::IP::Lite->new('255.255.255.255') );
|
||||
}
|
||||
|
||||
# For Search on Layers
|
||||
my @layer_search = ( '_', '_', '_', '_', '_', '_', '_' );
|
||||
# @layer_search is computer indexed, left->right
|
||||
my $layers = $p->{layers};
|
||||
if ( defined $layers && ref $layers ) {
|
||||
foreach my $layer (@$layers) {
|
||||
next unless defined $layer and length($layer);
|
||||
next if ( $layer < 1 || $layer > 7 );
|
||||
$layer_search[ $layer - 1 ] = 1;
|
||||
}
|
||||
}
|
||||
elsif ( defined $layers ) {
|
||||
$layer_search[ $layers - 1 ] = 1;
|
||||
}
|
||||
# the database field is in order 87654321
|
||||
my $layer_string = join( '', reverse @layer_search );
|
||||
|
||||
return $rs
|
||||
->search_rs({}, $attrs)
|
||||
->search({
|
||||
$op => [
|
||||
($p->{name} ? ('me.name' =>
|
||||
{ '-ilike' => "\%$p->{name}\%" }) : ()),
|
||||
($p->{location} ? ('me.location' =>
|
||||
{ '-ilike' => "\%$p->{location}\%" }) : ()),
|
||||
($p->{description} ? ('me.description' =>
|
||||
{ '-ilike' => "\%$p->{description}\%" }) : ()),
|
||||
($p->{layers} ? ('me.layers' =>
|
||||
{ '-ilike' => "\%$layer_string" }) : ()),
|
||||
|
||||
($p->{model} ? ('me.model' =>
|
||||
{ '-in' => $p->{model} }) : ()),
|
||||
($p->{os} ? ('me.os' =>
|
||||
{ '-in' => $p->{os} }) : ()),
|
||||
($p->{os_ver} ? ('me.os_ver' =>
|
||||
{ '-in' => $p->{os_ver} }) : ()),
|
||||
($p->{vendor} ? ('me.vendor' =>
|
||||
{ '-in' => $p->{vendor} }) : ()),
|
||||
|
||||
($p->{dns} ? (
|
||||
-or => [
|
||||
'me.dns' => { '-ilike' => "\%$p->{dns}\%" },
|
||||
'device_ips.dns' => { '-ilike' => "\%$p->{dns}\%" },
|
||||
]) : ()),
|
||||
|
||||
($p->{ip} ? (
|
||||
-or => [
|
||||
'me.ip' => { '<<=' => $p->{ip}->cidr },
|
||||
'device_ips.alias' => { '<<=' => $p->{ip}->cidr },
|
||||
]) : ()),
|
||||
],
|
||||
},
|
||||
{
|
||||
order_by => [qw/ me.dns me.ip /],
|
||||
(($p->{dns} or $p->{ip}) ? (
|
||||
join => 'device_ips',
|
||||
distinct => 1,
|
||||
) : ()),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
=head2 search_fuzzy( $value )
|
||||
|
||||
This method accepts a single parameter only and returns a ResultSet of rows
|
||||
from the Device table where one field matches the passed parameter.
|
||||
|
||||
The following fields are inspected for a match:
|
||||
|
||||
=over 4
|
||||
|
||||
=item contact
|
||||
|
||||
=item serial
|
||||
|
||||
=item location
|
||||
|
||||
=item name
|
||||
|
||||
=item description
|
||||
|
||||
=item dns
|
||||
|
||||
=item ip (including aliases)
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub search_fuzzy {
|
||||
my ($rs, $q) = @_;
|
||||
|
||||
die "missing param to search_fuzzy\n"
|
||||
unless $q;
|
||||
$q = "\%$q\%" if $q !~ m/\%/;
|
||||
|
||||
# basic IP check is a string match
|
||||
my $ip_clause = [
|
||||
'me.ip::text' => { '-ilike' => $q },
|
||||
'device_ips.alias::text' => { '-ilike' => $q },
|
||||
];
|
||||
|
||||
# but also allow prefix search
|
||||
(my $qc = $q) =~ s/\%//g;
|
||||
if (my $ip = NetAddr::IP::Lite->new($qc)) {
|
||||
$ip_clause = [
|
||||
'me.ip' => { '<<=' => $ip->cidr },
|
||||
'device_ips.alias' => { '<<=' => $ip->cidr },
|
||||
];
|
||||
}
|
||||
|
||||
return $rs->search(
|
||||
{
|
||||
-or => [
|
||||
'me.contact' => { '-ilike' => $q },
|
||||
'me.serial' => { '-ilike' => $q },
|
||||
'me.location' => { '-ilike' => $q },
|
||||
'me.name' => { '-ilike' => $q },
|
||||
'me.description' => { '-ilike' => $q },
|
||||
-or => [
|
||||
'me.dns' => { '-ilike' => $q },
|
||||
'device_ips.dns' => { '-ilike' => $q },
|
||||
],
|
||||
-or => $ip_clause,
|
||||
],
|
||||
},
|
||||
{
|
||||
order_by => [qw/ me.dns me.ip /],
|
||||
join => 'device_ips',
|
||||
distinct => 1,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
=head2 carrying_vlan( \%cond, \%attrs? )
|
||||
|
||||
my $set = $rs->carrying_vlan({ vlan => 123 });
|
||||
|
||||
Like C<search()>, this returns a ResultSet of matching rows from the Device
|
||||
table.
|
||||
|
||||
The returned devices each are aware of the given Vlan.
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
The C<cond> parameter must be a hashref containing a key C<vlan> with
|
||||
the value to search for.
|
||||
|
||||
=item *
|
||||
|
||||
Results are ordered by the Device DNS and IP fields.
|
||||
|
||||
=item *
|
||||
|
||||
Related rows from the C<device_vlan> table will be prefetched.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub carrying_vlan {
|
||||
my ($rs, $cond, $attrs) = @_;
|
||||
|
||||
die "vlan number required for carrying_vlan\n"
|
||||
if ref {} ne ref $cond or !exists $cond->{vlan};
|
||||
|
||||
return $rs
|
||||
->search_rs({ 'vlans.vlan' => $cond->{vlan} },
|
||||
{
|
||||
order_by => [qw/ me.dns me.ip /],
|
||||
columns => [
|
||||
'me.ip', 'me.dns',
|
||||
'me.model', 'me.os',
|
||||
'me.vendor', 'vlans.vlan',
|
||||
'vlans.description'
|
||||
],
|
||||
join => 'vlans'
|
||||
})
|
||||
->search({}, $attrs);
|
||||
}
|
||||
|
||||
=head2 carrying_vlan_name( \%cond, \%attrs? )
|
||||
|
||||
my $set = $rs->carrying_vlan_name({ name => 'Branch Office' });
|
||||
|
||||
Like C<search()>, this returns a ResultSet of matching rows from the Device
|
||||
table.
|
||||
|
||||
The returned devices each are aware of the named Vlan.
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
The C<cond> parameter must be a hashref containing a key C<name> with
|
||||
the value to search for. The value may optionally include SQL wildcard
|
||||
characters.
|
||||
|
||||
=item *
|
||||
|
||||
Results are ordered by the Device DNS and IP fields.
|
||||
|
||||
=item *
|
||||
|
||||
Related rows from the C<device_vlan> table will be prefetched.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub carrying_vlan_name {
|
||||
my ($rs, $cond, $attrs) = @_;
|
||||
|
||||
die "vlan name required for carrying_vlan_name\n"
|
||||
if ref {} ne ref $cond or !exists $cond->{name};
|
||||
|
||||
$cond->{'vlans.description'} = { '-ilike' => delete $cond->{name} };
|
||||
|
||||
return $rs
|
||||
->search_rs({}, {
|
||||
order_by => [qw/ me.dns me.ip /],
|
||||
columns => [
|
||||
'me.ip', 'me.dns',
|
||||
'me.model', 'me.os',
|
||||
'me.vendor', 'vlans.vlan',
|
||||
'vlans.description'
|
||||
],
|
||||
join => 'vlans'
|
||||
})
|
||||
->search($cond, $attrs);
|
||||
}
|
||||
|
||||
=head2 has_layer( $layer )
|
||||
|
||||
my $rset = $rs->has_layer(3);
|
||||
|
||||
This predefined C<search()> returns a ResultSet of matching rows from the
|
||||
Device table of devices advertising support of the supplied layer in the
|
||||
OSI Model.
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
The C<layer> parameter must be an integer between 1 and 7.
|
||||
|
||||
=cut
|
||||
|
||||
sub has_layer {
|
||||
my ( $rs, $layer ) = @_;
|
||||
|
||||
die "layer required and must be between 1 and 7\n"
|
||||
if !$layer || $layer < 1 || $layer > 7;
|
||||
|
||||
return $rs->search_rs( \[ 'substring(layers,9-?, 1)::int = 1', $layer ] );
|
||||
}
|
||||
|
||||
=back
|
||||
|
||||
=head2 get_models
|
||||
|
||||
Returns a sorted list of Device models with the following columns only:
|
||||
|
||||
=over 4
|
||||
|
||||
=item vendor
|
||||
|
||||
=item model
|
||||
|
||||
=item count
|
||||
|
||||
=back
|
||||
|
||||
Where C<count> is the number of instances of that Vendor's Model in the
|
||||
Netdisco database.
|
||||
|
||||
=cut
|
||||
|
||||
sub get_models {
|
||||
my $rs = shift;
|
||||
return $rs->search({}, {
|
||||
select => [ 'vendor', 'model', { count => 'ip' } ],
|
||||
as => [qw/vendor model count/],
|
||||
group_by => [qw/vendor model/],
|
||||
order_by => [{-asc => 'vendor'}, {-asc => 'model'}],
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
=head2 get_releases
|
||||
|
||||
Returns a sorted list of Device OS releases with the following columns only:
|
||||
|
||||
=over 4
|
||||
|
||||
=item os
|
||||
|
||||
=item os_ver
|
||||
|
||||
=item count
|
||||
|
||||
=back
|
||||
|
||||
Where C<count> is the number of devices running that OS release in the
|
||||
Netdisco database.
|
||||
|
||||
=cut
|
||||
|
||||
sub get_releases {
|
||||
my $rs = shift;
|
||||
return $rs->search({}, {
|
||||
select => [ 'os', 'os_ver', { count => 'ip' } ],
|
||||
as => [qw/os os_ver count/],
|
||||
group_by => [qw/os os_ver/],
|
||||
order_by => [{-asc => 'os'}, {-asc => 'os_ver'}],
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
=head2 with_port_count
|
||||
|
||||
This is a modifier for any C<search()> which
|
||||
will add the following additional synthesized column to the result set:
|
||||
|
||||
=over 4
|
||||
|
||||
=item port_count
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub with_port_count {
|
||||
my ($rs, $cond, $attrs) = @_;
|
||||
|
||||
return $rs
|
||||
->search_rs($cond, $attrs)
|
||||
->search({},
|
||||
{
|
||||
'+columns' => {
|
||||
port_count =>
|
||||
$rs->result_source->schema->resultset('DevicePort')
|
||||
->search(
|
||||
{
|
||||
'dp.ip' => { -ident => 'me.ip' },
|
||||
'dp.type' => { '!=' => 'propVirtual' },
|
||||
},
|
||||
{ alias => 'dp' }
|
||||
)->count_rs->as_query,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
=head1 SPECIAL METHODS
|
||||
|
||||
=head2 delete( \%options? )
|
||||
|
||||
Overrides the built-in L<DBIx::Class> delete method to more efficiently
|
||||
handle the removal or archiving of nodes.
|
||||
|
||||
=cut
|
||||
|
||||
sub delete {
|
||||
my $self = shift;
|
||||
|
||||
my $schema = $self->result_source->schema;
|
||||
my $devices = $self->search(undef, { columns => 'ip' });
|
||||
|
||||
foreach my $set (qw/
|
||||
DeviceIp
|
||||
DeviceVlan
|
||||
DevicePower
|
||||
DeviceModule
|
||||
Community
|
||||
/) {
|
||||
$schema->resultset($set)->search(
|
||||
{ ip => { '-in' => $devices->as_query } },
|
||||
)->delete;
|
||||
}
|
||||
|
||||
$schema->resultset('Admin')->search({
|
||||
device => { '-in' => $devices->as_query },
|
||||
})->delete;
|
||||
|
||||
$schema->resultset('Topology')->search({
|
||||
-or => [
|
||||
{ dev1 => { '-in' => $devices->as_query } },
|
||||
{ dev2 => { '-in' => $devices->as_query } },
|
||||
],
|
||||
})->delete;
|
||||
|
||||
$schema->resultset('DevicePort')->search(
|
||||
{ ip => { '-in' => $devices->as_query } },
|
||||
)->delete(@_);
|
||||
|
||||
# now let DBIC do its thing
|
||||
return $self->next::method();
|
||||
}
|
||||
|
||||
1;
|
||||
107
lib/App/Netdisco/DB/ResultSet/DeviceModule.pm
Normal file
107
lib/App/Netdisco/DB/ResultSet/DeviceModule.pm
Normal file
@@ -0,0 +1,107 @@
|
||||
package App::Netdisco::DB::ResultSet::DeviceModule;
|
||||
use base 'App::Netdisco::DB::ResultSet';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
=head1 ADDITIONAL METHODS
|
||||
|
||||
=head2 search_by_field( \%cond, \%attrs? )
|
||||
|
||||
This variant of the standard C<search()> method returns a ResultSet of Device
|
||||
Module entries. It is written to support web forms which accept fields that
|
||||
match and locate Device Modules in the database.
|
||||
|
||||
The hashref parameter should contain fields from the Device Module table
|
||||
which will be intelligently used in a search query.
|
||||
|
||||
In addition, you can provide the key C<matchall> which, given a True or False
|
||||
value, controls whether fields must all match or whether any can match, to
|
||||
select a row.
|
||||
|
||||
Supported keys:
|
||||
|
||||
=over 4
|
||||
|
||||
=item matchall
|
||||
|
||||
If a True value, fields must all match to return a given row of the Device
|
||||
table, otherwise any field matching will cause the row to be included in
|
||||
results.
|
||||
|
||||
=item description
|
||||
|
||||
Can match the C<description> field as a substring.
|
||||
|
||||
=item name
|
||||
|
||||
Can match the C<name> field as a substring.
|
||||
|
||||
=item type
|
||||
|
||||
Can match the C<type> field as a substring.
|
||||
|
||||
=item model
|
||||
|
||||
Can match the C<model> field as a substring.
|
||||
|
||||
=item serial
|
||||
|
||||
Can match the C<serial> field as a substring.
|
||||
|
||||
=item class
|
||||
|
||||
Will match exactly the C<class> field.
|
||||
|
||||
=item ips
|
||||
|
||||
List of Device IPs containing modules.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub search_by_field {
|
||||
my ( $rs, $p, $attrs ) = @_;
|
||||
|
||||
die "condition parameter to search_by_field must be hashref\n"
|
||||
if ref {} ne ref $p
|
||||
or 0 == scalar keys %$p;
|
||||
|
||||
my $op = $p->{matchall} ? '-and' : '-or';
|
||||
|
||||
return $rs->search_rs( {}, $attrs )->search(
|
||||
{ $op => [
|
||||
( $p->{description}
|
||||
? ( 'me.description' =>
|
||||
{ '-ilike' => "\%$p->{description}\%" } )
|
||||
: ()
|
||||
),
|
||||
( $p->{name}
|
||||
? ( 'me.name' => { '-ilike' => "\%$p->{name}\%" } )
|
||||
: ()
|
||||
),
|
||||
( $p->{type}
|
||||
? ( 'me.type' => { '-ilike' => "\%$p->{type}\%" } )
|
||||
: ()
|
||||
),
|
||||
( $p->{model}
|
||||
? ( 'me.model' => { '-ilike' => "\%$p->{model}\%" } )
|
||||
: ()
|
||||
),
|
||||
( $p->{serial}
|
||||
? ( 'me.serial' => { '-ilike' => "\%$p->{serial}\%" } )
|
||||
: ()
|
||||
),
|
||||
|
||||
( $p->{class}
|
||||
? ( 'me.class' => { '-in' => $p->{class} } )
|
||||
: ()
|
||||
),
|
||||
( $p->{ips} ? ( 'me.ip' => { '-in' => $p->{ips} } ) : () ),
|
||||
],
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
1;
|
||||
174
lib/App/Netdisco/DB/ResultSet/DevicePort.pm
Normal file
174
lib/App/Netdisco/DB/ResultSet/DevicePort.pm
Normal file
@@ -0,0 +1,174 @@
|
||||
package App::Netdisco::DB::ResultSet::DevicePort;
|
||||
use base 'App::Netdisco::DB::ResultSet';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
__PACKAGE__->load_components(qw/
|
||||
+App::Netdisco::DB::ExplicitLocking
|
||||
/);
|
||||
|
||||
=head1 ADDITIONAL METHODS
|
||||
|
||||
=head2 with_times
|
||||
|
||||
This is a modifier for any C<search()> (including the helpers below) which
|
||||
will add the following additional synthesized columns to the result set:
|
||||
|
||||
=over 4
|
||||
|
||||
=item lastchange_stamp
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub with_times {
|
||||
my ($rs, $cond, $attrs) = @_;
|
||||
|
||||
return $rs
|
||||
->search_rs($cond, $attrs)
|
||||
->search({},
|
||||
{
|
||||
'+columns' => { lastchange_stamp =>
|
||||
\("to_char(device.last_discover - (device.uptime - me.lastchange) / 100 * interval '1 second', "
|
||||
."'YYYY-MM-DD HH24:MI:SS')") },
|
||||
join => 'device',
|
||||
});
|
||||
}
|
||||
|
||||
=head2 with_free_ports
|
||||
|
||||
This is a modifier for any C<search()> (including the helpers below) which
|
||||
will add the following additional synthesized columns to the result set:
|
||||
|
||||
=over 4
|
||||
|
||||
=item is_free
|
||||
|
||||
=back
|
||||
|
||||
In the C<$cond> hash (the first parameter) pass in the C<age_num> which must
|
||||
be an integer, and the C<age_unit> which must be a string of either C<days>,
|
||||
C<weeks>, C<months> or C<years>.
|
||||
|
||||
=cut
|
||||
|
||||
sub with_is_free {
|
||||
my ($rs, $cond, $attrs) = @_;
|
||||
|
||||
my $interval = (delete $cond->{age_num}) .' '. (delete $cond->{age_unit});
|
||||
|
||||
return $rs
|
||||
->search_rs($cond, $attrs)
|
||||
->search({},
|
||||
{
|
||||
'+columns' => { is_free =>
|
||||
\["me.up != 'up' and "
|
||||
."age(now(), to_timestamp(extract(epoch from device.last_discover) "
|
||||
."- (device.uptime - me.lastchange)/100)) "
|
||||
."> ?::interval",
|
||||
[{} => $interval]] },
|
||||
join => 'device',
|
||||
});
|
||||
}
|
||||
|
||||
=head2 only_free_ports
|
||||
|
||||
This is a modifier for any C<search()> (including the helpers below) which
|
||||
will restrict results based on whether the port is considered "free".
|
||||
|
||||
In the C<$cond> hash (the first parameter) pass in the C<age_num> which must
|
||||
be an integer, and the C<age_unit> which must be a string of either C<days>,
|
||||
C<weeks>, C<months> or C<years>.
|
||||
|
||||
=cut
|
||||
|
||||
sub only_free_ports {
|
||||
my ($rs, $cond, $attrs) = @_;
|
||||
|
||||
my $interval = (delete $cond->{age_num}) .' '. (delete $cond->{age_unit});
|
||||
|
||||
return $rs
|
||||
->search_rs($cond, $attrs)
|
||||
->search(
|
||||
{
|
||||
'me.up' => { '!=' => 'up' },
|
||||
},{
|
||||
where =>
|
||||
\["age(now(), to_timestamp(extract(epoch from device.last_discover) "
|
||||
."- (device.uptime - me.lastchange)/100)) "
|
||||
."> ?::interval",
|
||||
[{} => $interval]],
|
||||
join => 'device' },
|
||||
);
|
||||
}
|
||||
|
||||
=head2 with_vlan_count
|
||||
|
||||
This is a modifier for any C<search()> (including the helpers below) which
|
||||
will add the following additional synthesized columns to the result set:
|
||||
|
||||
=over 4
|
||||
|
||||
=item vlan_count
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub with_vlan_count {
|
||||
my ($rs, $cond, $attrs) = @_;
|
||||
|
||||
return $rs
|
||||
->search_rs($cond, $attrs)
|
||||
->search({},
|
||||
{
|
||||
'+columns' => { vlan_count =>
|
||||
$rs->result_source->schema->resultset('DevicePortVlan')
|
||||
->search(
|
||||
{
|
||||
'dpv.ip' => { -ident => 'me.ip' },
|
||||
'dpv.port' => { -ident => 'me.port' },
|
||||
},
|
||||
{ alias => 'dpv' }
|
||||
)->count_rs->as_query
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
=head1 SPECIAL METHODS
|
||||
|
||||
=head2 delete( \%options? )
|
||||
|
||||
Overrides the built-in L<DBIx::Class> delete method to more efficiently
|
||||
handle the removal or archiving of nodes.
|
||||
|
||||
=cut
|
||||
|
||||
sub delete {
|
||||
my $self = shift;
|
||||
|
||||
my $schema = $self->result_source->schema;
|
||||
my $ports = $self->search(undef, { columns => 'ip' });
|
||||
|
||||
foreach my $set (qw/
|
||||
DevicePortPower
|
||||
DevicePortVlan
|
||||
DevicePortWireless
|
||||
DevicePortSsid
|
||||
/) {
|
||||
$schema->resultset($set)->search(
|
||||
{ ip => { '-in' => $ports->as_query }},
|
||||
)->delete;
|
||||
}
|
||||
|
||||
$schema->resultset('Node')->search(
|
||||
{ switch => { '-in' => $ports->as_query }},
|
||||
)->delete(@_);
|
||||
|
||||
# now let DBIC do its thing
|
||||
return $self->next::method();
|
||||
}
|
||||
|
||||
1;
|
||||
39
lib/App/Netdisco/DB/ResultSet/DevicePortLog.pm
Normal file
39
lib/App/Netdisco/DB/ResultSet/DevicePortLog.pm
Normal file
@@ -0,0 +1,39 @@
|
||||
package App::Netdisco::DB::ResultSet::DevicePortLog;
|
||||
use base 'App::Netdisco::DB::ResultSet';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
__PACKAGE__->load_components(qw/
|
||||
+App::Netdisco::DB::ExplicitLocking
|
||||
/);
|
||||
|
||||
=head1 ADDITIONAL METHODS
|
||||
|
||||
=head2 with_times
|
||||
|
||||
This is a modifier for any C<search()> which will add the following additional
|
||||
synthesized column to the result set:
|
||||
|
||||
=over 4
|
||||
|
||||
=item creation_stamp
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub with_times {
|
||||
my ($rs, $cond, $attrs) = @_;
|
||||
|
||||
return $rs
|
||||
->search_rs($cond, $attrs)
|
||||
->search({},
|
||||
{
|
||||
'+columns' => {
|
||||
creation_stamp => \"to_char(creation, 'YYYY-MM-DD HH24:MI:SS')",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
1;
|
||||
48
lib/App/Netdisco/DB/ResultSet/DevicePortSsid.pm
Normal file
48
lib/App/Netdisco/DB/ResultSet/DevicePortSsid.pm
Normal file
@@ -0,0 +1,48 @@
|
||||
package App::Netdisco::DB::ResultSet::DevicePortSsid;
|
||||
use base 'App::Netdisco::DB::ResultSet';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
__PACKAGE__->load_components(
|
||||
qw/
|
||||
+App::Netdisco::DB::ExplicitLocking
|
||||
/
|
||||
);
|
||||
|
||||
=head1 ADDITIONAL METHODS
|
||||
|
||||
=head2 get_ssids
|
||||
|
||||
Returns a sorted list of SSIDs with the following columns only:
|
||||
|
||||
=over 4
|
||||
|
||||
=item ssid
|
||||
|
||||
=item broadcast
|
||||
|
||||
=item count
|
||||
|
||||
=back
|
||||
|
||||
Where C<count> is the number of instances of the SSID in the Netdisco
|
||||
database.
|
||||
|
||||
=cut
|
||||
|
||||
sub get_ssids {
|
||||
my $rs = shift;
|
||||
|
||||
return $rs->search(
|
||||
{},
|
||||
{ select => [ 'ssid', 'broadcast', { count => 'ssid' } ],
|
||||
as => [qw/ ssid broadcast count /],
|
||||
group_by => [qw/ ssid broadcast /],
|
||||
order_by => { -desc => [qw/count/] },
|
||||
}
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
1;
|
||||
78
lib/App/Netdisco/DB/ResultSet/DevicePower.pm
Normal file
78
lib/App/Netdisco/DB/ResultSet/DevicePower.pm
Normal file
@@ -0,0 +1,78 @@
|
||||
package App::Netdisco::DB::ResultSet::DevicePower;
|
||||
use base 'App::Netdisco::DB::ResultSet';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
=head1 ADDITIONAL METHODS
|
||||
|
||||
|
||||
=head2 with_poestats
|
||||
|
||||
This is a modifier for any C<search()> which will add the following
|
||||
additional synthesized columns to the result set:
|
||||
|
||||
=over 4
|
||||
|
||||
=item poe_capable_ports
|
||||
|
||||
Count of ports which have the ability to supply PoE.
|
||||
|
||||
=item poe_powered_ports
|
||||
|
||||
Count of ports with PoE administratively disabled.
|
||||
|
||||
=item poe_disabled_ports
|
||||
|
||||
Count of ports which are delivering power.
|
||||
|
||||
=item poe_errored_ports
|
||||
|
||||
Count of ports either reporting a fault or in test mode.
|
||||
|
||||
=item poe_power_committed
|
||||
|
||||
Total power that has been negotiated and therefore committed on ports
|
||||
actively supplying power.
|
||||
|
||||
=item poe_power_delivering
|
||||
|
||||
Total power as measured on ports actively supplying power.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub with_poestats {
|
||||
my ($rs, $cond, $attrs) = @_;
|
||||
|
||||
return $rs
|
||||
->search_rs($cond, $attrs)
|
||||
->search({},
|
||||
{
|
||||
'columns' => {
|
||||
ip => \"DISTINCT ON (me.ip, me.module) me.ip",
|
||||
module => 'module',
|
||||
power => 'power::bigint',
|
||||
status => 'status',
|
||||
poe_capable_ports => \"COUNT(ports.port) OVER (PARTITION BY me.ip, me.module)",
|
||||
poe_powered_ports => \"SUM(CASE WHEN ports.status = 'deliveringPower' THEN 1 ELSE 0 END) OVER (PARTITION BY me.ip, me.module)",
|
||||
poe_disabled_ports => \"SUM(CASE WHEN ports.admin = 'false' THEN 1 ELSE 0 END) OVER (PARTITION BY me.ip, me.module)",
|
||||
poe_errored_ports => \"SUM(CASE WHEN ports.status ILIKE '%fault' THEN 1 ELSE 0 END) OVER (PARTITION BY me.ip, me.module)",
|
||||
poe_power_committed => \("SUM(CASE "
|
||||
. "WHEN ports.status = 'deliveringPower' AND ports.class = 'class0' THEN 15.4 "
|
||||
. "WHEN ports.status = 'deliveringPower' AND ports.class = 'class1' THEN 4.0 "
|
||||
. "WHEN ports.status = 'deliveringPower' AND ports.class = 'class2' THEN 7.0 "
|
||||
. "WHEN ports.status = 'deliveringPower' AND ports.class = 'class3' THEN 15.4 "
|
||||
. "WHEN ports.status = 'deliveringPower' AND ports.class = 'class4' THEN 30.0 "
|
||||
. "WHEN ports.status = 'deliveringPower' AND ports.class IS NULL THEN 15.4 "
|
||||
. "ELSE 0 END) OVER (PARTITION BY me.ip, me.module)"),
|
||||
poe_power_delivering => \("SUM(CASE WHEN (ports.power IS NULL OR ports.power = '0') "
|
||||
. "THEN 0 ELSE round(ports.power/1000.0, 1) END) "
|
||||
. "OVER (PARTITION BY me.ip, me.module)")
|
||||
},
|
||||
join => 'ports'
|
||||
});
|
||||
}
|
||||
|
||||
1;
|
||||
149
lib/App/Netdisco/DB/ResultSet/Node.pm
Normal file
149
lib/App/Netdisco/DB/ResultSet/Node.pm
Normal file
@@ -0,0 +1,149 @@
|
||||
package App::Netdisco::DB::ResultSet::Node;
|
||||
use base 'App::Netdisco::DB::ResultSet';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
__PACKAGE__->load_components(qw/
|
||||
+App::Netdisco::DB::ExplicitLocking
|
||||
/);
|
||||
|
||||
=head1 ADDITIONAL METHODS
|
||||
|
||||
=head2 search_by_mac( \%cond, \%attrs? )
|
||||
|
||||
my $set = $rs->search_by_mac({mac => '00:11:22:33:44:55', active => 1});
|
||||
|
||||
Like C<search()>, this returns a ResultSet of matching rows from the Node
|
||||
table.
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
The C<cond> parameter must be a hashref containing a key C<mac> with
|
||||
the value to search for.
|
||||
|
||||
=item *
|
||||
|
||||
Results are ordered by time last seen.
|
||||
|
||||
=item *
|
||||
|
||||
Additional columns C<time_first_stamp> and C<time_last_stamp> provide
|
||||
preformatted timestamps of the C<time_first> and C<time_last> fields.
|
||||
|
||||
=item *
|
||||
|
||||
A JOIN is performed on the Device table and the Device C<dns> column
|
||||
prefetched.
|
||||
|
||||
=back
|
||||
|
||||
To limit results only to active nodes, set C<< {active => 1} >> in C<cond>.
|
||||
|
||||
=cut
|
||||
|
||||
sub search_by_mac {
|
||||
my ($rs, $cond, $attrs) = @_;
|
||||
|
||||
die "mac address required for search_by_mac\n"
|
||||
if ref {} ne ref $cond or !exists $cond->{mac};
|
||||
|
||||
$cond->{'me.mac'} = delete $cond->{mac};
|
||||
|
||||
return $rs
|
||||
->search_rs({}, {
|
||||
order_by => {'-desc' => 'time_last'},
|
||||
'+columns' => [
|
||||
'device.dns',
|
||||
{ time_first_stamp => \"to_char(time_first, 'YYYY-MM-DD HH24:MI')" },
|
||||
{ time_last_stamp => \"to_char(time_last, 'YYYY-MM-DD HH24:MI')" },
|
||||
],
|
||||
join => 'device',
|
||||
})
|
||||
->search($cond, $attrs);
|
||||
}
|
||||
|
||||
=head1 SPECIAL METHODS
|
||||
|
||||
=head2 delete( \%options? )
|
||||
|
||||
Overrides the built-in L<DBIx::Class> delete method to more efficiently
|
||||
handle the removal or archiving of nodes.
|
||||
|
||||
=cut
|
||||
|
||||
sub delete {
|
||||
my $self = shift;
|
||||
my ($opts) = @_;
|
||||
$opts = {} if (ref {} ne ref $opts);
|
||||
|
||||
my $schema = $self->result_source->schema;
|
||||
my $nodes = $self->search(undef, { columns => 'mac' });
|
||||
|
||||
if (exists $opts->{archive_nodes} and $opts->{archive_nodes}) {
|
||||
foreach my $set (qw/
|
||||
NodeIp
|
||||
NodeNbt
|
||||
NodeMonitor
|
||||
Node
|
||||
/) {
|
||||
$schema->resultset($set)->search(
|
||||
{ mac => { '-in' => $nodes->as_query }},
|
||||
)->update({ active => \'false' });
|
||||
}
|
||||
|
||||
$schema->resultset('NodeWireless')
|
||||
->search({ mac => { '-in' => $nodes->as_query }})->delete;
|
||||
|
||||
# avoid letting DBIC delete nodes
|
||||
return 0E0;
|
||||
}
|
||||
elsif (exists $opts->{only_nodes} and $opts->{only_nodes}) {
|
||||
# now let DBIC do its thing
|
||||
return $self->next::method();
|
||||
}
|
||||
elsif (exists $opts->{keep_nodes} and $opts->{keep_nodes}) {
|
||||
# avoid letting DBIC delete nodes
|
||||
return 0E0;
|
||||
}
|
||||
else {
|
||||
# for node_ip and node_nbt *only* delete if there are no longer
|
||||
# any active nodes referencing the IP or NBT (hence 2nd IN clause).
|
||||
foreach my $set (qw/
|
||||
NodeIp
|
||||
NodeNbt
|
||||
/) {
|
||||
$schema->resultset($set)->search({
|
||||
'me.mac' => { '-in' => $schema->resultset($set)->search({
|
||||
'-and' => [
|
||||
-bool => 'nodes.active',
|
||||
'me.mac' => { '-in' => $nodes->as_query }
|
||||
]
|
||||
},
|
||||
{
|
||||
columns => 'mac',
|
||||
join => 'nodes',
|
||||
group_by => 'me.mac',
|
||||
having => \[ 'count(nodes.mac) = 0' ],
|
||||
})->as_query,
|
||||
},
|
||||
})->delete;
|
||||
}
|
||||
|
||||
foreach my $set (qw/
|
||||
NodeMonitor
|
||||
NodeWireless
|
||||
/) {
|
||||
$schema->resultset($set)->search(
|
||||
{ mac => { '-in' => $nodes->as_query }},
|
||||
)->delete;
|
||||
}
|
||||
|
||||
# now let DBIC do its thing
|
||||
return $self->next::method();
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
219
lib/App/Netdisco/DB/ResultSet/NodeIp.pm
Normal file
219
lib/App/Netdisco/DB/ResultSet/NodeIp.pm
Normal file
@@ -0,0 +1,219 @@
|
||||
package App::Netdisco::DB::ResultSet::NodeIp;
|
||||
use base 'App::Netdisco::DB::ResultSet';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
__PACKAGE__->load_components(qw/
|
||||
+App::Netdisco::DB::ExplicitLocking
|
||||
/);
|
||||
|
||||
my $search_attr = {
|
||||
order_by => {'-desc' => 'time_last'},
|
||||
'+columns' => [
|
||||
'oui.company',
|
||||
'oui.abbrev',
|
||||
{ time_first_stamp => \"to_char(time_first, 'YYYY-MM-DD HH24:MI')" },
|
||||
{ time_last_stamp => \"to_char(time_last, 'YYYY-MM-DD HH24:MI')" },
|
||||
],
|
||||
join => 'oui'
|
||||
};
|
||||
|
||||
=head1 with_times
|
||||
|
||||
This is a modifier for any C<search()> (including the helpers below) which
|
||||
will add the following additional synthesized columns to the result set:
|
||||
|
||||
=over 4
|
||||
|
||||
=item time_first_stamp
|
||||
|
||||
=item time_last_stamp
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub with_times {
|
||||
my ($rs, $cond, $attrs) = @_;
|
||||
|
||||
return $rs
|
||||
->search_rs({}, $search_attr)
|
||||
->search($cond, $attrs);
|
||||
}
|
||||
|
||||
=head1 search_by_ip( \%cond, \%attrs? )
|
||||
|
||||
my $set = $rs->search_by_ip({ip => '192.0.2.1', active => 1});
|
||||
|
||||
Like C<search()>, this returns a ResultSet of matching rows from the
|
||||
NodeIp table.
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
The C<cond> parameter must be a hashref containing a key C<ip> with the value
|
||||
to search for. Value can either be a simple string of IPv4 or IPv6, or a
|
||||
L<NetAddr::IP::Lite> object in which case all results within the CIDR/Prefix
|
||||
will be retrieved.
|
||||
|
||||
=item *
|
||||
|
||||
Results are ordered by time last seen.
|
||||
|
||||
=item *
|
||||
|
||||
Additional columns C<time_first_stamp> and C<time_last_stamp> provide
|
||||
preformatted timestamps of the C<time_first> and C<time_last> fields.
|
||||
|
||||
=item *
|
||||
|
||||
A JOIN is performed on the OUI table and the OUI C<company> column prefetched.
|
||||
|
||||
=back
|
||||
|
||||
To limit results only to active IPs, set C<< {active => 1} >> in C<cond>.
|
||||
|
||||
=cut
|
||||
|
||||
sub search_by_ip {
|
||||
my ($rs, $cond, $attrs) = @_;
|
||||
|
||||
die "ip address required for search_by_ip\n"
|
||||
if ref {} ne ref $cond or !exists $cond->{ip};
|
||||
|
||||
# handle either plain text IP or NetAddr::IP (/32 or CIDR)
|
||||
my ($op, $ip) = ('=', delete $cond->{ip});
|
||||
|
||||
if ('NetAddr::IP::Lite' eq ref $ip and $ip->num > 1) {
|
||||
$op = '<<=';
|
||||
$ip = $ip->cidr;
|
||||
}
|
||||
$cond->{ip} = { $op => $ip };
|
||||
|
||||
return $rs
|
||||
->search_rs({}, $search_attr)
|
||||
->search($cond, $attrs);
|
||||
}
|
||||
|
||||
=head1 search_by_name( \%cond, \%attrs? )
|
||||
|
||||
my $set = $rs->search_by_name({dns => 'foo.example.com', active => 1});
|
||||
|
||||
Like C<search()>, this returns a ResultSet of matching rows from the
|
||||
NodeIp table.
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
The NodeIp table must have a C<dns> column for this search to work. Typically
|
||||
this column is the IP's DNS PTR record, cached at the time of Netdisco Arpnip.
|
||||
|
||||
=item *
|
||||
|
||||
The C<cond> parameter must be a hashref containing a key C<dns> with the value
|
||||
to search for. The value may optionally include SQL wildcard characters.
|
||||
|
||||
=item *
|
||||
|
||||
Results are ordered by time last seen.
|
||||
|
||||
=item *
|
||||
|
||||
Additional columns C<time_first_stamp> and C<time_last_stamp> provide
|
||||
preformatted timestamps of the C<time_first> and C<time_last> fields.
|
||||
|
||||
=item *
|
||||
|
||||
A JOIN is performed on the OUI table and the OUI C<company> column prefetched.
|
||||
|
||||
=back
|
||||
|
||||
To limit results only to active IPs, set C<< {active => 1} >> in C<cond>.
|
||||
|
||||
=cut
|
||||
|
||||
sub search_by_dns {
|
||||
my ($rs, $cond, $attrs) = @_;
|
||||
|
||||
die "dns field required for search_by_dns\n"
|
||||
if ref {} ne ref $cond or !exists $cond->{dns};
|
||||
|
||||
$cond->{dns} = { '-ilike' => delete $cond->{dns} };
|
||||
|
||||
return $rs
|
||||
->search_rs({}, $search_attr)
|
||||
->search($cond, $attrs);
|
||||
}
|
||||
|
||||
=head1 search_by_mac( \%cond, \%attrs? )
|
||||
|
||||
my $set = $rs->search_by_mac({mac => '00:11:22:33:44:55', active => 1});
|
||||
|
||||
Like C<search()>, this returns a ResultSet of matching rows from the
|
||||
NodeIp table.
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
The C<cond> parameter must be a hashref containing a key C<mac> with the value
|
||||
to search for.
|
||||
|
||||
=item *
|
||||
|
||||
Results are ordered by time last seen.
|
||||
|
||||
=item *
|
||||
|
||||
Additional columns C<time_first_stamp> and C<time_last_stamp> provide
|
||||
preformatted timestamps of the C<time_first> and C<time_last> fields.
|
||||
|
||||
=item *
|
||||
|
||||
A JOIN is performed on the OUI table and the OUI C<company> column prefetched.
|
||||
|
||||
=back
|
||||
|
||||
To limit results only to active IPs, set C<< {active => 1} >> in C<cond>.
|
||||
|
||||
=cut
|
||||
|
||||
sub search_by_mac {
|
||||
my ($rs, $cond, $attrs) = @_;
|
||||
|
||||
die "mac address required for search_by_mac\n"
|
||||
if ref {} ne ref $cond or !exists $cond->{mac};
|
||||
|
||||
return $rs
|
||||
->search_rs({}, $search_attr)
|
||||
->search($cond, $attrs);
|
||||
}
|
||||
|
||||
=head2 ip_version( $version )
|
||||
|
||||
my $rset = $rs->ip_version(4);
|
||||
|
||||
This predefined C<search()> returns a ResultSet of matching rows from the
|
||||
NodeIp table of nodes with addresses of the supplied IP version.
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
The C<version> parameter must be an integer either 4 or 6.
|
||||
|
||||
=cut
|
||||
|
||||
sub ip_version {
|
||||
my ( $rs, $version ) = @_;
|
||||
|
||||
die "ip_version input must be either 4 or 6\n"
|
||||
unless $version && ( $version == 4 || $version == 6 );
|
||||
|
||||
return $rs->search_rs( \[ 'family(me.ip) = ?', $version ] );
|
||||
}
|
||||
|
||||
1;
|
||||
189
lib/App/Netdisco/DB/ResultSet/NodeNbt.pm
Normal file
189
lib/App/Netdisco/DB/ResultSet/NodeNbt.pm
Normal file
@@ -0,0 +1,189 @@
|
||||
package App::Netdisco::DB::ResultSet::NodeNbt;
|
||||
use base 'App::Netdisco::DB::ResultSet';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
__PACKAGE__->load_components(qw/
|
||||
+App::Netdisco::DB::ExplicitLocking
|
||||
/);
|
||||
|
||||
my $search_attr = {
|
||||
order_by => {'-desc' => 'time_last'},
|
||||
'+columns' => [
|
||||
'oui.company',
|
||||
{ time_first_stamp => \"to_char(time_first, 'YYYY-MM-DD HH24:MI')" },
|
||||
{ time_last_stamp => \"to_char(time_last, 'YYYY-MM-DD HH24:MI')" },
|
||||
],
|
||||
join => 'oui'
|
||||
};
|
||||
|
||||
=head1 with_times
|
||||
|
||||
This is a modifier for any C<search()> (including the helpers below) which
|
||||
will add the following additional synthesized columns to the result set:
|
||||
|
||||
=over 4
|
||||
|
||||
=item time_first_stamp
|
||||
|
||||
=item time_last_stamp
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub with_times {
|
||||
my ($rs, $cond, $attrs) = @_;
|
||||
|
||||
return $rs
|
||||
->search_rs({}, $search_attr)
|
||||
->search($cond, $attrs);
|
||||
}
|
||||
|
||||
=head1 search_by_ip( \%cond, \%attrs? )
|
||||
|
||||
my $set = $rs->search_by_ip({ip => '192.0.2.1', active => 1});
|
||||
|
||||
Like C<search()>, this returns a ResultSet of matching rows from the
|
||||
NodeNbt table.
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
The C<cond> parameter must be a hashref containing a key C<ip> with the value
|
||||
to search for. Value can either be a simple string of IPv4 or IPv6, or a
|
||||
L<NetAddr::IP::Lite> object in which case all results within the CIDR/Prefix
|
||||
will be retrieved.
|
||||
|
||||
=item *
|
||||
|
||||
Results are ordered by time last seen.
|
||||
|
||||
=item *
|
||||
|
||||
Additional columns C<time_first_stamp> and C<time_last_stamp> provide
|
||||
preformatted timestamps of the C<time_first> and C<time_last> fields.
|
||||
|
||||
=item *
|
||||
|
||||
A JOIN is performed on the OUI table and the OUI C<company> column prefetched.
|
||||
|
||||
=back
|
||||
|
||||
To limit results only to active IPs, set C<< {active => 1} >> in C<cond>.
|
||||
|
||||
=cut
|
||||
|
||||
sub search_by_ip {
|
||||
my ($rs, $cond, $attrs) = @_;
|
||||
|
||||
die "ip address required for search_by_ip\n"
|
||||
if ref {} ne ref $cond or !exists $cond->{ip};
|
||||
|
||||
# handle either plain text IP or NetAddr::IP (/32 or CIDR)
|
||||
my ($op, $ip) = ('=', delete $cond->{ip});
|
||||
|
||||
if ('NetAddr::IP::Lite' eq ref $ip and $ip->num > 1) {
|
||||
$op = '<<=';
|
||||
$ip = $ip->cidr;
|
||||
}
|
||||
$cond->{ip} = { $op => $ip };
|
||||
|
||||
return $rs
|
||||
->search_rs({}, $search_attr)
|
||||
->search($cond, $attrs);
|
||||
}
|
||||
|
||||
=head1 search_by_name( \%cond, \%attrs? )
|
||||
|
||||
my $set = $rs->search_by_name({nbname => 'MYNAME', active => 1});
|
||||
|
||||
Like C<search()>, this returns a ResultSet of matching rows from the
|
||||
NodeNbt table.
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
The C<cond> parameter must be a hashref containing a key C<nbname> with the
|
||||
value to search for. The value may optionally include SQL wildcard characters.
|
||||
|
||||
=item *
|
||||
|
||||
Results are ordered by time last seen.
|
||||
|
||||
=item *
|
||||
|
||||
Additional columns C<time_first_stamp> and C<time_last_stamp> provide
|
||||
preformatted timestamps of the C<time_first> and C<time_last> fields.
|
||||
|
||||
=item *
|
||||
|
||||
A JOIN is performed on the OUI table and the OUI C<company> column prefetched.
|
||||
|
||||
=back
|
||||
|
||||
To limit results only to active IPs, set C<< {active => 1} >> in C<cond>.
|
||||
|
||||
=cut
|
||||
|
||||
sub search_by_name {
|
||||
my ($rs, $cond, $attrs) = @_;
|
||||
|
||||
die "nbname field required for search_by_name\n"
|
||||
if ref {} ne ref $cond or !exists $cond->{nbname};
|
||||
|
||||
$cond->{nbname} = { '-ilike' => delete $cond->{nbname} };
|
||||
|
||||
return $rs
|
||||
->search_rs({}, $search_attr)
|
||||
->search($cond, $attrs);
|
||||
}
|
||||
|
||||
=head1 search_by_mac( \%cond, \%attrs? )
|
||||
|
||||
my $set = $rs->search_by_mac({mac => '00:11:22:33:44:55', active => 1});
|
||||
|
||||
Like C<search()>, this returns a ResultSet of matching rows from the
|
||||
NodeNbt table.
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
The C<cond> parameter must be a hashref containing a key C<mac> with the value
|
||||
to search for.
|
||||
|
||||
=item *
|
||||
|
||||
Results are ordered by time last seen.
|
||||
|
||||
=item *
|
||||
|
||||
Additional columns C<time_first_stamp> and C<time_last_stamp> provide
|
||||
preformatted timestamps of the C<time_first> and C<time_last> fields.
|
||||
|
||||
=item *
|
||||
|
||||
A JOIN is performed on the OUI table and the OUI C<company> column prefetched.
|
||||
|
||||
=back
|
||||
|
||||
To limit results only to active IPs, set C<< {active => 1} >> in C<cond>.
|
||||
|
||||
=cut
|
||||
|
||||
sub search_by_mac {
|
||||
my ($rs, $cond, $attrs) = @_;
|
||||
|
||||
die "mac address required for search_by_mac\n"
|
||||
if ref {} ne ref $cond or !exists $cond->{mac};
|
||||
|
||||
return $rs
|
||||
->search_rs({}, $search_attr)
|
||||
->search($cond, $attrs);
|
||||
}
|
||||
|
||||
1;
|
||||
11
lib/App/Netdisco/DB/ResultSet/NodeWireless.pm
Normal file
11
lib/App/Netdisco/DB/ResultSet/NodeWireless.pm
Normal file
@@ -0,0 +1,11 @@
|
||||
package App::Netdisco::DB::ResultSet::NodeWireless;
|
||||
use base 'App::Netdisco::DB::ResultSet';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
__PACKAGE__->load_components(qw/
|
||||
+App::Netdisco::DB::ExplicitLocking
|
||||
/);
|
||||
|
||||
1;
|
||||
11
lib/App/Netdisco/DB/ResultSet/Subnet.pm
Normal file
11
lib/App/Netdisco/DB/ResultSet/Subnet.pm
Normal file
@@ -0,0 +1,11 @@
|
||||
package App::Netdisco::DB::ResultSet::Subnet;
|
||||
use base 'App::Netdisco::DB::ResultSet';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
__PACKAGE__->load_components(qw/
|
||||
+App::Netdisco::DB::ExplicitLocking
|
||||
/);
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,372 @@
|
||||
BEGIN;
|
||||
|
||||
-- admin table - Queue for admin tasks sent from front-end for back-end processing.
|
||||
|
||||
CREATE TABLE admin (
|
||||
job serial,
|
||||
entered TIMESTAMP DEFAULT now(),
|
||||
started TIMESTAMP,
|
||||
finished TIMESTAMP,
|
||||
device inet,
|
||||
port text,
|
||||
action text,
|
||||
subaction text,
|
||||
status text,
|
||||
username text,
|
||||
userip inet,
|
||||
log text,
|
||||
debug boolean
|
||||
);
|
||||
|
||||
CREATE INDEX idx_admin_entered ON admin(entered);
|
||||
CREATE INDEX idx_admin_status ON admin(status);
|
||||
CREATE INDEX idx_admin_action ON admin(action);
|
||||
|
||||
CREATE TABLE device (
|
||||
ip inet PRIMARY KEY,
|
||||
creation TIMESTAMP DEFAULT now(),
|
||||
dns text,
|
||||
description text,
|
||||
uptime bigint,
|
||||
contact text,
|
||||
name text,
|
||||
location text,
|
||||
layers varchar(8),
|
||||
ports integer,
|
||||
mac macaddr,
|
||||
serial text,
|
||||
model text,
|
||||
ps1_type text,
|
||||
ps2_type text,
|
||||
ps1_status text,
|
||||
ps2_status text,
|
||||
fan text,
|
||||
slots integer,
|
||||
vendor text,
|
||||
os text,
|
||||
os_ver text,
|
||||
log text,
|
||||
snmp_ver integer,
|
||||
snmp_comm text,
|
||||
snmp_class text,
|
||||
vtp_domain text,
|
||||
last_discover TIMESTAMP,
|
||||
last_macsuck TIMESTAMP,
|
||||
last_arpnip TIMESTAMP
|
||||
);
|
||||
|
||||
-- Indexing for speed-ups
|
||||
CREATE INDEX idx_device_dns ON device(dns);
|
||||
CREATE INDEX idx_device_layers ON device(layers);
|
||||
CREATE INDEX idx_device_vendor ON device(vendor);
|
||||
CREATE INDEX idx_device_model ON device(model);
|
||||
|
||||
CREATE TABLE device_ip (
|
||||
ip inet,
|
||||
alias inet,
|
||||
subnet cidr,
|
||||
port text,
|
||||
dns text,
|
||||
creation TIMESTAMP DEFAULT now(),
|
||||
PRIMARY KEY(ip,alias)
|
||||
);
|
||||
|
||||
-- Indexing for speed ups
|
||||
CREATE INDEX idx_device_ip_ip ON device_ip(ip);
|
||||
CREATE INDEX idx_device_ip_alias ON device_ip(alias);
|
||||
CREATE INDEX idx_device_ip_ip_port ON device_ip(ip,port);
|
||||
|
||||
CREATE TABLE device_module (
|
||||
ip inet not null,
|
||||
index integer,
|
||||
description text,
|
||||
type text,
|
||||
parent integer,
|
||||
name text,
|
||||
class text,
|
||||
pos integer,
|
||||
hw_ver text,
|
||||
fw_ver text,
|
||||
sw_ver text,
|
||||
serial text,
|
||||
model text,
|
||||
fru boolean,
|
||||
creation TIMESTAMP DEFAULT now(),
|
||||
last_discover TIMESTAMP,
|
||||
PRIMARY KEY(ip,index)
|
||||
);
|
||||
|
||||
CREATE TABLE device_port (
|
||||
ip inet,
|
||||
port text,
|
||||
creation TIMESTAMP DEFAULT now(),
|
||||
descr text,
|
||||
up text,
|
||||
up_admin text,
|
||||
type text,
|
||||
duplex text,
|
||||
duplex_admin text,
|
||||
speed text,
|
||||
name text,
|
||||
mac macaddr,
|
||||
mtu integer,
|
||||
stp text,
|
||||
remote_ip inet,
|
||||
remote_port text,
|
||||
remote_type text,
|
||||
remote_id text,
|
||||
vlan text,
|
||||
pvid integer,
|
||||
lastchange bigint,
|
||||
PRIMARY KEY(port,ip)
|
||||
);
|
||||
|
||||
CREATE INDEX idx_device_port_ip ON device_port(ip);
|
||||
CREATE INDEX idx_device_port_remote_ip ON device_port(remote_ip);
|
||||
-- For the duplex mismatch finder :
|
||||
CREATE INDEX idx_device_port_ip_port_duplex ON device_port(ip,port,duplex);
|
||||
CREATE INDEX idx_device_port_ip_up_admin ON device_port(ip,up_admin);
|
||||
CREATE INDEX idx_device_port_mac ON device_port(mac);
|
||||
|
||||
CREATE TABLE device_port_log (
|
||||
id serial,
|
||||
ip inet,
|
||||
port text,
|
||||
reason text,
|
||||
log text,
|
||||
username text,
|
||||
userip inet,
|
||||
action text,
|
||||
creation TIMESTAMP DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE INDEX idx_device_port_log_1 ON device_port_log(ip,port);
|
||||
CREATE INDEX idx_device_port_log_user ON device_port_log(username);
|
||||
|
||||
CREATE TABLE device_port_power (
|
||||
ip inet,
|
||||
port text,
|
||||
module integer,
|
||||
admin text,
|
||||
status text,
|
||||
class text,
|
||||
power integer,
|
||||
PRIMARY KEY(port,ip)
|
||||
);
|
||||
|
||||
CREATE TABLE device_port_ssid (
|
||||
ip inet,
|
||||
port text,
|
||||
ssid text,
|
||||
broadcast boolean,
|
||||
bssid macaddr
|
||||
);
|
||||
|
||||
CREATE INDEX idx_device_port_ssid_ip_port ON device_port_ssid(ip,port);
|
||||
|
||||
CREATE TABLE device_port_vlan (
|
||||
ip inet,
|
||||
port text,
|
||||
vlan integer,
|
||||
native boolean not null default false,
|
||||
creation TIMESTAMP DEFAULT now(),
|
||||
last_discover TIMESTAMP DEFAULT now(),
|
||||
vlantype text,
|
||||
PRIMARY KEY(ip,port,vlan)
|
||||
);
|
||||
|
||||
CREATE TABLE device_port_wireless (
|
||||
ip inet,
|
||||
port text,
|
||||
channel integer,
|
||||
power integer
|
||||
);
|
||||
|
||||
CREATE INDEX idx_device_port_wireless_ip_port ON device_port_wireless(ip,port);
|
||||
|
||||
CREATE TABLE device_power (
|
||||
ip inet,
|
||||
module integer,
|
||||
power integer,
|
||||
status text,
|
||||
PRIMARY KEY(ip,module)
|
||||
);
|
||||
|
||||
CREATE TABLE device_vlan (
|
||||
ip inet,
|
||||
vlan integer,
|
||||
description text,
|
||||
creation TIMESTAMP DEFAULT now(),
|
||||
last_discover TIMESTAMP DEFAULT now(),
|
||||
PRIMARY KEY(ip,vlan)
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE log (
|
||||
id serial,
|
||||
creation TIMESTAMP DEFAULT now(),
|
||||
class text,
|
||||
entry text,
|
||||
logfile text
|
||||
);
|
||||
|
||||
CREATE TABLE node (
|
||||
mac macaddr,
|
||||
switch inet,
|
||||
port text,
|
||||
vlan text default '0',
|
||||
active boolean,
|
||||
oui varchar(8),
|
||||
time_first timestamp default now(),
|
||||
time_recent timestamp default now(),
|
||||
time_last timestamp default now(),
|
||||
PRIMARY KEY(mac,switch,port,vlan)
|
||||
);
|
||||
|
||||
-- Indexes speed things up a LOT
|
||||
CREATE INDEX idx_node_switch_port_active ON node(switch,port,active);
|
||||
CREATE INDEX idx_node_switch_port ON node(switch,port);
|
||||
CREATE INDEX idx_node_switch ON node(switch);
|
||||
CREATE INDEX idx_node_mac ON node(mac);
|
||||
CREATE INDEX idx_node_mac_active ON node(mac,active);
|
||||
-- CREATE INDEX idx_node_oui ON node(oui);
|
||||
|
||||
CREATE TABLE node_ip (
|
||||
mac macaddr,
|
||||
ip inet,
|
||||
active boolean,
|
||||
time_first timestamp default now(),
|
||||
time_last timestamp default now(),
|
||||
PRIMARY KEY(mac,ip)
|
||||
);
|
||||
|
||||
-- Indexing speed ups.
|
||||
CREATE INDEX idx_node_ip_ip ON node_ip(ip);
|
||||
CREATE INDEX idx_node_ip_ip_active ON node_ip(ip,active);
|
||||
CREATE INDEX idx_node_ip_mac ON node_ip(mac);
|
||||
CREATE INDEX idx_node_ip_mac_active ON node_ip(mac,active);
|
||||
|
||||
CREATE TABLE node_monitor (
|
||||
mac macaddr,
|
||||
active boolean,
|
||||
why text,
|
||||
cc text,
|
||||
date TIMESTAMP DEFAULT now(),
|
||||
PRIMARY KEY(mac)
|
||||
);
|
||||
|
||||
-- node_nbt - Hold Netbios information for each node.
|
||||
|
||||
CREATE TABLE node_nbt (
|
||||
mac macaddr PRIMARY KEY,
|
||||
ip inet,
|
||||
nbname text,
|
||||
domain text,
|
||||
server boolean,
|
||||
nbuser text,
|
||||
active boolean,
|
||||
time_first timestamp default now(),
|
||||
time_last timestamp default now()
|
||||
);
|
||||
|
||||
-- Indexing speed ups.
|
||||
CREATE INDEX idx_node_nbt_mac ON node_nbt(mac);
|
||||
CREATE INDEX idx_node_nbt_nbname ON node_nbt(nbname);
|
||||
CREATE INDEX idx_node_nbt_domain ON node_nbt(domain);
|
||||
CREATE INDEX idx_node_nbt_mac_active ON node_nbt(mac,active);
|
||||
|
||||
-- Add "vlan" column to node table
|
||||
-- ALTER TABLE node ADD COLUMN vlan text default '0';
|
||||
|
||||
alter table node drop constraint node_pkey;
|
||||
alter table node add primary key (mac, switch, port, vlan);
|
||||
|
||||
CREATE TABLE node_wireless (
|
||||
mac macaddr,
|
||||
ssid text default '',
|
||||
uptime integer,
|
||||
maxrate integer,
|
||||
txrate integer,
|
||||
sigstrength integer,
|
||||
sigqual integer,
|
||||
rxpkt integer,
|
||||
txpkt integer,
|
||||
rxbyte bigint,
|
||||
txbyte bigint,
|
||||
time_last timestamp default now(),
|
||||
PRIMARY KEY(mac,ssid)
|
||||
);
|
||||
|
||||
|
||||
-- Add "ssid" column to node_wireless table
|
||||
-- ALTER TABLE node_wireless ADD ssid text default '';
|
||||
|
||||
alter table node_wireless drop constraint node_wireless_pkey;
|
||||
alter table node_wireless add primary key (mac, ssid);
|
||||
|
||||
|
||||
|
||||
CREATE TABLE oui (
|
||||
oui varchar(8) PRIMARY KEY,
|
||||
company text
|
||||
);
|
||||
|
||||
|
||||
-- process table - Queue to coordinate between processes in multi-process mode.
|
||||
|
||||
CREATE TABLE process (
|
||||
controller integer not null,
|
||||
device inet not null,
|
||||
action text not null,
|
||||
status text,
|
||||
count integer,
|
||||
creation TIMESTAMP DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE TABLE sessions (
|
||||
id char(32) NOT NULL PRIMARY KEY,
|
||||
creation TIMESTAMP DEFAULT now(),
|
||||
a_session text
|
||||
);
|
||||
|
||||
CREATE TABLE subnets (
|
||||
net cidr NOT NULL,
|
||||
creation timestamp default now(),
|
||||
last_discover timestamp default now(),
|
||||
PRIMARY KEY(net)
|
||||
);
|
||||
|
||||
-- Add "topology" table to augment manual topo file
|
||||
CREATE TABLE topology (
|
||||
dev1 inet not null,
|
||||
port1 text not null,
|
||||
dev2 inet not null,
|
||||
port2 text not null
|
||||
);
|
||||
|
||||
|
||||
|
||||
-- This table logs login and logout / change requests for users
|
||||
|
||||
CREATE TABLE user_log (
|
||||
entry serial,
|
||||
username varchar(50),
|
||||
userip inet,
|
||||
event text,
|
||||
details text,
|
||||
creation TIMESTAMP DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE TABLE users (
|
||||
username varchar(50) PRIMARY KEY,
|
||||
password text,
|
||||
creation TIMESTAMP DEFAULT now(),
|
||||
last_on TIMESTAMP,
|
||||
port_control boolean DEFAULT false,
|
||||
ldap boolean DEFAULT false,
|
||||
admin boolean DEFAULT false,
|
||||
fullname text,
|
||||
note text
|
||||
);
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,5 @@
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE device_port_vlan ADD COLUMN vlantype text;
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,5 @@
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE node_ip ADD COLUMN dns text;
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,5 @@
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE node DROP CONSTRAINT node_pkey;
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,5 @@
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE node_wireless DROP CONSTRAINT node_wireless_pkey;
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,5 @@
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE node ADD COLUMN vlan text DEFAULT '0' NOT NULL;
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,5 @@
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE node_wireless ADD COLUMN ssid text DEFAULT '' NOT NULL;
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,5 @@
|
||||
BEGIN;
|
||||
|
||||
CREATE INDEX device_port_power_idx_ip_port on device_port_power (ip, port);
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,7 @@
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE admin DROP CONSTRAINT IF EXISTS admin_pkey;
|
||||
|
||||
ALTER TABLE admin ADD PRIMARY KEY (job);
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,5 @@
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE node ADD PRIMARY KEY (mac, switch, port, vlan);
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,5 @@
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE node_wireless ADD PRIMARY KEY (mac, ssid);
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,14 @@
|
||||
BEGIN;
|
||||
|
||||
-- Database Schema Modifications for upgrading from 0.9x to 0.93
|
||||
|
||||
ALTER TABLE device_port ADD COLUMN remote_type text;
|
||||
ALTER TABLE device_port ADD COLUMN remote_id text;
|
||||
ALTER TABLE device_port ADD COLUMN vlan text;
|
||||
|
||||
ALTER TABLE device ADD COLUMN vtp_domain text;
|
||||
|
||||
ALTER TABLE users ADD COLUMN fullname text;
|
||||
ALTER TABLE users ADD COLUMN note text;
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,10 @@
|
||||
BEGIN;
|
||||
|
||||
CREATE UNIQUE INDEX jobs_queued ON admin (
|
||||
action,
|
||||
coalesce(subaction, '_x_'),
|
||||
coalesce(device, '255.255.255.255'),
|
||||
coalesce(port, '_x_')
|
||||
) WHERE status LIKE 'queued%';
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,7 @@
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE topology ADD CONSTRAINT topology_dev1_port1 UNIQUE (dev1, port1);
|
||||
|
||||
ALTER TABLE topology ADD CONSTRAINT topology_dev2_port2 UNIQUE (dev2, port2);
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,5 @@
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE device_port ADD COLUMN "manual_topo" bool DEFAULT false NOT NULL;
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,6 @@
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE device_port ADD COLUMN "is_uplink" bool;
|
||||
ALTER TABLE device_port ADD COLUMN "is_uplink_admin" bool;
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,5 @@
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE device_ip DROP CONSTRAINT "device_ip_alias";
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,5 @@
|
||||
BEGIN;
|
||||
|
||||
-- ALTER TABLE device_port ALTER COLUMN remote_id TYPE bytea USING remote_id::bytea;
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,5 @@
|
||||
BEGIN;
|
||||
|
||||
-- ALTER TABLE device_port ALTER COLUMN remote_id TYPE text USING remote_id::text;
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,5 @@
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE device ADD COLUMN snmp_comm_rw text;
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,5 @@
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE device DROP COLUMN snmp_comm_rw;
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,9 @@
|
||||
BEGIN;
|
||||
|
||||
CREATE TABLE "community" (
|
||||
"ip" inet NOT NULL,
|
||||
"snmp_comm_rw" text,
|
||||
PRIMARY KEY ("ip")
|
||||
);
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,38 @@
|
||||
BEGIN;
|
||||
|
||||
-- Netdisco
|
||||
-- Database Schema Modifications
|
||||
-- UPGRADE from 0.93 to 0.94
|
||||
|
||||
ALTER TABLE device_port ADD COLUMN lastchange bigint;
|
||||
|
||||
ALTER TABLE log ADD COLUMN logfile text;
|
||||
|
||||
CREATE TABLE user_log (
|
||||
entry serial,
|
||||
username varchar(50),
|
||||
userip inet,
|
||||
event text,
|
||||
details text,
|
||||
creation TIMESTAMP DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE TABLE node_nbt (
|
||||
mac macaddr PRIMARY KEY,
|
||||
ip inet,
|
||||
nbname text,
|
||||
domain text,
|
||||
server boolean,
|
||||
nbuser text,
|
||||
active boolean,
|
||||
time_first timestamp default now(),
|
||||
time_last timestamp default now()
|
||||
);
|
||||
|
||||
-- Indexing speed ups.
|
||||
CREATE INDEX idx_node_nbt_mac ON node_nbt(mac);
|
||||
CREATE INDEX idx_node_nbt_nbname ON node_nbt(nbname);
|
||||
CREATE INDEX idx_node_nbt_domain ON node_nbt(domain);
|
||||
CREATE INDEX idx_node_nbt_mac_active ON node_nbt(mac,active);
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,8 @@
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE node_wireless ALTER COLUMN rxpkt TYPE bigint;
|
||||
ALTER TABLE node_wireless ALTER COLUMN txpkt TYPE bigint;
|
||||
ALTER TABLE node_wireless ALTER COLUMN rxbyte TYPE bigint;
|
||||
ALTER TABLE node_wireless ALTER COLUMN txbyte TYPE bigint;
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,5 @@
|
||||
BEGIN;
|
||||
|
||||
DROP INDEX IF EXISTS jobs_queued;
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,5 @@
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE community ADD COLUMN snmp_auth_tag text;
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,5 @@
|
||||
BEGIN;
|
||||
|
||||
UPDATE node SET vlan = '0' WHERE vlan IS NULL;
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,5 @@
|
||||
BEGIN;
|
||||
|
||||
CREATE INDEX node_ip_idx_ip_active ON node_ip (ip, active);
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,7 @@
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE device_port_vlan DROP CONSTRAINT device_port_vlan_pkey;
|
||||
|
||||
ALTER TABLE device_port_vlan ADD PRIMARY KEY (ip, port, vlan, native);
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,5 @@
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE oui ADD COLUMN abbrev text;
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,7 @@
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE device_port DROP COLUMN is_uplink_admin;
|
||||
ALTER TABLE device_port ADD COLUMN "slave_of" text;
|
||||
ALTER TABLE device_port ADD COLUMN "is_master" bool DEFAULT false NOT NULL;
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,15 @@
|
||||
-- clean up node table where vlan = 0 and vlan = <another number>
|
||||
--
|
||||
-- DELETE n1.*
|
||||
-- FROM node n1 INNER JOIN
|
||||
-- (SELECT mac, switch, port from node
|
||||
-- GROUP BY mac, switch, port
|
||||
-- HAVING count(*) > 1) n2
|
||||
-- ON n1.mac = n2.mac
|
||||
-- AND n1.switch = n2.switch
|
||||
-- AND n1.port = n2.port
|
||||
-- AND n1.vlan = '0';
|
||||
|
||||
BEGIN;
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,17 @@
|
||||
-- clean up node table where vlan = 0 and vlan = <another number>
|
||||
--
|
||||
-- DELETE n1.*
|
||||
-- FROM node n1 INNER JOIN
|
||||
-- (SELECT mac, switch, port from node
|
||||
-- GROUP BY mac, switch, port
|
||||
-- HAVING count(*) > 1) n2
|
||||
-- ON n1.mac = n2.mac
|
||||
-- AND n1.switch = n2.switch
|
||||
-- AND n1.port = n2.port
|
||||
-- AND n1.vlan = '0';
|
||||
|
||||
BEGIN;
|
||||
|
||||
DELETE FROM node AS n1 USING (SELECT mac, switch, port from node GROUP BY mac, switch, port HAVING count(*) > 1) n2 WHERE n1.mac = n2.mac AND n1.switch = n2.switch AND n1.port = n2.port AND n1.vlan = '0';
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,59 @@
|
||||
BEGIN;
|
||||
|
||||
-- Netdisco
|
||||
-- Database Schema Modifications
|
||||
-- UPGRADE from 0.94 to 0.95
|
||||
|
||||
CREATE TABLE subnets (
|
||||
net cidr NOT NULL,
|
||||
creation timestamp default now(),
|
||||
last_discover timestamp default now(),
|
||||
PRIMARY KEY(net)
|
||||
);
|
||||
|
||||
--
|
||||
-- node_nbt could already exist, if you upgraded to 0.94, but if
|
||||
-- you ran pg_all in 0.94, node_nbt wasn't created. This
|
||||
-- will report some harmless errors if it already exists.
|
||||
|
||||
CREATE TABLE node_nbt (
|
||||
mac macaddr PRIMARY KEY,
|
||||
ip inet,
|
||||
nbname text,
|
||||
domain text,
|
||||
server boolean,
|
||||
nbuser text,
|
||||
active boolean, -- do we need this still?
|
||||
time_first timestamp default now(),
|
||||
time_last timestamp default now()
|
||||
);
|
||||
|
||||
-- Indexing speed ups.
|
||||
CREATE INDEX idx_node_nbt_mac ON node_nbt(mac);
|
||||
CREATE INDEX idx_node_nbt_nbname ON node_nbt(nbname);
|
||||
CREATE INDEX idx_node_nbt_domain ON node_nbt(domain);
|
||||
CREATE INDEX idx_node_nbt_mac_active ON node_nbt(mac,active);
|
||||
|
||||
--
|
||||
-- Add time_recent to node table
|
||||
ALTER TABLE node ADD time_recent timestamp;
|
||||
ALTER TABLE node ALTER time_recent SET DEFAULT now();
|
||||
UPDATE node SET time_recent = time_first WHERE time_recent IS NULL;
|
||||
|
||||
--
|
||||
-- Add table to contain wireless base station SSIDs
|
||||
CREATE TABLE device_port_ssid (
|
||||
ip inet, -- ip of device
|
||||
port text, -- Unique identifier of Physical Port Name
|
||||
ssid text, -- An SSID that is valid on this port.
|
||||
broadcast boolean,-- Is it broadcast?
|
||||
channel integer -- 802.11 channel number
|
||||
);
|
||||
|
||||
CREATE INDEX idx_device_port_ssid_ip_port ON device_port_ssid(ip,port);
|
||||
|
||||
--
|
||||
-- The OUI field in the oui database is now lowercase.
|
||||
UPDATE oui SET oui=lower(oui);
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,7 @@
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE community RENAME COLUMN snmp_auth_tag TO snmp_auth_tag_read;
|
||||
|
||||
ALTER TABLE community ADD COLUMN snmp_auth_tag_write text;
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,159 @@
|
||||
BEGIN;
|
||||
|
||||
-- Netdisco
|
||||
-- Database Schema Modifications
|
||||
-- UPGRADE from 0.95 to 0.96
|
||||
|
||||
--
|
||||
-- Add snmp_class to device table
|
||||
ALTER TABLE device ADD snmp_class text;
|
||||
|
||||
--
|
||||
-- Add subnet to device_ip table
|
||||
ALTER TABLE device_ip ADD subnet cidr;
|
||||
|
||||
--
|
||||
-- Add indexes on admin table
|
||||
CREATE INDEX idx_admin_entered ON admin(entered);
|
||||
CREATE INDEX idx_admin_status ON admin(status);
|
||||
CREATE INDEX idx_admin_action ON admin(action);
|
||||
|
||||
--
|
||||
-- Create device_module table
|
||||
CREATE TABLE device_module (
|
||||
ip inet not null,
|
||||
index integer,
|
||||
description text,
|
||||
type text,
|
||||
parent integer,
|
||||
name text,
|
||||
class text,
|
||||
pos integer,
|
||||
hw_ver text,
|
||||
fw_ver text,
|
||||
sw_ver text,
|
||||
serial text,
|
||||
model text,
|
||||
fru boolean,
|
||||
creation TIMESTAMP DEFAULT now(),
|
||||
last_discover TIMESTAMP
|
||||
);
|
||||
|
||||
--
|
||||
-- Earlier versions of device_module didn't have the index
|
||||
ALTER TABLE device_module ADD PRIMARY KEY(ip,index);
|
||||
|
||||
-- Create process table - Queue to coordinate between processes in multi-process mode.
|
||||
CREATE TABLE process (
|
||||
controller integer not null, -- pid of controlling process
|
||||
device inet not null,
|
||||
action text not null, -- arpnip, macsuck, nbtstat, discover
|
||||
status text, -- queued, running, skipped, done, error, timeout, nocdp, nosnmp
|
||||
count integer,
|
||||
creation TIMESTAMP DEFAULT now()
|
||||
);
|
||||
|
||||
-- Earlier versions of the process table didn't have the creation timestamp
|
||||
ALTER TABLE process ADD creation TIMESTAMP DEFAULT now();
|
||||
|
||||
--
|
||||
-- Add ldap to users table
|
||||
ALTER TABLE users ADD ldap boolean;
|
||||
ALTER TABLE users ALTER ldap SET DEFAULT false;
|
||||
|
||||
--
|
||||
-- Add pvid to device_port table
|
||||
ALTER TABLE device_port ADD pvid integer;
|
||||
|
||||
--
|
||||
-- Create device_port_vlan table
|
||||
CREATE TABLE device_port_vlan (
|
||||
ip inet, -- ip of device
|
||||
port text, -- Unique identifier of Physical Port Name
|
||||
vlan integer, -- VLAN ID
|
||||
native boolean not null default false, -- native or trunked
|
||||
creation TIMESTAMP DEFAULT now(),
|
||||
last_discover TIMESTAMP DEFAULT now(),
|
||||
PRIMARY KEY(ip,port,vlan)
|
||||
);
|
||||
|
||||
--
|
||||
-- Create device_vlan table
|
||||
CREATE TABLE device_vlan (
|
||||
ip inet, -- ip of device
|
||||
vlan integer, -- VLAN ID
|
||||
description text, -- VLAN description
|
||||
creation TIMESTAMP DEFAULT now(),
|
||||
last_discover TIMESTAMP DEFAULT now(),
|
||||
PRIMARY KEY(ip,vlan)
|
||||
);
|
||||
|
||||
--
|
||||
-- Create device_power table
|
||||
CREATE TABLE device_power (
|
||||
ip inet, -- ip of device
|
||||
module integer,-- Module from PowerEthernet index
|
||||
power integer,-- nominal power of the PSE expressed in Watts
|
||||
status text, -- The operational status
|
||||
PRIMARY KEY(ip,module)
|
||||
);
|
||||
|
||||
--
|
||||
-- Create device_port_power table
|
||||
CREATE TABLE device_port_power (
|
||||
ip inet, -- ip of device
|
||||
port text, -- Unique identifier of Physical Port Name
|
||||
module integer,-- Module from PowerEthernet index
|
||||
admin text, -- Admin power status
|
||||
status text, -- Detected power status
|
||||
class text, -- Detected class
|
||||
PRIMARY KEY(port,ip)
|
||||
);
|
||||
|
||||
CREATE TABLE device_port_wireless (
|
||||
ip inet, -- ip of device
|
||||
port text, -- Unique identifier of Physical Port Name
|
||||
channel integer,-- 802.11 channel number
|
||||
power integer -- transmit power in mw
|
||||
);
|
||||
|
||||
CREATE INDEX idx_device_port_wireless_ip_port ON device_port_wireless(ip,port);
|
||||
|
||||
--
|
||||
-- device_port_ssid lost its channel column, it moved to device_port_wireless
|
||||
--
|
||||
-- Migrate any existing data
|
||||
INSERT INTO device_port_wireless ( ip,port,channel ) ( SELECT ip,port,channel FROM device_port_ssid WHERE channel IS NOT NULL );
|
||||
|
||||
ALTER TABLE device_port_ssid DROP channel;
|
||||
|
||||
|
||||
--
|
||||
-- node_wireless, for client association information
|
||||
CREATE TABLE node_wireless (
|
||||
mac macaddr,
|
||||
uptime integer,
|
||||
maxrate integer, -- can be 0.5 but we ignore that for now
|
||||
txrate integer, -- can be 0.5 but we ignore that for now
|
||||
sigstrength integer, -- signal strength (-db)
|
||||
sigqual integer, -- signal quality
|
||||
rxpkt integer, -- received packets
|
||||
txpkt integer, -- transmitted packets
|
||||
rxbyte bigint, -- received bytes
|
||||
txbyte bigint, -- transmitted bytes
|
||||
time_last timestamp default now(),
|
||||
PRIMARY KEY(mac)
|
||||
);
|
||||
|
||||
--
|
||||
-- node_monitor, for lost/stolen device monitoring
|
||||
CREATE TABLE node_monitor (
|
||||
mac macaddr,
|
||||
active boolean,
|
||||
why text,
|
||||
cc text,
|
||||
date TIMESTAMP DEFAULT now(),
|
||||
PRIMARY KEY(mac)
|
||||
);
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,14 @@
|
||||
BEGIN;
|
||||
|
||||
-- Netdisco
|
||||
-- Database Schema Modifications
|
||||
-- UPGRADE from 1.0 to 1.1
|
||||
|
||||
--
|
||||
-- Add index to node_ip table
|
||||
CREATE INDEX idx_node_ip_ip_active ON node_ip(ip,active);
|
||||
|
||||
-- Add "power" column to device_port_power table
|
||||
ALTER TABLE device_port_power ADD power integer;
|
||||
|
||||
COMMIT;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user