]> git.proxmox.com Git - pve-manager.git/blame - PVE/Report.pm
pvereport: add cluster resources node information
[pve-manager.git] / PVE / Report.pm
CommitLineData
2f7faeed
EK
1package PVE::Report;
2
3use strict;
4use warnings;
5use PVE::pvecfg;
6use PVE::Tools;
7
470c3515
EK
8$ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
9
ee3a8989
TL
10my $cmd_timeout = 10; # generous timeout
11
2c4ef55e
TL
12# NOTE: always add new sections to the report_order array!
13my $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',
f4606568 23 'pvesh get /cluster/resources --type node --output-format=yaml',
2c4ef55e
TL
24 ],
25 },
26 storage => [
27 'cat /etc/pve/storage.cfg',
28 'pvesm status',
29 'cat /etc/fstab',
a0801414 30 'findmnt --ascii',
2c4ef55e
TL
31 'df --human',
32 ],
33 'virtual guests' => [
34 'qm list',
35 sub { dir2text('/etc/pve/qemu-server/', '\d.*conf') },
8e363bee 36 'pct list',
2c4ef55e
TL
37 sub { dir2text('/etc/pve/lxc/', '\d.*conf') },
38 ],
39 network => [
40 'ip -details -statistics address',
44a3f316 41 'ip -details route show',
2c4ef55e
TL
42 'cat /etc/network/interfaces',
43 ],
44 firewall => [
45 sub { dir2text('/etc/pve/firewall/', '.*fw') },
b5f7824f 46 'cat /etc/pve/local/host.fw',
2c4ef55e
TL
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 ],
17b74593
TL
57 pci => [
58 'lspci -nnk',
59 ],
2c4ef55e
TL
60 disks => [
61 'lsblk --ascii',
62 ],
63 volumes => [
64 'lvs',
65 'vgs',
66 ],
2f7faeed
EK
67};
68
2c4ef55e 69my @report_order = ('general', 'storage', 'virtual guests', 'network',
17b74593 70'firewall', 'cluster', 'bios', 'pci', 'disks', 'volumes');
2f7faeed 71
2c4ef55e 72push @{$report_def->{volumes}}, 'zpool status', 'zfs list' if cmd_exists('zfs');
2f7faeed 73
2c4ef55e 74push @{$report_def->{disk}}, 'multipath -ll', 'multipath -v3' if cmd_exists('multipath');
2f7faeed 75
2c4ef55e 76my $report = '';
2f7faeed
EK
77
78# output the content of all the files of a directory
79sub dir2text {
80 my ($target_dir, $regexp) = @_;
81
82 PVE::Tools::dir_glob_foreach($target_dir, $regexp, sub {
83 my ($file) = @_;
ee3a8989 84 $report .= "\n# cat $target_dir$file\n";
2f7faeed
EK
85 $report .= PVE::Tools::file_get_contents($target_dir.$file)."\n";
86 });
87}
88
2c4ef55e
TL
89# command -v is the posix equivalent of 'which'
90sub cmd_exists { system("command -v '$_[0]' > /dev/null 2>&1") == 0 }
91
2f7faeed 92sub generate {
ee3a8989
TL
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
2c4ef55e
TL
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 }
2f7faeed
EK
117
118 $report .= "\n==== $title ====\n";
2c4ef55e 119 foreach my $command (@$commands) {
ee3a8989
TL
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 $@;
2f7faeed
EK
129 }
130 }
ee3a8989
TL
131
132 return $report;
2f7faeed 133}
2c4ef55e
TL
134
1351;