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