[#110] rules for IP Phone and Wireless AP identification now configurable
This commit is contained in:
		@@ -3,11 +3,13 @@ package App::Netdisco::Core::Discover;
 | 
			
		||||
use Dancer qw/:syntax :script/;
 | 
			
		||||
use Dancer::Plugin::DBIC 'schema';
 | 
			
		||||
 | 
			
		||||
use App::Netdisco::Util::Device qw/get_device is_discoverable/;
 | 
			
		||||
use App::Netdisco::Util::Device
 | 
			
		||||
  qw/get_device match_devicetype is_discoverable/;
 | 
			
		||||
use App::Netdisco::Util::DNS ':all';
 | 
			
		||||
use App::Netdisco::JobQueue qw/jq_queued jq_insert/;
 | 
			
		||||
use NetAddr::IP::Lite ':lower';
 | 
			
		||||
use List::MoreUtils ();
 | 
			
		||||
use Scalar::Util 'blessed';
 | 
			
		||||
use Encode;
 | 
			
		||||
use Try::Tiny;
 | 
			
		||||
use NetAddr::MAC;
 | 
			
		||||
@@ -723,14 +725,16 @@ sub store_neighbors {
 | 
			
		||||
 | 
			
		||||
      # IP Phone and WAP detection type fixup
 | 
			
		||||
      if (scalar @$remote_cap or $remote_type) {
 | 
			
		||||
          my $phone_flag = grep {/phone/i} @$remote_cap;
 | 
			
		||||
          my $ap_flag    = grep {/wlanAccessPoint/} @$remote_cap;
 | 
			
		||||
          my $phone_flag = grep {match_devicetype($_, 'phone_capabilities')}
 | 
			
		||||
                                @$remote_cap;
 | 
			
		||||
          my $ap_flag    = grep {match_devicetype($_, 'wap_capabilities')}
 | 
			
		||||
                                @$remote_cap;
 | 
			
		||||
 | 
			
		||||
          if ($phone_flag or $remote_type =~ m/mitel.5\d{3}/i) {
 | 
			
		||||
          if ($phone_flag or match_devicetype($remote_type, 'phone_platforms')) {
 | 
			
		||||
              $remote_type = 'IP Phone: '. $remote_type
 | 
			
		||||
                if $remote_type !~ /ip phone/i;
 | 
			
		||||
                if $remote_type !~ /ip.phone/i;
 | 
			
		||||
          }
 | 
			
		||||
          elsif ($ap_flag or $remote_type =~ m/\bw?ap\b/i) {
 | 
			
		||||
          elsif ($ap_flag or match_devicetype($remote_type, 'wap_platforms')) {
 | 
			
		||||
              $remote_type = 'AP: '. $remote_type;
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
@@ -831,8 +835,21 @@ sub store_neighbors {
 | 
			
		||||
              push @to_discover, [$remote_ip, $remote_type];
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
          $remote_port = $c_port->{$entry};
 | 
			
		||||
          # further device type discovery using MAC OUI
 | 
			
		||||
          # only works once device is fully discovered (so we have a MAC addr)
 | 
			
		||||
          my $neigh = get_device($remote_ip);
 | 
			
		||||
          if (blessed $neigh and $neigh->in_storage and $neigh->mac) {
 | 
			
		||||
              if (match_devicetype($neigh->mac, 'phone_ouis')) {
 | 
			
		||||
                  $remote_type = 'IP Phone: '. $remote_type
 | 
			
		||||
                    if $remote_type !~ /ip.phone/i;
 | 
			
		||||
              }
 | 
			
		||||
              elsif (match_devicetype($neigh->mac, 'wap_ouis')) {
 | 
			
		||||
                  $remote_type = 'AP: '. $remote_type
 | 
			
		||||
                    if $remote_type !~ /^AP: /;
 | 
			
		||||
              }
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
          $remote_port = $c_port->{$entry};
 | 
			
		||||
          if (defined $remote_port) {
 | 
			
		||||
              # clean weird characters
 | 
			
		||||
              $remote_port =~ s/[^\d\/\.,()\w:-]+//gi;
 | 
			
		||||
 
 | 
			
		||||
@@ -252,6 +252,14 @@ sub renumber {
 | 
			
		||||
 | 
			
		||||
=head1 ADDITIONAL COLUMNS
 | 
			
		||||
 | 
			
		||||
=head2 oui
 | 
			
		||||
 | 
			
		||||
Returns the first half of the device MAC address.
 | 
			
		||||
 | 
			
		||||
=cut
 | 
			
		||||
 | 
			
		||||
sub oui { return substr( ((shift)->mac || ''), 0, 8 ) }
 | 
			
		||||
 | 
			
		||||
=head2 port_count
 | 
			
		||||
 | 
			
		||||
Returns the number of ports on this device. Enable this
 | 
			
		||||
 
 | 
			
		||||
@@ -961,6 +961,92 @@ Value: Boolean. Default: C<false>.
 | 
			
		||||
Turn this on to have Netdisco do a reverse lookup of the device C<sysName.0>
 | 
			
		||||
field to use as the management IP address for a device.
 | 
			
		||||
 | 
			
		||||
=head3 C<phone_capabilities>
 | 
			
		||||
 | 
			
		||||
Value: List of Strings. Default:
 | 
			
		||||
 | 
			
		||||
 phone_capabilities:
 | 
			
		||||
   - '(?i:phone)'
 | 
			
		||||
 | 
			
		||||
Regular expressions to match the Capability field received within neighbor
 | 
			
		||||
discovery protocols such as CDP/FDP/LLDP. Netdisco uses this to display a
 | 
			
		||||
"phone" icon alongside devices or nodes in the Device Ports table.
 | 
			
		||||
 | 
			
		||||
To find the received Capabilities on an upstream device, run this command:
 | 
			
		||||
 | 
			
		||||
 ~netdisco/bin/netdisco-do show -d <IP-of-device> -e c_cap
 | 
			
		||||
 | 
			
		||||
=head3 C<phone_platforms>
 | 
			
		||||
 | 
			
		||||
Value: List of Strings. Default:
 | 
			
		||||
 | 
			
		||||
 phone_platforms:
 | 
			
		||||
   - '(?i:mitel.5\d{3})'
 | 
			
		||||
 | 
			
		||||
Regular expressions to match the Platform field received within neighbor
 | 
			
		||||
discovery protocols such as CDP/FDP/LLDP. Netdisco uses this to display a
 | 
			
		||||
"phone" icon alongside devices or nodes in the Device Ports table.
 | 
			
		||||
 | 
			
		||||
To find the received Platforms on an upstream device, run this command:
 | 
			
		||||
 | 
			
		||||
 ~netdisco/bin/netdisco-do show -d <IP-of-device> -e c_platform
 | 
			
		||||
 | 
			
		||||
=head3 C<phone_ouis>
 | 
			
		||||
 | 
			
		||||
Value: List of Strings. Default: Empty List.
 | 
			
		||||
 | 
			
		||||
If you can't get C<phone_capabilities> or C<phone_platforms> to match, as a
 | 
			
		||||
last ditch attempt you can match on the MAC address of the device (if it has
 | 
			
		||||
one). This is a set of regular expressions matched against the whole MAC
 | 
			
		||||
address (not only the OUI portion) in IEEE format. For example:
 | 
			
		||||
 | 
			
		||||
 phone_ouis:
 | 
			
		||||
   - '^a4:0c:c3'
 | 
			
		||||
 | 
			
		||||
=head3 C<wap_capabilities>
 | 
			
		||||
 | 
			
		||||
Value: List of Strings. Default:
 | 
			
		||||
 | 
			
		||||
 wap_capabilities:
 | 
			
		||||
   - 'wlanAccessPoint'
 | 
			
		||||
 | 
			
		||||
Regular expressions to match the Capability field received within neighbor
 | 
			
		||||
discovery protocols such as CDP/FDP/LLDP. Netdisco uses this to display a
 | 
			
		||||
"wireless signal" icon alongside devices or nodes in the Device Ports table.
 | 
			
		||||
 | 
			
		||||
To find the received Capabilities on an upstream device, run this command:
 | 
			
		||||
 | 
			
		||||
 ~netdisco/bin/netdisco-do show -d <IP-of-device> -e c_cap
 | 
			
		||||
 | 
			
		||||
=head3 C<wap_platforms>
 | 
			
		||||
 | 
			
		||||
Value: List of Strings. Default:
 | 
			
		||||
 | 
			
		||||
 wap_platforms:
 | 
			
		||||
   - '(?i:\bw?ap\b)'
 | 
			
		||||
   - 'cisco\s+AIR-[L|C]?AP'
 | 
			
		||||
   - '-K9W8-'
 | 
			
		||||
 | 
			
		||||
Regular expressions to match the Platform field received within neighbor
 | 
			
		||||
discovery protocols such as CDP/FDP/LLDP. Netdisco uses this to display a
 | 
			
		||||
"wireless signal" icon alongside devices or nodes in the Device Ports table.
 | 
			
		||||
 | 
			
		||||
To find the received Platforms on an upstream device, run this command:
 | 
			
		||||
 | 
			
		||||
 ~netdisco/bin/netdisco-do show -d <IP-of-device> -e c_platform
 | 
			
		||||
 | 
			
		||||
=head3 C<wap_ouis>
 | 
			
		||||
 | 
			
		||||
Value: List of Strings. Default: Empty List.
 | 
			
		||||
 | 
			
		||||
If you can't get C<wap_capabilities> or C<wap_platforms> to match, as a last
 | 
			
		||||
ditch attempt you can match on the MAC address of the device (if it has one).
 | 
			
		||||
This is a set of regular expressions matched against the whole MAC address
 | 
			
		||||
(not only the OUI portion) in IEEE format. For example:
 | 
			
		||||
 | 
			
		||||
 wap_ouis:
 | 
			
		||||
   - '^a4:0c:c3'
 | 
			
		||||
 | 
			
		||||
=head2 Backend Daemon
 | 
			
		||||
 | 
			
		||||
=head3 C<workers>
 | 
			
		||||
 
 | 
			
		||||
@@ -36,6 +36,19 @@ but they are backwards compatible.
 | 
			
		||||
 | 
			
		||||
=back
 | 
			
		||||
 | 
			
		||||
=head1 2.032000
 | 
			
		||||
 | 
			
		||||
=head2 General Notices
 | 
			
		||||
 | 
			
		||||
The identification of IP Phone hansets and Wireless APs is now configurable,
 | 
			
		||||
using the CDP/LLDP information from the device. See
 | 
			
		||||
L<documentation|App::Netdisco::Manual::Configuration> for:
 | 
			
		||||
 | 
			
		||||
 phone_capabilities
 | 
			
		||||
 phone_platforms
 | 
			
		||||
 wap_capabilities
 | 
			
		||||
 wap_platforms
 | 
			
		||||
 | 
			
		||||
=head1 2.031006
 | 
			
		||||
 | 
			
		||||
=head2 General Notices
 | 
			
		||||
 
 | 
			
		||||
@@ -48,6 +48,7 @@ stored to the database.
 | 
			
		||||
 | 
			
		||||
sub get_device {
 | 
			
		||||
  my $ip = shift;
 | 
			
		||||
  return unless $ip;
 | 
			
		||||
 | 
			
		||||
  # naive check for existing DBIC object
 | 
			
		||||
  return $ip if ref $ip;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user