From dfeb9d9ddc114c0ad6f1779f60fbba285c1d0503 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sun, 8 Oct 2017 18:40:02 +0100 Subject: [PATCH] make device_auth have driver setting for snmp entries --- lib/App/Netdisco/Util/SNMP.pm | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/App/Netdisco/Util/SNMP.pm b/lib/App/Netdisco/Util/SNMP.pm index aa20b9a5..eeea2fa8 100644 --- a/lib/App/Netdisco/Util/SNMP.pm +++ b/lib/App/Netdisco/Util/SNMP.pm @@ -80,6 +80,12 @@ sub fixup_device_auth { community => $_, }} @{setting('community_rw') || []}; + foreach my $stanza (@new_stanzas) { + $stanza->{driver} ||= 'snmp' + if exists $stanza->{community} + or exists $stanza->{user}; + } + return @new_stanzas; } @@ -109,20 +115,26 @@ sub get_communities { if ($device->in_storage and $stored_tag) { foreach my $stanza (@$config) { if ($stanza->{tag} and $stored_tag eq $stanza->{tag}) { - push @communities, $stanza; + push @communities, {%$stanza, only => [$device->ip]}; last; } } } # try last-known-good v2 read - push @communities, {read => 1, community => $device->snmp_comm} - if defined $device->snmp_comm and $mode eq 'read'; + push @communities, { + read => 1, write => 0, driver => 'snmp', + only => [$device->ip], + community => $device->snmp_comm, + } if defined $device->snmp_comm and $mode eq 'read'; # try last-known-good v2 write my $snmp_comm_rw = eval { $device->community->snmp_comm_rw }; - push @communities, {write => 1, community => $snmp_comm_rw} - if $snmp_comm_rw and $mode eq 'write'; + push @communities, { + write => 1, read => 0, driver => 'snmp', + only => [$device->ip], + community => $snmp_comm_rw, + } if $snmp_comm_rw and $mode eq 'write'; # clean the community table of obsolete tags eval { $device->community->update({$tag_name => undef}) } @@ -151,6 +163,7 @@ sub _get_external_community { if (length $1 and $mode eq 'read') { return map {{ read => 1, + only => [$device->ip], community => $_, }} split(m/\s*,\s*/,$1); } @@ -159,6 +172,7 @@ sub _get_external_community { if (length $1 and $mode eq 'write') { return map {{ write => 1, + only => [$device->ip], community => $_, }} split(m/\s*,\s*/,$1); }