]> git.proxmox.com Git - pve-manager.git/blob - PVE/Report.pm
add 'pvs' to pvereport
[pve-manager.git] / PVE / Report.pm
1 package PVE::Report;
2
3 use strict;
4 use warnings;
5 use PVE::pvecfg;
6 use PVE::Tools;
7
8 $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
9
10 my $cmd_timeout = 10; # generous timeout
11
12 # NOTE: always add new sections to the report_order array!
13 my $report_def = {
14 general => {
15 title => 'general system info',
16 cmds => [
17 'hostname',
18 'pveversion --verbose',
19 'cat /etc/hosts',
20 'top -b -n 1 | head -n 15',
21 'pvesubscription get',
22 'lscpu',
23 'pvesh get /cluster/resources --type node --output-format=yaml',
24 ],
25 },
26 storage => [
27 'cat /etc/pve/storage.cfg',
28 'pvesm status',
29 'cat /etc/fstab',
30 'findmnt --ascii',
31 'df --human',
32 ],
33 'virtual guests' => [
34 'qm list',
35 sub { dir2text('/etc/pve/qemu-server/', '\d.*conf') },
36 'pct list',
37 sub { dir2text('/etc/pve/lxc/', '\d.*conf') },
38 ],
39 network => [
40 'ip -details -statistics address',
41 'ip -details -4 route show',
42 'ip -details -6 route show',
43 'cat /etc/network/interfaces',
44 ],
45 firewall => [
46 sub { dir2text('/etc/pve/firewall/', '.*fw') },
47 'cat /etc/pve/local/host.fw',
48 'iptables-save',
49 ],
50 cluster => [
51 'pvecm nodes',
52 'pvecm status',
53 'cat /etc/pve/corosync.conf 2>/dev/null'
54 ],
55 bios => [
56 'dmidecode -t bios',
57 ],
58 pci => [
59 'lspci -nnk',
60 ],
61 disks => [
62 'lsblk --ascii',
63 ],
64 volumes => [
65 'pvs',
66 'lvs',
67 'vgs',
68 ],
69 };
70
71 my @report_order = ('general', 'storage', 'virtual guests', 'network',
72 'firewall', 'cluster', 'bios', 'pci', 'disks', 'volumes');
73
74 push @{$report_def->{volumes}}, 'zpool status', 'zfs list' if cmd_exists('zfs');
75
76 push @{$report_def->{disk}}, 'multipath -ll', 'multipath -v3' if cmd_exists('multipath');
77
78 my $report = '';
79
80 # output the content of all the files of a directory
81 sub dir2text {
82 my ($target_dir, $regexp) = @_;
83
84 PVE::Tools::dir_glob_foreach($target_dir, $regexp, sub {
85 my ($file) = @_;
86 $report .= "\n# cat $target_dir$file\n";
87 $report .= PVE::Tools::file_get_contents($target_dir.$file)."\n";
88 });
89 }
90
91 # command -v is the posix equivalent of 'which'
92 sub cmd_exists { system("command -v '$_[0]' > /dev/null 2>&1") == 0 }
93
94 sub generate {
95
96 my $record_output = sub {
97 $report .= shift . "\n";
98 };
99
100 my $run_cmd_params = {
101 outfunc => $record_output,
102 errfunc => $record_output,
103 timeout => $cmd_timeout,
104 noerr => 1, # avoid checking programs exit code
105 };
106
107 foreach my $section (@report_order) {
108 my $s = $report_def->{$section};
109
110 my $title = "info about $section";
111 my $commands = $s;
112
113 if (ref($s) eq 'HASH') {
114 $commands = $s->{cmds};
115 $title = $s->{title} if defined($s->{title});
116 } elsif (ref($s) ne 'ARRAY') {
117 die "unknown report definition in section '$section'!";
118 }
119
120 $report .= "\n==== $title ====\n";
121 foreach my $command (@$commands) {
122 eval {
123 if (ref $command eq 'CODE') {
124 PVE::Tools::run_with_timeout($cmd_timeout, $command);
125 } else {
126 $report .= "\n# $command\n";
127 PVE::Tools::run_command($command, %$run_cmd_params);
128 }
129 };
130 $report .= "\nERROR: $@\n" if $@;
131 }
132 }
133
134 return $report;
135 }
136
137 1;