App-Netdisco

 view release on metacpan or  search on metacpan

lib/App/Netdisco/DB/Result/DevicePort.pm  view on Meta::CPAN

Returns the C<oui> table entry matching this Port. You can then join on this
relation and retrieve the Company name from the related table.

The JOIN is of type LEFT, in case the OUI table has not been populated.

=cut

__PACKAGE__->belongs_to( oui => 'App::Netdisco::DB::Result::Oui',
  sub {
      my $args = shift;
      return {
          "$args->{foreign_alias}.oui" =>
            { '=' => \"substring(cast($args->{self_alias}.mac as varchar) for 8)" }
      };
  },
  { join_type => 'LEFT' }
);

=head2 manufacturer

Returns the C<manufacturer> table entry matching this Port. You can then join on this
relation and retrieve the Company name from the related table.

The JOIN is of type LEFT, in case the Manufacturer table has not been populated.

=cut

__PACKAGE__->belongs_to( manufacturer => 'App::Netdisco::DB::Result::Manufacturer',
  sub {
      my $args = shift;
      return {
        "$args->{foreign_alias}.range" => { '@>' =>
          \qq{('x' || lpad( translate( $args->{self_alias}.mac ::text, ':', ''), 16, '0')) ::bit(64) ::bigint} },
      };
  },
  { join_type => 'LEFT' }
);

=head1 ADDITIONAL METHODS

=head2 neighbor

Returns the Device entry for the neighbour Device on the given port.

Might return an undefined value if there is no neighbor on the port, or if the
neighbor has not been fully discovered by Netdisco and so does not exist in
the database.

=cut

sub neighbor {
    my $row = shift;
    return eval { $row->neighbor_alias->device || undef };
}

=head1 ADDITIONAL COLUMNS

=head2 native

An alias for the C<vlan> column, which stores the PVID (that is, the VLAN
ID assigned to untagged frames received on the port).

=cut

sub native { return (shift)->vlan }

=head2 error_disable_cause

Returns the textual reason given by the device if the port is in an error
state, or else `undef` if the port is not in an error state.

=cut

sub error_disable_cause { return (shift)->get_column('error_disable_cause') }

=head2 remote_is_discoverable

Returns true if Netdisco is permitted to discover the remote device with
the configuration of the local poller doing the local device discovery.

=cut

sub remote_is_discoverable { return (shift)->get_column('remote_is_discoverable') }

=head2 remote_is_wap

Returns true if the remote LLDP neighbor has reported Wireless Access Point
capability.

=cut

sub remote_is_wap { return (shift)->get_column('remote_is_wap') }

=head2 remote_is_phone

Returns true if the remote LLDP neighbor has reported Telephone capability.

=cut

sub remote_is_phone { return (shift)->get_column('remote_is_phone') }

=head2 ifindex

Returns the interface index (C<ifIndex>) of the port.

=cut

sub ifindex { return (shift)->get_column('ifindex') }

=head2 pae_authsess_user

Returns the pae_authsess_user of the port.

=cut

sub pae_authsess_user { return (shift)->get_column('pae_authsess_user') }

=head2 pae_authsess_user_net_mac

Returns the pae_authsess_user of the port as a NetAddr::MAC instance.

=cut

sub pae_authsess_user_net_mac { return NetAddr::MAC->new(mac => ((shift)->pae_authsess_user || '')) }

=head2 pae_authconfig_port_control

Returns the pae_authconfig_port_control of the port.

=cut

sub pae_authconfig_port_control { return (shift)->get_column('pae_authconfig_port_control') }

=head2 pae_authconfig_state

Returns the pae_authconfig_state of the port.

=cut

sub pae_authconfig_state { return (shift)->get_column('pae_authconfig_state') }

=head2 pae_authconfig_port_status

Returns the pae_authconfig_port_status of the port.

=cut

sub pae_authconfig_port_status { return (shift)->get_column('pae_authconfig_port_status') }

=head2 pae_authsess_mab

Returns the pae_authsess_mab of the port.

=cut

sub pae_authsess_mab { return (shift)->get_column('pae_authsess_mab') }

=head2 pae_last_eapol_frame_source

Returns the pae_last_eapol_frame_source of the port.

=cut

sub pae_last_eapol_frame_source { return (shift)->get_column('pae_last_eapol_frame_source') }

=head2 remote_dns

Returns a hostname resolved from C<remote_ip> column.

=cut

sub remote_dns { return (shift)->get_column('remote_dns') }

=head2 remote_inventory

Returns a synthesized description of the remote LLDP device if inventory
information was given, including vendor, model, OS version, and serial number.

=cut

sub remote_inventory {
  my $port = shift;
  my $os_ver = ($port->get_column('remote_os_ver')
    ? ('running '. $port->get_column('remote_os_ver')) : '');
  my $serial = ($port->get_column('remote_serial')
    ? ('('. $port->get_column('remote_serial') .')') : '');

  my $retval = join ' ', ($port->get_column('remote_vendor') || ''),
    ($port->get_column('remote_model') || ''), $serial, $os_ver;

  return (($retval =~ m/[[:alnum:]]/) ? $retval : '');
}

=head2 vlan_count

Returns the number of VLANs active on this device port. Enable this column by
applying the C<with_vlan_count()> modifier to C<search()>.

=cut

sub vlan_count { return (shift)->get_column('vlan_count') }

=head2 lastchange_stamp

Formatted version of the C<lastchange> field, accurate to the minute. Enable
this column by applying the C<with_times()> modifier to C<search()>.

The format is somewhat like ISO 8601 or RFC3339 but without the middle C<T>
between the date stamp and time stamp. That is:

 2012-02-06 12:49

=cut

sub lastchange_stamp { return (shift)->get_column('lastchange_stamp') }

=head2 is_free

This method can be used to evaluate whether a device port could be considered
unused, based on the last time it changed from the "up" state to a "down"
state.

See the C<with_is_free> and C<only_free_ports> modifiers to C<search()>.



( run in 1.210 second using v1.01-cache-2.11-cpan-e1769b4cff6 )