]> git.proxmox.com Git - pve-manager.git/blob - PVE/Report.pm
report: add multipath.conf and wwids file
[pve-manager.git] / PVE / Report.pm
1 package PVE::Report;
2
3 use strict;
4 use warnings;
5
6 use PVE::Tools;
7
8 $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
9
10 my $cmd_timeout = 10; # generous timeout
11
12 my $init_report_cmds = sub {
13 # NOTE: always add new sections to the report_order array!
14 my $report_def = {
15 general => {
16 title => 'general system info',
17 cmds => [
18 'hostname',
19 'pveversion --verbose',
20 'cat /etc/hosts',
21 'top -b -n 1 | head -n 15',
22 'pvesubscription get',
23 'cat /etc/apt/sources.list',
24 sub { dir2text('/etc/apt/sources.list.d/', '.*list') },
25 sub { dir2text('/etc/apt/sources.list.d/', '.*sources') },
26 'lscpu',
27 'pvesh get /cluster/resources --type node --output-format=yaml',
28 ],
29 },
30 storage => [
31 'cat /etc/pve/storage.cfg',
32 'pvesm status',
33 'cat /etc/fstab',
34 'findmnt --ascii',
35 'df --human',
36 ],
37 'virtual guests' => [
38 'qm list',
39 sub { dir2text('/etc/pve/qemu-server/', '\d.*conf') },
40 'pct list',
41 sub { dir2text('/etc/pve/lxc/', '\d.*conf') },
42 ],
43 network => [
44 'ip -details -statistics address',
45 'ip -details -4 route show',
46 'ip -details -6 route show',
47 'cat /etc/network/interfaces',
48 ],
49 firewall => [
50 sub { dir2text('/etc/pve/firewall/', '.*fw') },
51 'cat /etc/pve/local/host.fw',
52 'iptables-save',
53 ],
54 cluster => [
55 'pvecm nodes',
56 'pvecm status',
57 'cat /etc/pve/corosync.conf 2>/dev/null',
58 'ha-manager status',
59 ],
60 bios => [
61 'dmidecode -t bios',
62 ],
63 pci => [
64 'lspci -nnk',
65 ],
66 disks => [
67 'lsblk --ascii',
68 'ls -l /dev/disk/by-*/',
69 'iscsiadm -m node',
70 'iscsiadm -m session',
71 ],
72 volumes => [
73 'pvs',
74 'lvs',
75 'vgs',
76 ],
77 };
78
79 push @{$report_def->{volumes}}, 'zpool status', 'zpool list -v', 'zfs list'
80 if cmd_exists('zfs');
81
82 if (-e '/etc/ceph/ceph.conf') {
83 push @{$report_def->{volumes}},
84 'pveceph status',
85 'ceph osd status',
86 'ceph df',
87 'ceph osd df tree',
88 'cat /etc/ceph/ceph.conf',
89 'ceph config dump',
90 'pveceph pool ls',
91 'ceph versions',
92 ;
93 }
94
95 if (cmd_exists('multipath')) {
96 push @{$report_def->{disks}},
97 'cat /etc/multipath.conf',
98 'cat /etc/multipath/wwids',
99 'multipath -ll';
100 }
101
102 return $report_def;
103 };
104
105 my $report;
106 # output the content of all the files of a directory
107 sub dir2text {
108 my ($target_dir, $regexp) = @_;
109
110 PVE::Tools::dir_glob_foreach($target_dir, $regexp, sub {
111 my ($file) = @_;
112 $report .= "\n# cat $target_dir$file\n";
113 $report .= PVE::Tools::file_get_contents($target_dir.$file)."\n";
114 });
115 }
116
117 # command -v is the posix equivalent of 'which'
118 sub cmd_exists { system("command -v '$_[0]' > /dev/null 2>&1") == 0 }
119
120 sub generate {
121
122 my $report_def = $init_report_cmds->();
123
124 my @report_order = ('general', 'storage', 'virtual guests', 'network',
125 'firewall', 'cluster', 'bios', 'pci', 'disks', 'volumes');
126
127 $report = '';
128 my $record_output = sub {
129 $report .= shift . "\n";
130 };
131
132 my $run_cmd_params = {
133 outfunc => $record_output,
134 errfunc => $record_output,
135 timeout => $cmd_timeout,
136 noerr => 1, # avoid checking programs exit code
137 };
138
139 foreach my $section (@report_order) {
140 my $s = $report_def->{$section};
141
142 my $title = "info about $section";
143 my $commands = $s;
144
145 if (ref($s) eq 'HASH') {
146 $commands = $s->{cmds};
147 $title = $s->{title} if defined($s->{title});
148 } elsif (ref($s) ne 'ARRAY') {
149 die "unknown report definition in section '$section'!";
150 }
151
152 $report .= "\n==== $title ====\n";
153 foreach my $command (@$commands) {
154 eval {
155 if (ref $command eq 'CODE') {
156 PVE::Tools::run_with_timeout($cmd_timeout, $command);
157 } else {
158 print STDERR "Process ".$command."...";
159 $report .= "\n# $command\n";
160 PVE::Tools::run_command($command, %$run_cmd_params);
161 }
162 print STDERR "OK";
163 };
164 print STDERR "\n";
165 $report .= "\nERROR: $@\n" if $@;
166 }
167 }
168
169 return $report;
170 }
171
172 1;