From b8ddbd1eca7eadbec3947edd09af352136446e9b Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Thu, 4 Apr 2013 17:08:06 +0100 Subject: [PATCH] implementation of store_wireless (without storing, yet) --- .../Netdisco/Daemon/Worker/Poller/Discover.pm | 2 +- .../lib/App/Netdisco/Util/DiscoverAndStore.pm | 70 ++++++++++++++++++- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/Netdisco/lib/App/Netdisco/Daemon/Worker/Poller/Discover.pm b/Netdisco/lib/App/Netdisco/Daemon/Worker/Poller/Discover.pm index 688672a0..9b1b5c9b 100644 --- a/Netdisco/lib/App/Netdisco/Daemon/Worker/Poller/Discover.pm +++ b/Netdisco/lib/App/Netdisco/Daemon/Worker/Poller/Discover.pm @@ -43,7 +43,7 @@ sub discover { store_device($device, $snmp); store_interfaces($device, $snmp); - #store_wireless($device, $snmp); + store_wireless($device, $snmp); #store_vlans($device, $snmp); #store_power($device, $snmp); #store_modules($device, $snmp); diff --git a/Netdisco/lib/App/Netdisco/Util/DiscoverAndStore.pm b/Netdisco/lib/App/Netdisco/Util/DiscoverAndStore.pm index ac6ada3a..688a8b90 100644 --- a/Netdisco/lib/App/Netdisco/Util/DiscoverAndStore.pm +++ b/Netdisco/lib/App/Netdisco/Util/DiscoverAndStore.pm @@ -9,7 +9,7 @@ use NetAddr::IP::Lite ':lower'; use base 'Exporter'; our @EXPORT = (); our @EXPORT_OK = qw/ - store_device store_interfaces + store_device store_interfaces store_wireless /; our %EXPORT_TAGS = (all => \@EXPORT_OK); @@ -196,4 +196,72 @@ sub store_interfaces { }); } +=head2 store_wireless( $device, $snmp ) + +Given a Device database object, and a working SNMP connection, discover and +store the device's wireless interface information. + +The Device database object can be a fresh L object which is +not yet stored to the database. + +=cut + +sub store_wireless { + my ($device, $snmp) = @_; + + my $ssidlist = $snmp->i_ssidlist; + return unless scalar keys %$ssidlist; + + my $interfaces = $snmp->interfaces; + my $ssidbcast = $snmp->i_ssidbcast; + my $ssidmac = $snmp->i_ssidmac; + my $channel = $snmp->i_80211channel; + my $power = $snmp->i_dot11_cur_tx_pwr_mw; + + # build device ssid list suitable for DBIC + my @ssids; + foreach my $entry (keys %$ssidlist) { + $entry =~ s/\.\d+$//; + my $port = $interfaces->{$entry}; + + if (not length $port) { + # TODO log message + next; + } + + push @ssids, { + port => $port, + ssid => $ssidlist->{$entry}, + broadcast => $ssidbcast->{$entry}, + bssid => $ssidmac->{$entry}, + }; + } + + # build device channel list suitable for DBIC + my @channels; + foreach my $entry (keys %$channel) { + $entry =~ s/\.\d+$//; + my $port = $interfaces->{$entry}; + + if (not length $port) { + # TODO log message + next; + } + + push @channels, { + port => $port, + channel => $channel->{$entry}, + power => $power->{$entry}, + }; + } + + # FIXME not sure what relations need adding for wireless ports + # + #schema('netdisco')->txn_do(sub { + # $device->ports->delete; + # $device->update_or_insert; + # $device->ports->populate(\@interfaces); + #}); +} + 1;