diff options
author | Petter Reinholdtsen <pere@hungry.com> | 2008-07-25 16:55:19 +0000 |
---|---|---|
committer | Petter Reinholdtsen <pere@hungry.com> | 2008-07-25 16:55:19 +0000 |
commit | 46c7af2ac216bfce7c55347ee2ecea3d391abfa7 (patch) | |
tree | 1c8aaa47c18b94aca3e85de4042f73588f7c3745 | |
parent | d723b5e7158455a0628df8c6f19ec098f02447cd (diff) | |
download | sitesummary-46c7af2ac216bfce7c55347ee2ecea3d391abfa7.tar.gz sitesummary-46c7af2ac216bfce7c55347ee2ecea3d391abfa7.tar.bz2 sitesummary-46c7af2ac216bfce7c55347ee2ecea3d391abfa7.tar.xz |
* Add new statistics script hardware-models to list the different
hardware vendor and models.
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | SiteSummary.pm | 32 | ||||
-rw-r--r-- | debian/changelog | 7 | ||||
-rwxr-xr-x | hardware-models | 78 |
4 files changed, 118 insertions, 0 deletions
@@ -23,6 +23,7 @@ COLLECTORS = \ SUMMARYSCRIPTS = \ agesinceseen-summary \ site-summary \ + hardware-models \ hostclass-summary \ kernelversion-summary \ debian_edu-summary diff --git a/SiteSummary.pm b/SiteSummary.pm index f5a1db4..033956b 100644 --- a/SiteSummary.pm +++ b/SiteSummary.pm @@ -19,6 +19,7 @@ our @EXPORT = qw( get_linux_kernel_ver get_debian_edu_profile get_debian_edu_ver + get_hardware_info ); my $pwd = "/var/lib/sitesummary/entries"; # Path to the entries @@ -207,6 +208,37 @@ sub get_debian_edu_ver { } } +sub get_hardware_info { + my $hostid = shift; + my $path = get_filepath_current($hostid, "/system/dmidecode"); + if (open(FILE, "<", $path)) { + my $sysinfo = 0; + my ($vendor, $model, $version, $serial); + while (<FILE>) { + chomp; + next unless ($sysinfo || m/^System Information/); + $sysinfo = 1; + $vendor = $1 if (m/Manufacturer: (.+\S)\s*$/); + $model = $1 if (m/Product Name: (.+\S)\s*$/); + $version = $1 if (m/Version: (.+\S)\s*$/); + $serial = $1 if (m/Serial Number: (.+\S)\s*$/); + last if (m/^Handle /); + } + close(FILE); + + # Append version string to get for example the thinkpad model + # name, but ignore bogus entries. + $model = "$model $version" if ($version + && $version ne "Not Specified" + && $version ne "Not Available" + && $version ne "None"); + + return ($vendor, $model, $serial); + } else { + return undef; + } +} + sub for_all_hosts { my $callback = shift; diff --git a/debian/changelog b/debian/changelog index 03a6796..579803d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +sitesummary (0.0.45) UNRELEASED; urgency=low + + * Add new statistics script hardware-models to list the different + hardware vendor and models. + + -- Petter Reinholdtsen <pere@debian.org> Fri, 25 Jul 2008 00:50:51 +0200 + sitesummary (0.0.44) unstable; urgency=low * Undo fix for slow propagation of information on first time install, diff --git a/hardware-models b/hardware-models new file mode 100755 index 0000000..3cb857d --- /dev/null +++ b/hardware-models @@ -0,0 +1,78 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use SiteSummary; +use Getopt::Std; + +my %vendors; +my %models; +my %hostmap; +my %modelmap; +my %opts; + +sub usage { + my $retval = shift; + print <<EOF; +Usage: $0 [-l] + -l list hosts with the given vendor/model +EOF + exit $retval; +} + +getopt("l", \%opts) || usage(1); + +for_all_hosts(\&handle_host); + +print_summary(); + +sub handle_host { + my $hostid = shift; + #print "$hostid\n"; + my ($vendor, $model, undef) = get_hardware_info($hostid); + $vendor = "[unknown]" unless defined $vendor; + $vendors{$vendor}++; + if ($model) { + $models{$vendor}{$model}++; + if (exists $modelmap{$vendor} && exists $modelmap{$vendor}{$model}) { + push @{$modelmap{$vendor}{$model}}, $hostid ; + } else { + $modelmap{$vendor}{$model} = [$hostid]; + } + } else { + if (exists $hostmap{$vendor}) { + push @{$hostmap{$vendor}}, $hostid ; + } else { + $hostmap{$vendor} = [$hostid]; + } + } +} + +sub print_summary { + printf(" %-25s %5s\n", "vendor", "count"); + for my $vendor (sort keys %vendors) { + printf(" %-25s %5d\n", $vendor, $vendors{$vendor}); + if (exists $opts{l}) { + if (exists $hostmap{$vendor}) { + for my $hostid (sort @{$hostmap{$vendor}}) { + my $hostname = get_hostname($hostid); + my ($vendor, $model, undef) = get_hardware_info($hostid); + $vendor = "[unknown]" unless defined $vendor; + $model = "" unless defined $model; + printf " %s %s/%s %s\n", $hostname, $vendor, $model, $hostid; + } + } + for my $model (sort keys %{$models{$vendor}}) { + printf(" %-23s %5d\n", $model, $models{$vendor}{$model}); + if (exists $opts{l}) { + for my $hostid (sort @{$modelmap{$vendor}{$model}}) { + my $hostname = get_hostname($hostid); + my ($vendor, $model, undef) = get_hardware_info($hostid); + printf " %s %s/%s %s\n", $hostname, $vendor, $model, $hostid; + } + } + } + } + } +} |