<& SELF:matches &>

Device Module Search

Hints

<%args> @classes => () $ip => '' $text => '' $dns => '' $mname => '' $desc => '' $type => '' $model => '' $serial => '' $boolean => 'and' $exact => 0 <%shared> my $matches = undef; my $where = {}; my $arg_exact; my $winsize = 5; # max size for select boxes. my $title = 'Search Results'; # Search Result Title <%init> my $classes = sql_column('device_module',['distinct(class)', 'true']); $arg_exact = $exact; # Search on all text fields if (length($text)) { my $match = sql_match($text,0); push(@{$where->{'d.ip/i.alias'}}, $match); push(@{$where->{'d.dns/i.dns'}}, $match); push(@{$where->{'dm.name'}}, $match); push(@{$where->{'dm.description'}}, $match); push(@{$where->{'dm.type'}}, $match); push(@{$where->{'dm.serial'}}, $match); push(@{$where->{'dm.model'}}, $match); push(@{$where->{'dm.class'}}, $match); $boolean = 'or'; } # Generalized Search Terms # Search on Class foreach my $class (@classes){ next unless defined $class and length($class); push (@{$where->{'dm.class'}},$class); } # Search on Description if (length($desc)){ my $match = sql_match($desc,$exact); push(@{$where->{'dm.description'}}, $match); } # Search on Name if (length($mname)){ my $match = sql_match($mname,$exact); push(@{$where->{'dm.name'}}, $match); } # Search on Type if (length($type)){ my $match = sql_match($type,$exact); push(@{$where->{'dm.type'}}, $match); } # Search on Model if (length($model)){ my $match = sql_match($model,$exact); push(@{$where->{'dm.model'}}, $match); } # Search on DNS entry if (length($dns)){ my $match = sql_match($dns,$exact); push(@{$where->{'d.dns/i.dns'}}, $match); } # Search on Serial if (length($serial)){ my $match = sql_match($serial,$exact); push(@{$where->{'dm.serial'}}, $match); } # Search on IP if (length($ip)){ my $match = sql_match($ip,$exact); push(@{$where->{'d.ip/i.alias'}}, $match); } # Run Query if (scalar keys %$where){ $matches = sql_rows('device d left join device_ip i on d.ip = i.ip join device_module dm on dm.ip = d.ip', ['distinct(d.ip)','d.dns','dm.description', 'dm.name', 'dm.type', 'dm.hw_ver', 'dm.fw_ver', 'dm.sw_ver', 'dm.serial', 'dm.model'], $where, $boolean eq 'or'); } %# %# matches() - Display search results stored in @$matches. %# <%method matches > %return unless defined $matches;

<%$title%>

% unless (scalar @$matches) { No Results Found. % return; % } <%perl> my $count=0; my @sort_matches = sort {$a->{dns} cmp $b->{dns}} @$matches; foreach my $result (@sort_matches){ my $ip = $result->{ip}; my $dns = $result->{dns}; $dns = defined $dns ? $dns : $ip; $dns =~ s/\Q$netdisco::CONFIG{domain}\E//; % $count++; }
Device Description Name Type Model Serial HW
Version
SW
Version
FW
Version
<% $dns %> <%$result->{description}%> <%$result->{name}%> <%$result->{type}%> <%$result->{model}%> <%$result->{serial}%> <%$result->{hw_ver}%> <%$result->{sw_ver}%> <%$result->{fw_ver}%>
<% $count %> matches. %# %# title() %# <%method title> - Device Module Search\ %# $Id$ %# vim:syntax=mason