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