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