| 1 | use utf8; | ||
| 2 | package App::Netdisco::DB::Result::NodeWireless; | ||
| 3 | |||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | |||
| 8 | use NetAddr::MAC; | ||
| 9 | |||
| 10 | use base 'App::Netdisco::DB::Result'; | ||
| 11 | __PACKAGE__->table("node_wireless"); | ||
| 12 | __PACKAGE__->add_columns( | ||
| 13 | "mac", | ||
| 14 | { data_type => "macaddr", is_nullable => 0 }, | ||
| 15 | "uptime", | ||
| 16 | { data_type => "integer", is_nullable => 1 }, | ||
| 17 | "maxrate", | ||
| 18 | { data_type => "integer", is_nullable => 1 }, | ||
| 19 | "txrate", | ||
| 20 | { data_type => "integer", is_nullable => 1 }, | ||
| 21 | "sigstrength", | ||
| 22 | { data_type => "integer", is_nullable => 1 }, | ||
| 23 | "sigqual", | ||
| 24 | { data_type => "integer", is_nullable => 1 }, | ||
| 25 | "rxpkt", | ||
| 26 | { data_type => "bigint", is_nullable => 1 }, | ||
| 27 | "txpkt", | ||
| 28 | { data_type => "bigint", is_nullable => 1 }, | ||
| 29 | "rxbyte", | ||
| 30 | { data_type => "bigint", is_nullable => 1 }, | ||
| 31 | "txbyte", | ||
| 32 | { data_type => "bigint", is_nullable => 1 }, | ||
| 33 | "time_last", | ||
| 34 | { | ||
| 35 | data_type => "timestamp", | ||
| 36 | default_value => \"LOCALTIMESTAMP", | ||
| 37 | is_nullable => 1, | ||
| 38 | original => { default_value => \"LOCALTIMESTAMP" }, | ||
| 39 | }, | ||
| 40 | "ssid", | ||
| 41 | { data_type => "text", is_nullable => 0, default_value => '' }, | ||
| 42 | ); | ||
| 43 | __PACKAGE__->set_primary_key("mac", "ssid"); | ||
| 44 | |||
| 45 | |||
| 46 | |||
| 47 | =head1 RELATIONSHIPS | ||
| 48 | |||
| 49 | =head2 oui | ||
| 50 | |||
| 51 | DEPRECATED: USE MANUFACTURER INSTEAD | ||
| 52 | |||
| 53 | Returns the C<oui> table entry matching this Node. You can then join on this | ||
| 54 | relation and retrieve the Company name from the related table. | ||
| 55 | |||
| 56 | The JOIN is of type LEFT, in case the OUI table has not been populated. | ||
| 57 | |||
| 58 | =cut | ||
| 59 | |||
| 60 | __PACKAGE__->belongs_to( oui => 'App::Netdisco::DB::Result::Oui', | ||
| 61 | sub { | ||
| 62 | my $args = shift; | ||
| 63 | return { | ||
| 64 | "$args->{foreign_alias}.oui" => | ||
| 65 | { '=' => \"substring(cast($args->{self_alias}.mac as varchar) for 8)" } | ||
| 66 | }; | ||
| 67 | }, | ||
| 68 | { join_type => 'LEFT' } | ||
| 69 | ); | ||
| 70 | |||
| 71 | =head2 manufacturer | ||
| 72 | |||
| 73 | Returns the C<manufacturer> table entry matching this Node. You can then join on this | ||
| 74 | relation and retrieve the Company name from the related table. | ||
| 75 | |||
| 76 | The JOIN is of type LEFT, in case the Manufacturer table has not been populated. | ||
| 77 | |||
| 78 | =cut | ||
| 79 | |||
| 80 | __PACKAGE__->belongs_to( manufacturer => 'App::Netdisco::DB::Result::Manufacturer', | ||
| 81 | sub { | ||
| 82 | my $args = shift; | ||
| 83 | return { | ||
| 84 | "$args->{foreign_alias}.range" => { '@>' => | ||
| 85 | \qq{('x' || lpad( translate( $args->{self_alias}.mac ::text, ':', ''), 16, '0')) ::bit(64) ::bigint} }, | ||
| 86 | }; | ||
| 87 | }, | ||
| 88 | { join_type => 'LEFT' } | ||
| 89 | ); | ||
| 90 | |||
| 91 | =head2 node | ||
| 92 | |||
| 93 | Returns the C<node> table entry matching this wireless entry. | ||
| 94 | |||
| 95 | The JOIN is of type LEFT, in case the C<node> is no longer present in the | ||
| 96 | database but the relation is being used in C<search()>. | ||
| 97 | |||
| 98 | =cut | ||
| 99 | |||
| 100 | __PACKAGE__->belongs_to( node => 'App::Netdisco::DB::Result::Node', | ||
| 101 | { 'foreign.mac' => 'self.mac' }, | ||
| 102 | { join_type => 'LEFT' } ); | ||
| 103 | |||
| 104 | =head1 ADDITIONAL COLUMNS | ||
| 105 | |||
| 106 | =head2 net_mac | ||
| 107 | |||
| 108 | Returns the C<mac> column instantiated into a L<NetAddr::MAC> object. | ||
| 109 | |||
| 110 | =cut | ||
| 111 | |||
| 112 | sub net_mac { return NetAddr::MAC->new(mac => ((shift)->mac || '')) } | ||
| 113 | |||
| 114 | 1; |