]> git.proxmox.com Git - pve-manager.git/blame - PVE/Report.pm
report: create "jobs" section, add `jobs.cfg`
[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
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 },
a26e547e
AZ
102 jobs => {
103 order => 65,
104 cmds => [
105 'cat /etc/pve/jobs.cfg',
106 ],
107 },
8b94e6bb 108 hardware => {
f784b925
TL
109 order => 70,
110 cmds => [
111 'dmidecode -t bios',
f784b925
TL
112 'lspci -nnk',
113 ],
114 },
8b94e6bb 115 'block devices' => {
f784b925
TL
116 order => 80,
117 cmds => [
c4c3ed73 118 'lsblk --ascii -M -o +HOTPLUG,ROTA,PHY-SEC,FSTYPE,MODEL,TRAN',
f784b925
TL
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 },
01c8f6fe 132 };
1cf7db21 133
fb925d65 134 if (cmd_exists('zfs')) {
f784b925 135 push @{$report_def->{volumes}->{cmds}},
fb925d65
TL
136 'zpool status',
137 'zpool list -v',
138 'zfs list',
c46eb47e 139 'arcstat',
fb925d65
TL
140 ;
141 }
1cf7db21 142
01c8f6fe 143 if (-e '/etc/ceph/ceph.conf') {
f784b925 144 push @{$report_def->{volumes}->{cmds}},
c83c3d45
TL
145 'pveceph status',
146 'ceph osd status',
147 'ceph df',
148 'ceph osd df tree',
ea4d55c9 149 'ceph device ls',
c83c3d45
TL
150 'cat /etc/ceph/ceph.conf',
151 'ceph config dump',
152 'pveceph pool ls',
153 'ceph versions',
c1eef1f4 154 'ceph health detail',
c83c3d45 155 ;
01c8f6fe 156 }
2f7faeed 157
1226cd97 158 if (cmd_exists('multipath')) {
f784b925 159 push @{$report_def->{disks}->{cmds}},
1226cd97
ML
160 'cat /etc/multipath.conf',
161 'cat /etc/multipath/wwids',
fb925d65
TL
162 'multipath -ll',
163 ;
1226cd97 164 }
2f7faeed 165
01c8f6fe
TL
166 return $report_def;
167};
2f7faeed 168
2f7faeed 169sub generate {
f784b925 170 my $def = $init_report_cmds->();
01c8f6fe 171
3a0b2c40 172 my $report = '';
ee3a8989
TL
173 my $record_output = sub {
174 $report .= shift . "\n";
175 };
176
73cdcc98
TL
177 local $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
178 my $cmd_timeout = 10; # generous timeout
179
ee3a8989
TL
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
f784b925 187 my $sorter = sub { ($def->{$_[0]}->{order} // 1<<30) <=> ($def->{$_[1]}->{order} // 1<<30) };
2c4ef55e 188
f784b925
TL
189 for my $section ( sort { $sorter->($a, $b) } keys %$def) {
190 my $s = $def->{$section};
191 my $title = $s->{title} // "info about $section";
2f7faeed
EK
192
193 $report .= "\n==== $title ====\n";
f784b925 194 for my $command (@{$s->{cmds}}) {
ee3a8989
TL
195 eval {
196 if (ref $command eq 'CODE') {
3a0b2c40 197 $report .= PVE::Tools::run_with_timeout($cmd_timeout, $command);
ee3a8989 198 } else {
01c8f6fe 199 print STDERR "Process ".$command."...";
ee3a8989
TL
200 $report .= "\n# $command\n";
201 PVE::Tools::run_command($command, %$run_cmd_params);
202 }
2bdf85f8 203 print STDERR "OK";
ee3a8989 204 };
2bdf85f8 205 print STDERR "\n";
ee3a8989 206 $report .= "\nERROR: $@\n" if $@;
2f7faeed
EK
207 }
208 }
ee3a8989
TL
209
210 return $report;
2f7faeed 211}
2c4ef55e
TL
212
2131;