]>
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}'..."; |
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' | |
24 | my sub cmd_exists { system("command -v '$_[0]' > /dev/null 2>&1") == 0 } | |
ee3a8989 | 25 | |
01c8f6fe | 26 | my $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 SI |
38 | 'cat /etc/apt/sources.list', |
39 | sub { dir2text('/etc/apt/sources.list.d/', '.*list') }, | |
8672c64e | 40 | sub { dir2text('/etc/apt/sources.list.d/', '.*sources') }, |
01c8f6fe TL |
41 | 'lscpu', |
42 | 'pvesh get /cluster/resources --type node --output-format=yaml', | |
43 | ], | |
44 | }, | |
8b94e6bb TL |
45 | 'system-load' => { |
46 | title => 'overall system load info', | |
47 | order => 20, | |
48 | cmds => [ | |
cdb63825 | 49 | 'top -b -c -w512 -n 1 -o TIME | head -n 30', |
8b94e6bb TL |
50 | 'head /proc/pressure/*', |
51 | ], | |
52 | }, | |
f784b925 TL |
53 | storage => { |
54 | order => 30, | |
55 | cmds => [ | |
56 | 'cat /etc/pve/storage.cfg', | |
57 | 'pvesm status', | |
58 | 'cat /etc/fstab', | |
59 | 'findmnt --ascii', | |
80e456f6 | 60 | 'df --human -T', |
ef09450c | 61 | 'proxmox-boot-tool status', |
f784b925 TL |
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 => { | |
c5b25c00 | 74 | order => 45, |
f784b925 TL |
75 | cmds => [ |
76 | 'ip -details -statistics address', | |
77 | 'ip -details -4 route show', | |
78 | 'ip -details -6 route show', | |
79 | 'cat /etc/network/interfaces', | |
b2b516f3 | 80 | sub { dir2text('/etc/network/interfaces.d/', '.*') }, |
e5ecadec | 81 | sub { dir2text('/etc/pve/sdn/', '.*') }, |
f784b925 TL |
82 | ], |
83 | }, | |
84 | firewall => { | |
85 | order => 50, | |
86 | cmds => [ | |
87 | sub { dir2text('/etc/pve/firewall/', '.*fw') }, | |
88 | 'cat /etc/pve/local/host.fw', | |
dd9ee03b | 89 | 'iptables-save -c | column -t -l4 -o" "', |
f784b925 TL |
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', | |
0fb89b4a | 99 | 'cat /etc/pve/datacenter.cfg', |
f784b925 TL |
100 | ], |
101 | }, | |
8b94e6bb | 102 | hardware => { |
f784b925 TL |
103 | order => 70, |
104 | cmds => [ | |
105 | 'dmidecode -t bios', | |
f784b925 TL |
106 | 'lspci -nnk', |
107 | ], | |
108 | }, | |
8b94e6bb | 109 | 'block devices' => { |
f784b925 TL |
110 | order => 80, |
111 | cmds => [ | |
c4c3ed73 | 112 | 'lsblk --ascii -M -o +HOTPLUG,ROTA,PHY-SEC,FSTYPE,MODEL,TRAN', |
f784b925 TL |
113 | 'ls -l /dev/disk/by-*/', |
114 | 'iscsiadm -m node', | |
115 | 'iscsiadm -m session', | |
116 | ], | |
117 | }, | |
118 | volumes => { | |
119 | order => 90, | |
120 | cmds => [ | |
121 | 'pvs', | |
122 | 'lvs', | |
123 | 'vgs', | |
124 | ], | |
125 | }, | |
01c8f6fe | 126 | }; |
1cf7db21 | 127 | |
fb925d65 | 128 | if (cmd_exists('zfs')) { |
f784b925 | 129 | push @{$report_def->{volumes}->{cmds}}, |
fb925d65 TL |
130 | 'zpool status', |
131 | 'zpool list -v', | |
132 | 'zfs list', | |
c46eb47e | 133 | 'arcstat', |
fb925d65 TL |
134 | ; |
135 | } | |
1cf7db21 | 136 | |
01c8f6fe | 137 | if (-e '/etc/ceph/ceph.conf') { |
f784b925 | 138 | push @{$report_def->{volumes}->{cmds}}, |
c83c3d45 TL |
139 | 'pveceph status', |
140 | 'ceph osd status', | |
141 | 'ceph df', | |
142 | 'ceph osd df tree', | |
ea4d55c9 | 143 | 'ceph device ls', |
c83c3d45 TL |
144 | 'cat /etc/ceph/ceph.conf', |
145 | 'ceph config dump', | |
146 | 'pveceph pool ls', | |
147 | 'ceph versions', | |
c1eef1f4 | 148 | 'ceph health detail', |
c83c3d45 | 149 | ; |
01c8f6fe | 150 | } |
2f7faeed | 151 | |
1226cd97 | 152 | if (cmd_exists('multipath')) { |
f784b925 | 153 | push @{$report_def->{disks}->{cmds}}, |
1226cd97 ML |
154 | 'cat /etc/multipath.conf', |
155 | 'cat /etc/multipath/wwids', | |
fb925d65 TL |
156 | 'multipath -ll', |
157 | ; | |
1226cd97 | 158 | } |
2f7faeed | 159 | |
01c8f6fe TL |
160 | return $report_def; |
161 | }; | |
2f7faeed | 162 | |
2f7faeed | 163 | sub generate { |
f784b925 | 164 | my $def = $init_report_cmds->(); |
01c8f6fe | 165 | |
3a0b2c40 | 166 | my $report = ''; |
ee3a8989 TL |
167 | my $record_output = sub { |
168 | $report .= shift . "\n"; | |
169 | }; | |
170 | ||
73cdcc98 TL |
171 | local $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin'; |
172 | my $cmd_timeout = 10; # generous timeout | |
173 | ||
ee3a8989 TL |
174 | my $run_cmd_params = { |
175 | outfunc => $record_output, | |
176 | errfunc => $record_output, | |
177 | timeout => $cmd_timeout, | |
178 | noerr => 1, # avoid checking programs exit code | |
179 | }; | |
180 | ||
f784b925 | 181 | my $sorter = sub { ($def->{$_[0]}->{order} // 1<<30) <=> ($def->{$_[1]}->{order} // 1<<30) }; |
2c4ef55e | 182 | |
f784b925 TL |
183 | for my $section ( sort { $sorter->($a, $b) } keys %$def) { |
184 | my $s = $def->{$section}; | |
185 | my $title = $s->{title} // "info about $section"; | |
2f7faeed EK |
186 | |
187 | $report .= "\n==== $title ====\n"; | |
f784b925 | 188 | for my $command (@{$s->{cmds}}) { |
ee3a8989 TL |
189 | eval { |
190 | if (ref $command eq 'CODE') { | |
3a0b2c40 | 191 | $report .= PVE::Tools::run_with_timeout($cmd_timeout, $command); |
ee3a8989 | 192 | } else { |
01c8f6fe | 193 | print STDERR "Process ".$command."..."; |
ee3a8989 TL |
194 | $report .= "\n# $command\n"; |
195 | PVE::Tools::run_command($command, %$run_cmd_params); | |
196 | } | |
2bdf85f8 | 197 | print STDERR "OK"; |
ee3a8989 | 198 | }; |
2bdf85f8 | 199 | print STDERR "\n"; |
ee3a8989 | 200 | $report .= "\nERROR: $@\n" if $@; |
2f7faeed EK |
201 | } |
202 | } | |
ee3a8989 TL |
203 | |
204 | return $report; | |
2f7faeed | 205 | } |
2c4ef55e TL |
206 | |
207 | 1; |