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