#912 use new all_oids format with additional status,enum,descr
This commit is contained in:
1
Build.PL
1
Build.PL
@@ -51,6 +51,7 @@ Module::Build->new(
|
|||||||
'Guard' => '1.022',
|
'Guard' => '1.022',
|
||||||
'HTML::Parser' => '3.70',
|
'HTML::Parser' => '3.70',
|
||||||
'HTTP::Tiny' => '0.029',
|
'HTTP::Tiny' => '0.029',
|
||||||
|
'IO::Uncompress::Gunzip' => '0',
|
||||||
'IO::Socket::INET6' => '2.72',
|
'IO::Socket::INET6' => '2.72',
|
||||||
'IO::Socket::SSL' => '2.048',
|
'IO::Socket::SSL' => '2.048',
|
||||||
'JSON' => '2.90',
|
'JSON' => '2.90',
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ __PACKAGE__->load_namespaces(
|
|||||||
);
|
);
|
||||||
|
|
||||||
our # try to hide from kwalitee
|
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 Path::Class;
|
||||||
use File::ShareDir 'dist_dir';
|
use File::ShareDir 'dist_dir';
|
||||||
|
|||||||
@@ -23,6 +23,12 @@ __PACKAGE__->add_columns(
|
|||||||
{ data_type => "text[]", is_nullable => 1, default_value => \"'{}'::text[]" },
|
{ data_type => "text[]", is_nullable => 1, default_value => \"'{}'::text[]" },
|
||||||
"num_children",
|
"num_children",
|
||||||
{ data_type => "integer", is_nullable => 0, default_value => \'0' },
|
{ 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");
|
__PACKAGE__->set_primary_key("oid");
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ __PACKAGE__->table("filtered_snmp_object");
|
|||||||
__PACKAGE__->result_source_instance->is_virtual(1);
|
__PACKAGE__->result_source_instance->is_virtual(1);
|
||||||
__PACKAGE__->result_source_instance->view_definition(<<ENDSQL
|
__PACKAGE__->result_source_instance->view_definition(<<ENDSQL
|
||||||
|
|
||||||
SELECT so.oid, so.oid_parts, so.mib, so.leaf, so.type, so.access, so.index, so.num_children,
|
SELECT so.oid, so.oid_parts, so.mib, so.leaf, so.type, so.access, so.index, so.status, so.enum, so.descr, so.num_children,
|
||||||
count(db.oid) AS browser
|
count(db.oid) AS browser
|
||||||
FROM snmp_object so
|
FROM snmp_object so
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ __PACKAGE__->result_source_instance->view_definition(<<ENDSQL
|
|||||||
WHERE array_length(so.oid_parts,1) = ?
|
WHERE array_length(so.oid_parts,1) = ?
|
||||||
AND so.oid LIKE ?::text || '.%'
|
AND so.oid LIKE ?::text || '.%'
|
||||||
|
|
||||||
GROUP BY so.oid, so.oid_parts, so.mib, so.leaf, so.type, so.access, so.index, so.num_children
|
GROUP BY so.oid, so.oid_parts, so.mib, so.leaf, so.type, so.access, so.index, so.status, so.enum, so.descr, so.num_children
|
||||||
|
|
||||||
ENDSQL
|
ENDSQL
|
||||||
);
|
);
|
||||||
@@ -38,6 +38,9 @@ __PACKAGE__->add_columns(
|
|||||||
'type' => { data_type => 'text' },
|
'type' => { data_type => 'text' },
|
||||||
'access' => { data_type => 'text' },
|
'access' => { data_type => 'text' },
|
||||||
'index' => { data_type => 'text[]' },
|
'index' => { data_type => 'text[]' },
|
||||||
|
'status' => { data_type => 'text' },
|
||||||
|
'enum' => { data_type => 'text[]' },
|
||||||
|
'descr' => { data_type => 'text' },
|
||||||
'num_children' => { data_type => 'integer' },
|
'num_children' => { data_type => 'integer' },
|
||||||
'browser' => { data_type => 'integer' },
|
'browser' => { data_type => 'integer' },
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ ajax '/ajax/data/device/:ip/snmptree/:base' => require_login sub {
|
|||||||
to_json $items;
|
to_json $items;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# TODO add form option for limiting to this device, so leave :ip
|
||||||
ajax '/ajax/data/device/:ip/typeahead' => require_login sub {
|
ajax '/ajax/data/device/:ip/typeahead' => require_login sub {
|
||||||
my $device = try { schema('netdisco')->resultset('Device')
|
my $device = try { schema('netdisco')->resultset('Device')
|
||||||
->find( param('ip') ) }
|
->find( param('ip') ) }
|
||||||
@@ -48,8 +49,8 @@ ajax '/ajax/data/device/:ip/typeahead' => require_login sub {
|
|||||||
my $term = param('term') or return to_json [];
|
my $term = param('term') or return to_json [];
|
||||||
$term = '%'. $term .'%';
|
$term = '%'. $term .'%';
|
||||||
|
|
||||||
my @found = schema('netdisco')->resultset('DeviceBrowser')
|
my @found = schema('netdisco')->resultset('SNMPObject')
|
||||||
->search({ leaf => { -ilike => $term }, ip => $device->ip },
|
->search({ leaf => { -ilike => $term } },
|
||||||
{ rows => 25, columns => 'leaf' })
|
{ rows => 25, columns => 'leaf' })
|
||||||
->get_column('leaf')->all;
|
->get_column('leaf')->all;
|
||||||
return to_json [] unless scalar @found;
|
return to_json [] unless scalar @found;
|
||||||
@@ -58,6 +59,7 @@ ajax '/ajax/data/device/:ip/typeahead' => require_login sub {
|
|||||||
to_json [ sort @found ];
|
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 {
|
ajax '/ajax/data/device/:ip/snmpnodesearch' => require_login sub {
|
||||||
my $device = try { schema('netdisco')->resultset('Device')
|
my $device = try { schema('netdisco')->resultset('Device')
|
||||||
->find( param('ip') ) }
|
->find( param('ip') ) }
|
||||||
@@ -72,8 +74,8 @@ ajax '/ajax/data/device/:ip/snmpnodesearch' => require_login sub {
|
|||||||
my $found = undef;
|
my $found = undef;
|
||||||
|
|
||||||
my $op = ($partial ? '-ilike' : '=');
|
my $op = ($partial ? '-ilike' : '=');
|
||||||
$found = schema('netdisco')->resultset('DeviceBrowser')
|
$found = schema('netdisco')->resultset('SNMPObject')
|
||||||
->search({ -or => [ oid => { $op => $to_match }, leaf => { $op => $to_match } ], ip => $device->ip },
|
->search({ -or => [ oid => { $op => $to_match }, leaf => { $op => $to_match } ] },
|
||||||
{ rows => 1, order_by => 'oid_parts' })->first;
|
{ rows => 1, order_by => 'oid_parts' })->first;
|
||||||
|
|
||||||
return to_json [] unless $found;
|
return to_json [] unless $found;
|
||||||
@@ -140,7 +142,7 @@ sub _get_snmp_data {
|
|||||||
(scalar @{$meta{$_}->{index}}
|
(scalar @{$meta{$_}->{index}}
|
||||||
? (icon => 'icon-th'.($meta{$_}->{browser} ? ' text-info' : ' muted')) : ()),
|
? (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')) : ()),
|
? (icon => 'icon-leaf'.($meta{$_}->{browser} ? ' text-info' : ' muted')) : ()),
|
||||||
|
|
||||||
# jstree will async call to expand these, and while it's possible
|
# jstree will async call to expand these, and while it's possible
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ use Dancer::Plugin::DBIC 'schema';
|
|||||||
|
|
||||||
use File::Spec::Functions qw(catdir catfile);
|
use File::Spec::Functions qw(catdir catfile);
|
||||||
use File::Slurper qw(read_lines write_text);
|
use File::Slurper qw(read_lines write_text);
|
||||||
|
use IO::Uncompress::Gunzip qw(gunzip $GunzipError);
|
||||||
|
use File::Temp;
|
||||||
# use DDP;
|
# use DDP;
|
||||||
|
|
||||||
register_worker({ phase => 'main' }, sub {
|
register_worker({ phase => 'main' }, sub {
|
||||||
@@ -16,13 +18,17 @@ register_worker({ phase => 'main' }, sub {
|
|||||||
debug "loadmibs - loading netdisco-mibs object cache";
|
debug "loadmibs - loading netdisco-mibs object cache";
|
||||||
|
|
||||||
my $home = (setting('mibhome') || catdir(($ENV{NETDISCO_HOME} || $ENV{HOME}), 'netdisco-mibs'));
|
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 @browser = ();
|
||||||
my %children = ();
|
my %children = ();
|
||||||
|
|
||||||
foreach my $line (@report) {
|
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;
|
next unless defined $oid and defined $qual_leaf;
|
||||||
|
|
||||||
my ($mib, $leaf) = split m/::/, $qual_leaf;
|
my ($mib, $leaf) = split m/::/, $qual_leaf;
|
||||||
@@ -38,6 +44,9 @@ register_worker({ phase => 'main' }, sub {
|
|||||||
type => $type,
|
type => $type,
|
||||||
access => $access,
|
access => $access,
|
||||||
index => [($index ? (split m/:/, $index) : ())],
|
index => [($index ? (split m/:/, $index) : ())],
|
||||||
|
status => $status,
|
||||||
|
enum => [($enum ? (split m/:/, $enum ) : ())],
|
||||||
|
descr => $descr,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
<td></td>
|
<td></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Munge</th>
|
<th scope="row">Unpacker</th>
|
||||||
<td></td>
|
<td></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -44,6 +44,18 @@
|
|||||||
<th scope="row">Index</th>
|
<th scope="row">Index</th>
|
||||||
<td></td>
|
<td></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Status</th>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Enum Syntax</th>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Description</th>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Value</th>
|
<th scope="row">Value</th>
|
||||||
<td></td>
|
<td></td>
|
||||||
|
|||||||
@@ -2,28 +2,28 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row" class="span1">OID</th>
|
<th scope="row" class="span1">OID</th>
|
||||||
<td>[% node.snmp_object.oid %]</td>
|
<td>[% node.snmp_object.oid | html_entity %]</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Module</th>
|
<th scope="row">Module</th>
|
||||||
<td>[% node.snmp_object.mib %]</td>
|
<td>[% node.snmp_object.mib | html_entity %]</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Leaf</th>
|
<th scope="row">Leaf</th>
|
||||||
<td>[% node.snmp_object.leaf %]</td>
|
<td>[% node.snmp_object.leaf | html_entity %]</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Type</th>
|
<th scope="row">Type</th>
|
||||||
<td>[% node.snmp_object.type %]</td>
|
<td>[% node.snmp_object.type | html_entity %]</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Munge</th>
|
<th scope="row">Unpacker</th>
|
||||||
<td>
|
<td>
|
||||||
[% IF node.value %]
|
[% IF node.value %]
|
||||||
<select name="munger" id="munger">
|
<select name="munger" id="munger">
|
||||||
[% UNLESS munge %]<option value="" selected disabled hidden>None applied</option>[% END %]
|
[% UNLESS munge %]<option value="" selected disabled hidden>None applied</option>[% END %]
|
||||||
[% FOREACH m IN mungers %]
|
[% FOREACH m IN mungers %]
|
||||||
<option [% 'selected' IF m == munge %] value="[% m %]">[% m %]</option>
|
<option [% 'selected' IF m == munge %] value="[% m | uri %]">[% m | html_entity %]</option>
|
||||||
[% END %]
|
[% END %]
|
||||||
</select>
|
</select>
|
||||||
[% END %]
|
[% END %]
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Access</th>
|
<th scope="row">Access</th>
|
||||||
<td>[% node.snmp_object.access %]</td>
|
<td>[% node.snmp_object.access | html_entity %]</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Index</th>
|
<th scope="row">Index</th>
|
||||||
@@ -39,15 +39,35 @@
|
|||||||
[% IF node.snmp_object.index.size > 0 %]
|
[% IF node.snmp_object.index.size > 0 %]
|
||||||
<table class="table table-condensed table-bordered">
|
<table class="table table-condensed table-bordered">
|
||||||
[% FOREACH idx IN node.snmp_object.index %]
|
[% FOREACH idx IN node.snmp_object.index %]
|
||||||
<tr><td>[% idx %]</td></tr>
|
<tr><td>[% idx | html_entity %]</td></tr>
|
||||||
[% END %]
|
[% END %]
|
||||||
</table>
|
</table>
|
||||||
[% END %]
|
[% END %]
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Status</th>
|
||||||
|
<td>[% node.snmp_object.status | html_entity %]</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Enum Syntax</th>
|
||||||
|
<td>
|
||||||
|
[% IF node.snmp_object.enum.size > 0 %]
|
||||||
|
<table class="table table-condensed table-bordered">
|
||||||
|
[% FOREACH idx IN node.snmp_object.enum %]
|
||||||
|
<tr><td>[% idx | html_entity %]</td></tr>
|
||||||
|
[% END %]
|
||||||
|
</table>
|
||||||
|
[% END %]
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Description</th>
|
||||||
|
<td>[% node.snmp_object.descr | html_entity %]</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Value</th>
|
<th scope="row">Value</th>
|
||||||
<td>[% IF node.value %]<pre id="snmp_node_value">[% node.value %]</pre>[% END %]</td>
|
<td>[% IF node.value %]<pre id="snmp_node_value">[% node.value | html_entity %]</pre>[% END %]</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
Reference in New Issue
Block a user