Debian Codegraph @

imvirt-report

raw
1 #!/usr/bin/perl
2
3 # imvirt - I'm virtualized?
4 #
5 # Authors:
6 # Thomas Liske <[email protected]>
7 #
8 # Copyright Holder:
9 # 2012 - 2013 (C) IBH IT-Service GmbH [http://www.ibh.de/]
10 #
11 # License:
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
16 #
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this package; if not, write to the Free Software
24 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #
26
27 use strict;
28 use warnings;
29 use Getopt::Std;
30 use MIME::Lite;
31 use ImVirt;
32
33 $|++;
34
35 eval 'use File::Which;';
36 my $nowhich = $@;
37
38
39 my $hostname = `hostname -f`;
40 chomp($hostname);
41
42 $Getopt::Std::STANDARD_HELP_VERSION++;
43
44 sub HELP_MESSAGE {
45 print <<USG;
46 About:
47 imvirt-report collects various system information and saves them to a
48 mime encoded file. It might help the upstream author to provide a better
49 detection support of virtualizing technologies. It might be helpful to
50 attach the output to bug reports.
51
52 Usage:
53 imvirt-report [-s <filename>]
54
55 -s <filename> where to write the collected data
56
57 USG
58 }
59
60 sub VERSION_MESSAGE {
61 print <<LIC;
62 imvirt $ImVirt::VERSION - I'm virtualized?
63
64 Authors:
65 Thomas Liske <liske\@ibh.de>
66
67 Copyright Holder:
68 2008 - 2013 (C) IBH IT-Service GmbH [http://www.ibh.de/]
69
70 License:
71 This program is free software; you can redistribute it and/or modify
72 it under the terms of the GNU General Public License as published by
73 the Free Software Foundation; either version 2 of the License, or
74 (at your option) any later version.
75
76 LIC
77 #'
78 }
79
80 our $opt_s = "imvirt-report_${hostname}_$$.eml";
81 getopts('s:') || exit(1);
82
83 my $ivout = imv_get(IMV_PROB_DEFAULT);
84
85 my $msg = MIME::Lite->new(
86 Subject => $hostname,
87 Type => 'multipart/mixed',
88 );
89
90 $msg->attach(
91 Type => 'TEXT',
92 Data => "Hostname: $hostname\nImVirt Version: $ImVirt::VERSION\nImVirt Output: $ivout\n",
93 );
94
95 sub attach_path($$) {
96 my ($msg, $glob) = @_;
97
98 foreach my $path (glob $glob) {
99 my $fn = $path;
100 $fn =~ s@/@_@g;
101
102 unless (-r $path) {
103 $msg->attach(
104 Type => 'TEXT',
105 Data => "File $path not readable!",
106 Filename => $fn,
107 );
108 }
109 else {
110 print STDERR " Attaching '$path'.\n";
111 $msg->attach(
112 Type => 'TEXT',
113 Path => $path,
114 Filename => $fn,
115 );
116 }
117 }
118 }
119
120 sub attach_cmd($$$) {
121 my ($msg, $cmd, $params) = @_;
122 my $run = ($nowhich ne '' ? $cmd : which($cmd));
123
124 unless (defined($run)) {
125 $msg->attach(
126 Type => 'TEXT',
127 Data => "Command $cmd not available!",
128 Filename => $cmd,
129 );
130
131 return;
132 }
133
134 print STDERR " Attaching `$cmd $params`.\n";
135 $msg->attach(
136 Type => 'TEXT',
137 Data => scalar `$run $params 2>&1`,
138 Filename => $cmd,
139 );
140 }
141
142 print STDERR "Collecting data...\n";
143
144 attach_path($msg, '/proc/1/cgroup');
145 attach_path($msg, '/proc/1/environ');
146 attach_path($msg, '/proc/1/stat');
147 attach_path($msg, '/proc/cmdline');
148 attach_path($msg, '/proc/cpuinfo');
149 attach_path($msg, '/proc/kallsyms');
150 attach_path($msg, '/proc/mounts');
151 attach_path($msg, '/proc/modules');
152 attach_path($msg, '/proc/bus/input/devices');
153 attach_path($msg, '/proc/uptime');
154 attach_path($msg, '/proc/timer_list');
155 attach_path($msg, '/sys/devices/system/clocksource/clocksource*/available_clocksource');
156 attach_path($msg, '/sys/devices/system/cpu/cpu*/cpufreq/scaling_driver');
157 attach_path($msg, '/var/log/dmesg');
158
159 attach_cmd($msg, 'dmesg', '');
160 attach_cmd($msg, 'dmidecode', '');
161 attach_cmd($msg, 'find', '/dev');
162 attach_cmd($msg, 'find', '/proc');
163 attach_cmd($msg, 'find', '/sys');
164 attach_cmd($msg, 'imvirt', '-d');
165 attach_cmd($msg, 'lsb_release', '-a');
166 attach_cmd($msg, 'lspci', '');
167 attach_cmd($msg, 'uname', '-a');
168
169
170 open(HSAVE, '>', $opt_s) || die "Could not open $opt_s: $!\n";
171 $msg->print(\*HSAVE);
172 close(HSAVE);
173
174 print STDERR "Data saved to '$opt_s'.\n";