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