diff --git a/Build.PL b/Build.PL index 1b1e7abd..8731e767 100644 --- a/Build.PL +++ b/Build.PL @@ -51,6 +51,7 @@ Module::Build->new( 'Guard' => '1.022', 'HTML::Parser' => '3.70', 'HTTP::Tiny' => '0.029', + 'IO::Uncompress::Gunzip' => '0', 'IO::Socket::INET6' => '2.72', 'IO::Socket::SSL' => '2.048', 'JSON' => '2.90', diff --git a/lib/App/Netdisco/DB.pm b/lib/App/Netdisco/DB.pm index 183e0f0d..187322ed 100644 --- a/lib/App/Netdisco/DB.pm +++ b/lib/App/Netdisco/DB.pm @@ -11,7 +11,7 @@ __PACKAGE__->load_namespaces( ); our # try to hide from kwalitee - $VERSION = 73; # schema version used for upgrades, keep as integer + $VERSION = 74; # schema version used for upgrades, keep as integer use Path::Class; use File::ShareDir 'dist_dir'; diff --git a/lib/App/Netdisco/DB/Result/SNMPObject.pm b/lib/App/Netdisco/DB/Result/SNMPObject.pm index 2360ebcc..9543f806 100644 --- a/lib/App/Netdisco/DB/Result/SNMPObject.pm +++ b/lib/App/Netdisco/DB/Result/SNMPObject.pm @@ -23,6 +23,12 @@ __PACKAGE__->add_columns( { data_type => "text[]", is_nullable => 1, default_value => \"'{}'::text[]" }, "num_children", { data_type => "integer", is_nullable => 0, default_value => \'0' }, + "status", + { data_type => "text", is_nullable => 1 }, + "enum", + { data_type => "text[]", is_nullable => 1, default_value => \"'{}'::text[]" }, + "descr", + { data_type => "text", is_nullable => 1 }, ); __PACKAGE__->set_primary_key("oid"); diff --git a/lib/App/Netdisco/DB/Result/Virtual/FilteredSNMPObject.pm b/lib/App/Netdisco/DB/Result/Virtual/FilteredSNMPObject.pm index 927c0dba..020b9db5 100644 --- a/lib/App/Netdisco/DB/Result/Virtual/FilteredSNMPObject.pm +++ b/lib/App/Netdisco/DB/Result/Virtual/FilteredSNMPObject.pm @@ -12,7 +12,7 @@ __PACKAGE__->table("filtered_snmp_object"); __PACKAGE__->result_source_instance->is_virtual(1); __PACKAGE__->result_source_instance->view_definition(<result_source_instance->view_definition(<add_columns( 'type' => { data_type => 'text' }, 'access' => { data_type => 'text' }, 'index' => { data_type => 'text[]' }, + 'status' => { data_type => 'text' }, + 'enum' => { data_type => 'text[]' }, + 'descr' => { data_type => 'text' }, 'num_children' => { data_type => 'integer' }, 'browser' => { data_type => 'integer' }, ); diff --git a/lib/App/Netdisco/Web/Plugin/Device/SNMP.pm b/lib/App/Netdisco/Web/Plugin/Device/SNMP.pm index 7bd1f53e..c15a4f10 100644 --- a/lib/App/Netdisco/Web/Plugin/Device/SNMP.pm +++ b/lib/App/Netdisco/Web/Plugin/Device/SNMP.pm @@ -40,6 +40,7 @@ ajax '/ajax/data/device/:ip/snmptree/:base' => require_login sub { to_json $items; }; +# TODO add form option for limiting to this device, so leave :ip ajax '/ajax/data/device/:ip/typeahead' => require_login sub { my $device = try { schema('netdisco')->resultset('Device') ->find( param('ip') ) } @@ -48,8 +49,8 @@ ajax '/ajax/data/device/:ip/typeahead' => require_login sub { my $term = param('term') or return to_json []; $term = '%'. $term .'%'; - my @found = schema('netdisco')->resultset('DeviceBrowser') - ->search({ leaf => { -ilike => $term }, ip => $device->ip }, + my @found = schema('netdisco')->resultset('SNMPObject') + ->search({ leaf => { -ilike => $term } }, { rows => 25, columns => 'leaf' }) ->get_column('leaf')->all; return to_json [] unless scalar @found; @@ -58,6 +59,7 @@ ajax '/ajax/data/device/:ip/typeahead' => require_login sub { to_json [ sort @found ]; }; +# TODO add form option for limiting to this device, so leave :ip ajax '/ajax/data/device/:ip/snmpnodesearch' => require_login sub { my $device = try { schema('netdisco')->resultset('Device') ->find( param('ip') ) } @@ -72,8 +74,8 @@ ajax '/ajax/data/device/:ip/snmpnodesearch' => require_login sub { my $found = undef; my $op = ($partial ? '-ilike' : '='); - $found = schema('netdisco')->resultset('DeviceBrowser') - ->search({ -or => [ oid => { $op => $to_match }, leaf => { $op => $to_match } ], ip => $device->ip }, + $found = schema('netdisco')->resultset('SNMPObject') + ->search({ -or => [ oid => { $op => $to_match }, leaf => { $op => $to_match } ] }, { rows => 1, order_by => 'oid_parts' })->first; return to_json [] unless $found; @@ -140,7 +142,7 @@ sub _get_snmp_data { (scalar @{$meta{$_}->{index}} ? (icon => 'icon-th'.($meta{$_}->{browser} ? ' text-info' : ' muted')) : ()), - (($meta{$_}->{num_children} == 0 and ($meta{$_}->{type} or $meta{$_}->{oid_parts}->[-1] == 0)) + (($meta{$_}->{num_children} == 0 and ($meta{$_}->{access} =~ m/^(?:read|write)/ or $meta{$_}->{oid_parts}->[-1] == 0)) ? (icon => 'icon-leaf'.($meta{$_}->{browser} ? ' text-info' : ' muted')) : ()), # jstree will async call to expand these, and while it's possible diff --git a/lib/App/Netdisco/Worker/Plugin/LoadMIBs.pm b/lib/App/Netdisco/Worker/Plugin/LoadMIBs.pm index fc75d816..20bb644e 100644 --- a/lib/App/Netdisco/Worker/Plugin/LoadMIBs.pm +++ b/lib/App/Netdisco/Worker/Plugin/LoadMIBs.pm @@ -8,6 +8,8 @@ use Dancer::Plugin::DBIC 'schema'; use File::Spec::Functions qw(catdir catfile); use File::Slurper qw(read_lines write_text); +use IO::Uncompress::Gunzip qw(gunzip $GunzipError); +use File::Temp; # use DDP; register_worker({ phase => 'main' }, sub { @@ -16,13 +18,17 @@ register_worker({ phase => 'main' }, sub { debug "loadmibs - loading netdisco-mibs object cache"; my $home = (setting('mibhome') || catdir(($ENV{NETDISCO_HOME} || $ENV{HOME}), 'netdisco-mibs')); - my @report = read_lines(catfile($home, qw(EXTRAS reports all_oids)), 'latin-1'); + my $infile = catfile($home, qw(EXTRAS reports all_oids)); + my $outfh = File::Temp->new(); + my $outfile = $outfh->filename; + gunzip $infile => $outfile or die "gunzip failed: $GunzipError\n"; + my @report = read_lines($outfile, 'latin-1'); my @browser = (); my %children = (); foreach my $line (@report) { - my ($oid, $qual_leaf, $type, $access, $index) = split m/,/, $line; + my ($oid, $qual_leaf, $type, $access, $index, $status, $enum, $descr) = split m/,/, $line, 8; next unless defined $oid and defined $qual_leaf; my ($mib, $leaf) = split m/::/, $qual_leaf; @@ -38,6 +44,9 @@ register_worker({ phase => 'main' }, sub { type => $type, access => $access, index => [($index ? (split m/:/, $index) : ())], + status => $status, + enum => [($enum ? (split m/:/, $enum ) : ())], + descr => $descr, }; } diff --git a/share/schema_versions/App-Netdisco-DB-73-74-PostgreSQL.sql b/share/schema_versions/App-Netdisco-DB-73-74-PostgreSQL.sql new file mode 100644 index 00000000..e1a88486 --- /dev/null +++ b/share/schema_versions/App-Netdisco-DB-73-74-PostgreSQL.sql @@ -0,0 +1,7 @@ +BEGIN; + +ALTER TABLE snmp_object ADD COLUMN "status" text; +ALTER TABLE snmp_object ADD COLUMN "enum" text[] DEFAULT '{}' NOT NULL; +ALTER TABLE snmp_object ADD COLUMN "descr" text; + +COMMIT; diff --git a/share/views/ajax/device/snmp.tt b/share/views/ajax/device/snmp.tt index 4d6d1fe2..c6a2516c 100644 --- a/share/views/ajax/device/snmp.tt +++ b/share/views/ajax/device/snmp.tt @@ -33,7 +33,7 @@ - Munge + Unpacker @@ -44,6 +44,18 @@ Index + + Status + + + + Enum Syntax + + + + Description + + Value diff --git a/share/views/ajax/device/snmpnode.tt b/share/views/ajax/device/snmpnode.tt index 28d0d50d..dc8ed79e 100644 --- a/share/views/ajax/device/snmpnode.tt +++ b/share/views/ajax/device/snmpnode.tt @@ -2,28 +2,28 @@ OID - [% node.snmp_object.oid %] + [% node.snmp_object.oid | html_entity %] Module - [% node.snmp_object.mib %] + [% node.snmp_object.mib | html_entity %] Leaf - [% node.snmp_object.leaf %] + [% node.snmp_object.leaf | html_entity %] Type - [% node.snmp_object.type %] + [% node.snmp_object.type | html_entity %] - Munge + Unpacker [% IF node.value %] [% END %] @@ -31,7 +31,7 @@ Access - [% node.snmp_object.access %] + [% node.snmp_object.access | html_entity %] Index @@ -39,15 +39,35 @@ [% IF node.snmp_object.index.size > 0 %] [% FOREACH idx IN node.snmp_object.index %] - + [% END %]
[% idx %]
[% idx | html_entity %]
[% END %] + + Status + [% node.snmp_object.status | html_entity %] + + + Enum Syntax + + [% IF node.snmp_object.enum.size > 0 %] + + [% FOREACH idx IN node.snmp_object.enum %] + + [% END %] +
[% idx | html_entity %]
+ [% END %] + + + + Description + [% node.snmp_object.descr | html_entity %] + Value - [% IF node.value %]
[% node.value %]
[% END %] + [% IF node.value %]
[% node.value | html_entity %]
[% END %]