relocate repo files so ND2 is the only code

This commit is contained in:
Oliver Gorwits
2017-04-14 23:08:55 +01:00
parent 9a016ea6ba
commit d23b32500f
469 changed files with 0 additions and 6920 deletions

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;