]> git.proxmox.com Git - pve-manager.git/blob - PVE/Report.pm
pvereport: add cluster resources node information
[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 route show',
42 'cat /etc/network/interfaces',
43 ],
44 firewall => [
45 sub { dir2text('/etc/pve/firewall/', '.*fw') },
46 'cat /etc/pve/local/host.fw',
47 'iptables-save',
48 ],
49 cluster => [
50 'pvecm nodes',
51 'pvecm status',
52 'cat /etc/pve/corosync.conf 2>/dev/null'
53 ],
54 bios => [
55 'dmidecode -t bios',
56 ],
57 pci => [
58 'lspci -nnk',
59 ],
60 disks => [
61 'lsblk --ascii',
62 ],
63 volumes => [
64 'lvs',
65 'vgs',
66 ],
67 };
68
69 my @report_order = ('general', 'storage', 'virtual guests', 'network',
70 'firewall', 'cluster', 'bios', 'pci', 'disks', 'volumes');
71
72 push @{$report_def->{volumes}}, 'zpool status', 'zfs list' if cmd_exists('zfs');
73
74 push @{$report_def->{disk}}, 'multipath -ll', 'multipath -v3' if cmd_exists('multipath');
75
76 my $report = '';
77
78 # output the content of all the files of a directory
79 sub dir2text {
80 my ($target_dir, $regexp) = @_;
81
82 PVE::Tools::dir_glob_foreach($target_dir, $regexp, sub {
83 my ($file) = @_;
84 $report .= "\n# cat $target_dir$file\n";
85 $report .= PVE::Tools::file_get_contents($target_dir.$file)."\n";
86 });
87 }
88
89 # command -v is the posix equivalent of 'which'
90 sub cmd_exists { system("command -v '$_[0]' > /dev/null 2>&1") == 0 }
91
92 sub generate {
93
94 my $record_output = sub {
95 $report .= shift . "\n";
96 };
97
98 my $run_cmd_params = {
99 outfunc => $record_output,
100 errfunc => $record_output,
101 timeout => $cmd_timeout,
102 noerr => 1, # avoid checking programs exit code
103 };
104
105 foreach my $section (@report_order) {
106 my $s = $report_def->{$section};
107
108 my $title = "info about $section";
109 my $commands = $s;
110
111 if (ref($s) eq 'HASH') {
112 $commands = $s->{cmds};
113 $title = $s->{title} if defined($s->{title});
114 } elsif (ref($s) ne 'ARRAY') {
115 die "unknown report definition in section '$section'!";
116 }
117
118 $report .= "\n==== $title ====\n";
119 foreach my $command (@$commands) {
120 eval {
121 if (ref $command eq 'CODE') {
122 PVE::Tools::run_with_timeout($cmd_timeout, $command);
123 } else {
124 $report .= "\n# $command\n";
125 PVE::Tools::run_command($command, %$run_cmd_params);
126 }
127 };
128 $report .= "\nERROR: $@\n" if $@;
129 }
130 }
131
132 return $report;
133 }
134
135 1;