Device Inventory

[By Age] [By Model] [By OS] [By Location] [Wireless SSID]

By Age

% $m->comp('SELF:show_age') if $cmd eq 'age';
Find Devices
Find Devices
That have been up for at least

By Model

<%perl> $count = 0; $odd = 1; foreach my $row (sort { # Sort by vendor then model return $a->{vendor} cmp $b->{vendor} if $a->{vendor} ne $b->{vendor}; return lc($a->{model}) cmp lc($b->{model}); } @$model_count ) { # Change class if we change vendor if ($old_vendor ne $row->{vendor}){ $odd++; $old_vendor = $row->{vendor}; } $count += $row->{count}; % }
Vendor Model Count
<%$row->{vendor}%> <%$row->{model}%> <%$row->{count}%>
  Total: <%$count%>

By OS

<%perl> $count = 0; foreach my $row (sort { # Sort by OS then Version return $a->{os} cmp $b->{os} if $a->{os} ne $b->{os}; return $a->{os_ver} cmp $b->{os_ver}; } @$os_count ) { if ($old_vendor ne $row->{os}) { $odd++; $old_vendor = $row->{os}; } $count += $row->{count}; % }
OS Version Count
<% $row->{os} || 'Unknown' %> <% $row->{os_ver} || 'Unknown' %> <% $row->{count} %>
  Total: <%$count%>

By Location

% if ($show_loc) { <& SELF:show_loc &> % } else {
% }

Wireless SSID Inventory

% if ($show_ssid) { <& SELF:show_ssid &> % } else {
% } <%args> $cmd => undef $age_type => 'last' $age_val => 2 $age_mul => 'months' $age_bool => 'not in' $show_loc => 0 $show_ssid => 0 <%shared> my $age = []; my $domain = $netdisco::CONFIG{domain}; my $odd = 1; my ($arg_cmd,$arg_age_type,$count,$arg_show_loc); <%init> $arg_cmd = $cmd; $arg_age_type = $age_type; $arg_show_loc = $show_loc; my $old_vendor = ''; my $model_count = sql_rows('device',['vendor','model','count(*)'], undef,undef,'GROUP by model,vendor'); my $os_count = sql_rows('device',['os','os_ver','count(*)'], undef,undef,'GROUP by os,os_ver'); if ($cmd eq 'age'){ # prevent stuffing $age_val = 3 unless $age_val =~ m/^\d+$/; $age_mul =~ s/[^a-z ]+//g; my $bool = '>='; $bool = '<=' if $age_bool =~ /last/; # Default - Last Discovered my $col = 'age(now(),last_discover)'; my $val = "$bool interval '$age_val $age_mul'"; # First Created if ($age_type eq 'first'){ $col = 'age(now(),creation)'; $val = "$bool interval '$age_val $age_mul'"; } # Uptime elsif ($age_type eq 'uptime') { $col = 'uptime'; my $interval = 0; my $mult = 60*60*24; # 1 day in seconds $mult = $mult * 30 if ($age_mul eq 'months'); $mult = $mult * 365 if ($age_mul eq 'years'); $mult *= 100; # uptime is in 100ths of seconds $interval = $age_val * $mult; $val = "$bool $interval" } $age = sql_rows('device',['ip','dns','name','vendor','model','uptime', 'age(now(),creation) as creation_age', 'age(now(),last_discover) as last_discover_age' ], {$col => \\$val} ); } %# %# show_age() - Process by age requests %# <%method show_age>

Results

% unless (scalar @$age) { No Results Found. % return; } <%perl> my @results; if ($arg_age_type eq 'uptime') { @results = sort { $b->{uptime} <=> $a->{uptime} } @$age; } else { @results = sort { return $a->{dns} cmp $b->{dns} unless (! defined($a->{dns}) or ! defined $b->{dns}); return $a->{ip} cmp $b->{ip}; } @$age; } foreach my $dev (@results) { my $dns = $dev->{dns} || 'No DNS'; $dns =~ s/\Q$domain\E//; my $creation_age = $m->comp("SELF:.trim_age", age => $dev->{creation_age}); my $last_discover_age = $m->comp("SELF:.trim_age", age => $dev->{last_discover_age}); my $uptime = $m->comp('device.html:uptime',uptime => $dev->{uptime}); % }
Device IP Vendor - Model <%$arg_age_type eq 'uptime' ? 'Uptime' : 'First
Discovered'%>
Last
Updated
<%$dns%> <%$dev->{ip}%> <%$dev->{vendor}%> - <%$dev->{model}%> <%$arg_age_type eq 'uptime' ? $uptime : $creation_age%> <%$last_discover_age%>
Found <%scalar @$age%> devices. %# %# .trim_age(age=>string) - Trim postgres ugly age string %# <%method .trim_age> <%args> $age => '' <%perl> $age =~ s/mon/month/; if ($age =~ /(day|month|year)/){ $age =~ s/(-)?\d{2}:\d{2}.*$//; } else { $age =~ s/(\d{2}:\d{2}):\d{2}(\.\d*)$/$1/; } return $age; %# %# show_ssid() - Inventory based on SSID %# <%method show_ssid> <%perl> my $ssid_count = sql_rows('device_port_ssid',['ssid','broadcast','count(ssid)'], undef,undef,'group by ssid,broadcast'); $count = 0; $odd = 1; my $old_loc = ''; foreach my $row (sort { $b->{count} <=> $a->{count} } @$ssid_count) { <%perl> }
SSID Broadcast? Count
<%$row->{ssid}|h%> <%$row->{broadcast} ? "Broadcast" : "Stealth"%> <%$row->{count}%>
[Hide] %# %# show_loc() - Sorts and shows by location %# <%method show_loc> <%perl> my $location_count = sql_rows('device',['location','dns','name','ip','vendor','model'], undef,undef,undef); $count = 0; $odd = 1; my $old_loc = ''; foreach my $row (sort { # Sort by Location => Name => IP Address => Vendor => Model return $a->{location} cmp $b->{location} if $a->{location} ne $b->{location}; return $a->{name} cmp $b->{name} if $a->{name} ne $b->{name}; return $a->{ip} cmp $b->{ip} if $a->{ip} ne $b->{ip}; return $a->{vendor} cmp $b->{vendor} if $a->{vendor} ne $b->{vendor}; return $a->{model} cmp $b->{model} if $a->{model} ne $b->{model}; } @$location_count ) { $count += $row->{count}; $odd++ if $row->{location} ne $old_loc; $old_loc = $row->{location}; my $dns = $row->{dns} || $row->{ip}; $dns =~ s/\Q$domain\E//; % }
Location IP Address sysName Vendor Model
<%$row->{location} || '[Not Set]'%> {ip}%> TITLE="Click to View Device"><%$dns|h%> {ip}%> TITLE="Click to View Device"><%$row->{name}|h%> <%$row->{vendor}|h%> <%$row->{model}|h%>
  Total: <%scalar(@$location_count)%>
[Hide] %# %# title() %# <%method title> - Device Inventory \ %# $Id: device_inv.html,v 1.16 2006/06/28 21:32:07 maxbaker Exp $ %# vim:syntax=mason