Merge branch 'master' into og-api-tokens-simple
This commit is contained in:
@@ -262,20 +262,27 @@ sub renumber {
|
||||
foreach my $set (qw/
|
||||
DeviceIp
|
||||
DeviceModule
|
||||
DevicePower
|
||||
DeviceVlan
|
||||
DevicePort
|
||||
DevicePortLog
|
||||
DevicePortPower
|
||||
DevicePortProperties
|
||||
DevicePortSsid
|
||||
DevicePortVlan
|
||||
DevicePortWireless
|
||||
DevicePower
|
||||
DeviceVlan
|
||||
/) {
|
||||
$schema->resultset($set)
|
||||
->search({ip => $old_ip})
|
||||
->update({ip => $new_ip});
|
||||
}
|
||||
|
||||
$schema->resultset('DeviceSkip')
|
||||
->search({device => $new_ip})->delete;
|
||||
$schema->resultset('DeviceSkip')
|
||||
->search({device => $old_ip})
|
||||
->update({device => $new_ip});
|
||||
|
||||
$schema->resultset('DevicePort')
|
||||
->search({remote_ip => $old_ip})
|
||||
->update({remote_ip => $new_ip});
|
||||
|
||||
@@ -29,6 +29,8 @@ __PACKAGE__->add_columns(
|
||||
{ data_type => "bigint", is_nullable => 1 },
|
||||
"faststart",
|
||||
{ data_type => "boolean", is_nullable => 1 },
|
||||
"ifindex",
|
||||
{ data_type => "bigint", is_nullable => 1 },
|
||||
);
|
||||
__PACKAGE__->set_primary_key("port", "ip");
|
||||
|
||||
|
||||
@@ -15,32 +15,61 @@ __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, ld.dns AS left_dns, ld.name AS left_name,
|
||||
array_agg(dp.port) AS left_port, array_agg(dp.name) AS left_descr,
|
||||
sum( COALESCE(dpp.raw_speed,0) ) as aggspeed,
|
||||
count(*) AS aggports,
|
||||
di.ip AS right_ip, rd.dns AS right_dns, rd.name AS right_name,
|
||||
array_agg(dp.remote_port) AS right_port, array_agg(dp2.name) AS right_descr
|
||||
WITH BothWays AS
|
||||
( SELECT dp.ip AS left_ip,
|
||||
ld.dns AS left_dns,
|
||||
ld.name AS left_name,
|
||||
array_agg(dp.port) AS left_port,
|
||||
array_agg(dp.name) AS left_descr,
|
||||
|
||||
FROM device_port dp
|
||||
LEFT OUTER JOIN device_port_properties dpp USING (ip, port)
|
||||
INNER JOIN device ld ON dp.ip = ld.ip
|
||||
INNER JOIN device_ip di ON dp.remote_ip = di.alias
|
||||
INNER JOIN device rd ON di.ip = rd.ip
|
||||
LEFT OUTER JOIN device_port dp2
|
||||
ON (di.ip = dp2.ip
|
||||
AND ((dp.remote_port = dp2.port)
|
||||
OR (dp.remote_port = dp2.name)
|
||||
OR (dp.remote_port = dp2.descr)))
|
||||
count(dpp.*) AS aggports,
|
||||
sum(COALESCE(dpp.raw_speed, 0)) AS aggspeed,
|
||||
|
||||
WHERE dp.remote_port IS NOT NULL
|
||||
AND dp.port !~* 'vlan'
|
||||
AND (dp.descr IS NULL OR dp.descr !~* 'vlan')
|
||||
AND (dp.type IS NULL OR dp.type !~* '^(53|ieee8023adLag|propVirtual|l2vlan|l3ipvlan|135|136|137)\$')
|
||||
AND (dp.is_master = 'false' OR dp.slave_of IS NOT NULL)
|
||||
AND dp.ip <= di.ip
|
||||
GROUP BY left_ip, left_dns, left_name, right_ip, right_dns, right_name
|
||||
ORDER BY dp.ip
|
||||
di.ip AS right_ip,
|
||||
rd.dns AS right_dns,
|
||||
rd.name AS right_name,
|
||||
array_agg(dp.remote_port) AS right_port,
|
||||
array_agg(dp2.name) AS right_descr
|
||||
|
||||
FROM device_port dp
|
||||
|
||||
LEFT OUTER JOIN device_port_properties dpp ON (
|
||||
(dp.ip = dpp.ip) AND (dp.port = dpp.port)
|
||||
AND (dp.type IS NULL
|
||||
OR dp.type !~* '^(53|ieee8023adLag|propVirtual|l2vlan|l3ipvlan|135|136|137)\$')
|
||||
AND (dp.is_master = 'false'
|
||||
OR dp.slave_of IS NOT NULL) )
|
||||
|
||||
INNER JOIN device ld ON dp.ip = ld.ip
|
||||
INNER JOIN device_ip di ON dp.remote_ip = di.alias
|
||||
INNER JOIN device rd ON di.ip = rd.ip
|
||||
|
||||
LEFT OUTER JOIN device_port dp2 ON (di.ip = dp2.ip
|
||||
AND ((dp.remote_port = dp2.port)
|
||||
OR (dp.remote_port = dp2.name)
|
||||
OR (dp.remote_port = dp2.descr)))
|
||||
|
||||
WHERE dp.remote_port IS NOT NULL
|
||||
AND dp.port !~* 'vlan'
|
||||
AND (dp.descr IS NULL OR dp.descr !~* 'vlan')
|
||||
|
||||
GROUP BY left_ip,
|
||||
left_dns,
|
||||
left_name,
|
||||
right_ip,
|
||||
right_dns,
|
||||
right_name )
|
||||
|
||||
SELECT *
|
||||
FROM BothWays b
|
||||
WHERE NOT EXISTS
|
||||
( SELECT *
|
||||
FROM BothWays b2
|
||||
WHERE b2.right_ip = b.left_ip
|
||||
AND b2.right_port = b.left_port
|
||||
AND b2.left_ip < b.left_ip )
|
||||
ORDER BY 1,
|
||||
2
|
||||
ENDSQL
|
||||
);
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ __PACKAGE__->result_source_instance->view_definition(<<'ENDSQL');
|
||||
d.ip, d.name, d.dns,
|
||||
p.port, p.name AS port_description,
|
||||
p.remote_ip, p.remote_id, p.remote_type, p.remote_port,
|
||||
dpp.remote_is_wap, dpp.remote_is_phone,
|
||||
l.log AS comment,
|
||||
a.log, a.finished
|
||||
|
||||
@@ -23,6 +24,7 @@ __PACKAGE__->result_source_instance->view_definition(<<'ENDSQL');
|
||||
INNER JOIN device d USING (ip)
|
||||
LEFT OUTER JOIN device_skip ds
|
||||
ON ('discover' = ANY(ds.actionset) AND p.remote_ip = ds.device)
|
||||
LEFT OUTER JOIN device_port_properties dpp USING (ip, port)
|
||||
LEFT OUTER JOIN device_port_log l USING (ip, port)
|
||||
LEFT OUTER JOIN admin a
|
||||
ON (p.remote_ip = a.device AND a.action = 'discover')
|
||||
@@ -58,6 +60,10 @@ __PACKAGE__->add_columns(
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"remote_id",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"remote_is_wap",
|
||||
{ data_type => "boolean", is_nullable => 1 },
|
||||
"remote_is_phone",
|
||||
{ data_type => "boolean", is_nullable => 1 },
|
||||
"comment",
|
||||
{ data_type => "text", is_nullable => 1 },
|
||||
"log",
|
||||
|
||||
@@ -3,7 +3,10 @@ use base 'App::Netdisco::DB::ResultSet';
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Try::Tiny;
|
||||
use NetAddr::IP::Lite ':lower';
|
||||
require Dancer::Logger;
|
||||
|
||||
=head1 ADDITIONAL METHODS
|
||||
|
||||
@@ -44,16 +47,16 @@ sub with_times {
|
||||
->search({},
|
||||
{
|
||||
'+columns' => {
|
||||
uptime_age => \("replace(age(timestamp 'epoch' + uptime / 100 * interval '1 second', "
|
||||
uptime_age => \("replace(age(timestamp 'epoch' + me.uptime / 100 * interval '1 second', "
|
||||
."timestamp '1970-01-01 00:00:00-00')::text, 'mon', 'month')"),
|
||||
first_seen_stamp => \"to_char(me.creation, 'YYYY-MM-DD HH24:MI')",
|
||||
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')",
|
||||
last_discover_stamp => \"to_char(me.last_discover, 'YYYY-MM-DD HH24:MI')",
|
||||
last_macsuck_stamp => \"to_char(me.last_macsuck, 'YYYY-MM-DD HH24:MI')",
|
||||
last_arpnip_stamp => \"to_char(me.last_arpnip, 'YYYY-MM-DD HH24:MI')",
|
||||
since_first_seen => \"extract(epoch from (age(now(), me.creation)))",
|
||||
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)))",
|
||||
since_last_discover => \"extract(epoch from (age(now(), me.last_discover)))",
|
||||
since_last_macsuck => \"extract(epoch from (age(now(), me.last_macsuck)))",
|
||||
since_last_arpnip => \"extract(epoch from (age(now(), me.last_arpnip)))",
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -591,12 +594,22 @@ handle the removal or archiving of nodes.
|
||||
|
||||
=cut
|
||||
|
||||
sub _plural { (shift || 0) == 1 ? 'entry' : 'entries' };
|
||||
|
||||
sub delete {
|
||||
my $self = shift;
|
||||
|
||||
my $schema = $self->result_source->schema;
|
||||
my $devices = $self->search(undef, { columns => 'ip' });
|
||||
|
||||
my $ip = undef;
|
||||
{
|
||||
no autovivification;
|
||||
try { $ip ||= $devices->{attrs}->{where}->{ip} };
|
||||
try { $ip ||= $devices->{attrs}->{where}->{'me.ip'} };
|
||||
}
|
||||
$ip ||= 'netdisco';
|
||||
|
||||
foreach my $set (qw/
|
||||
DeviceIp
|
||||
DeviceVlan
|
||||
@@ -604,9 +617,12 @@ sub delete {
|
||||
DeviceModule
|
||||
Community
|
||||
/) {
|
||||
$schema->resultset($set)->search(
|
||||
my $gone = $schema->resultset($set)->search(
|
||||
{ ip => { '-in' => $devices->as_query } },
|
||||
)->delete;
|
||||
|
||||
Dancer::Logger::debug sprintf ' [%s] db/device - removed %d %s from %s',
|
||||
$ip, $gone, _plural($gone), $set if defined Dancer::Logger::logger();
|
||||
}
|
||||
|
||||
foreach my $set (qw/
|
||||
@@ -618,13 +634,16 @@ sub delete {
|
||||
)->delete;
|
||||
}
|
||||
|
||||
$schema->resultset('Topology')->search({
|
||||
my $gone = $schema->resultset('Topology')->search({
|
||||
-or => [
|
||||
{ dev1 => { '-in' => $devices->as_query } },
|
||||
{ dev2 => { '-in' => $devices->as_query } },
|
||||
],
|
||||
})->delete;
|
||||
|
||||
Dancer::Logger::debug sprintf ' [%s] db/device - removed %d manual topology %s',
|
||||
$ip, $gone, _plural($gone) if defined Dancer::Logger::logger();
|
||||
|
||||
$schema->resultset('DevicePort')->search(
|
||||
{ ip => { '-in' => $devices->as_query } },
|
||||
)->delete(@_);
|
||||
|
||||
@@ -4,6 +4,9 @@ use base 'App::Netdisco::DB::ResultSet';
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Try::Tiny;
|
||||
require Dancer::Logger;
|
||||
|
||||
__PACKAGE__->load_components(qw/
|
||||
+App::Netdisco::DB::ExplicitLocking
|
||||
/);
|
||||
@@ -222,12 +225,22 @@ handle the removal or archiving of nodes.
|
||||
|
||||
=cut
|
||||
|
||||
sub _plural { (shift || 0) == 1 ? 'entry' : 'entries' };
|
||||
|
||||
sub delete {
|
||||
my $self = shift;
|
||||
|
||||
my $schema = $self->result_source->schema;
|
||||
my $ports = $self->search(undef, { columns => 'ip' });
|
||||
|
||||
my $ip = undef;
|
||||
{
|
||||
no autovivification;
|
||||
try { $ip ||= ${ $ports->{attrs}->{where}->{ip}->{'-in'} }->[1]->[1] };
|
||||
try { $ip ||= $ports->{attrs}->{where}->{'me.ip'} };
|
||||
}
|
||||
$ip ||= 'netdisco';
|
||||
|
||||
foreach my $set (qw/
|
||||
DevicePortPower
|
||||
DevicePortProperties
|
||||
@@ -235,9 +248,12 @@ sub delete {
|
||||
DevicePortWireless
|
||||
DevicePortSsid
|
||||
/) {
|
||||
$schema->resultset($set)->search(
|
||||
my $gone = $schema->resultset($set)->search(
|
||||
{ ip => { '-in' => $ports->as_query }},
|
||||
)->delete;
|
||||
|
||||
Dancer::Logger::debug sprintf ' [%s] db/ports - removed %d port %s from %s',
|
||||
$ip, $gone, _plural($gone), $set if defined Dancer::Logger::logger();
|
||||
}
|
||||
|
||||
$schema->resultset('Node')->search(
|
||||
|
||||
Reference in New Issue
Block a user