]> git.proxmox.com Git - pve-manager.git/blob - PVE/Report.pm
report: add packet counter to iptables output
[pve-manager.git] / PVE / Report.pm
1 package PVE::Report;
2
3 use strict;
4 use warnings;
5
6 use PVE::Tools;
7
8 # output the content of all the files of a directory
9 my sub dir2text {
10 my ($target_dir, $regexp) = @_;
11
12 print STDERR "dir2text '${target_dir}${regexp}'...";
13 my $text = "# output '${target_dir}${regexp}' file(s)\n";
14 PVE::Tools::dir_glob_foreach($target_dir, $regexp, sub {
15 my ($file) = @_;
16 return if $file eq '.' || $file eq '..';
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 }
25
26 my $init_report_cmds = sub {
27 my $report_def = {
28 general => {
29 title => 'general system info',
30 order => 10,
31 cmds => [
32 'hostname',
33 'date -R',
34 'pveversion --verbose',
35 'cat /etc/hosts',
36 'pvesubscription get',
37 'cat /etc/apt/sources.list',
38 sub { dir2text('/etc/apt/sources.list.d/', '.*list') },
39 sub { dir2text('/etc/apt/sources.list.d/', '.*sources') },
40 'lscpu',
41 'pvesh get /cluster/resources --type node --output-format=yaml',
42 ],
43 },
44 'system-load' => {
45 title => 'overall system load info',
46 order => 20,
47 cmds => [
48 'top -b -c -w512 -n 1 -o TIME | head -n 30',
49 'head /proc/pressure/*',
50 ],
51 },
52 storage => {
53 order => 30,
54 cmds => [
55 'cat /etc/pve/storage.cfg',
56 'pvesm status',
57 'cat /etc/fstab',
58 'findmnt --ascii',
59 'df --human -T',
60 'proxmox-boot-tool status',
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 => {
73 order => 45,
74 cmds => [
75 'ip -details -statistics address',
76 'ip -details -4 route show',
77 'ip -details -6 route show',
78 'cat /etc/network/interfaces',
79 sub { dir2text('/etc/network/interfaces.d/', '.*') },
80 sub { dir2text('/etc/pve/sdn/', '.*') },
81 ],
82 },
83 firewall => {
84 order => 50,
85 cmds => [
86 sub { dir2text('/etc/pve/firewall/', '.*fw') },
87 'cat /etc/pve/local/host.fw',
88 'iptables-save -c',
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',
98 'cat /etc/pve/datacenter.cfg',
99 ],
100 },
101 hardware => {
102 order => 70,
103 cmds => [
104 'dmidecode -t bios',
105 'lspci -nnk',
106 ],
107 },
108 'block devices' => {
109 order => 80,
110 cmds => [
111 'lsblk --ascii -M -o +HOTPLUG,ROTA,PHY-SEC,FSTYPE,MODEL,TRAN',
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 },
125 };
126
127 if (cmd_exists('zfs')) {
128 push @{$report_def->{volumes}->{cmds}},
129 'zpool status',
130 'zpool list -v',
131 'zfs list',
132 'arcstat',
133 ;
134 }
135
136 if (-e '/etc/ceph/ceph.conf') {
137 push @{$report_def->{volumes}->{cmds}},
138 'pveceph status',
139 'ceph osd status',
140 'ceph df',
141 'ceph osd df tree',
142 'ceph device ls',
143 'cat /etc/ceph/ceph.conf',
144 'ceph config dump',
145 'pveceph pool ls',
146 'ceph versions',
147 'ceph health detail',
148 ;
149 }
150
151 if (cmd_exists('multipath')) {
152 push @{$report_def->{disks}->{cmds}},
153 'cat /etc/multipath.conf',
154 'cat /etc/multipath/wwids',
155 'multipath -ll',
156 ;
157 }
158
159 return $report_def;
160 };
161
162 sub generate {
163 my $def = $init_report_cmds->();
164
165 my $report = '';
166 my $record_output = sub {
167 $report .= shift . "\n";
168 };
169
170 local $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
171 my $cmd_timeout = 10; # generous timeout
172
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
180 my $sorter = sub { ($def->{$_[0]}->{order} // 1<<30) <=> ($def->{$_[1]}->{order} // 1<<30) };
181
182 for my $section ( sort { $sorter->($a, $b) } keys %$def) {
183 my $s = $def->{$section};
184 my $title = $s->{title} // "info about $section";
185
186 $report .= "\n==== $title ====\n";
187 for my $command (@{$s->{cmds}}) {
188 eval {
189 if (ref $command eq 'CODE') {
190 $report .= PVE::Tools::run_with_timeout($cmd_timeout, $command);
191 } else {
192 print STDERR "Process ".$command."...";
193 $report .= "\n# $command\n";
194 PVE::Tools::run_command($command, %$run_cmd_params);
195 }
196 print STDERR "OK";
197 };
198 print STDERR "\n";
199 $report .= "\nERROR: $@\n" if $@;
200 }
201 }
202
203 return $report;
204 }
205
206 1;