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