]>
Commit | Line | Data |
---|---|---|
2f7faeed EK |
1 | package PVE::Report; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | use PVE::pvecfg; | |
6 | use PVE::Tools; | |
7 | ||
470c3515 EK |
8 | $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin'; |
9 | ||
2f7faeed EK |
10 | my $report; |
11 | ||
12 | my @general = ('hostname', 'pveversion --verbose', 'cat /etc/hosts', 'top -b -n 1 | head -n 15', | |
13 | 'pvesubscription get', 'lscpu'); | |
14 | ||
15 | my @storage = ('cat /etc/pve/storage.cfg', 'pvesm status', 'cat /etc/fstab', 'mount', 'df --human'); | |
16 | ||
470c3515 EK |
17 | my @volumes = ('lvs', 'vgs'); |
18 | # command -v is the posix equivalent of 'which' | |
19 | if (system('command -v zfs > /dev/null 2>&1') == 0) { | |
20 | push @volumes, 'zpool status', 'zfs list' | |
21 | } | |
8c9e7b5a | 22 | |
5e3fd48d | 23 | my @disks = ('lsblk --ascii'); |
470c3515 EK |
24 | if (system('command -v multipath > /dev/null 2>&1') == 0) { |
25 | push @disks, 'multipath -ll', 'multipath -v3' | |
26 | } | |
2f7faeed EK |
27 | |
28 | my @machines = ('qm list', sub { dir2text('/etc/pve/qemu-server/', '\d.*conf') }); | |
29 | ||
30 | my @net = ('ifconfig', 'cat /etc/network/interfaces', sub { dir2text('/etc/pve/firewall/', '.*fw') }, | |
31 | 'iptables-save'); | |
32 | ||
33 | my @cluster = ('pvecm nodes', 'pvecm status'); | |
34 | ||
35 | my @bios = ('dmidecode -t bios'); | |
36 | ||
37 | if (PVE::pvecfg::version() >= 4.0) { | |
38 | push @cluster, 'cat /etc/pve/corosync.conf 2> /dev/null' ; | |
39 | push @machines, sub { dir2text('/etc/pve/lxc/', '\d.*conf') }; | |
40 | } else { | |
41 | push @general, 'grep --max-count=1 "model name" /proc/cpuinfo'; | |
42 | push @machines, sub { dir2text('/etc/pve/openvz/', '\d.*conf') }; | |
43 | push @cluster, 'clustat', 'cat /etc/cluster.conf 2> /dev/null'; | |
44 | } | |
45 | ||
46 | my $general_report = { | |
47 | title => 'general system info', | |
48 | commands => \@general, | |
49 | }; | |
50 | ||
51 | my $storage_report = { | |
52 | title => 'info about storage (lvm and zfs)', | |
53 | commands => \@storage, | |
54 | }; | |
55 | ||
56 | my $volume_report = { | |
57 | title => 'info about virtual machines', | |
58 | commands => \@machines, | |
59 | }; | |
60 | ||
61 | my $net_report = { | |
62 | title => 'info about network and firewall', | |
63 | commands => \@net, | |
64 | }; | |
65 | ||
66 | my $cluster_report = { | |
67 | title => 'info about clustering', | |
68 | commands => \@cluster, | |
69 | }; | |
70 | ||
71 | my $bios_report = { | |
72 | title => 'info about bios', | |
73 | commands => \@bios, | |
74 | }; | |
75 | ||
8c9e7b5a WL |
76 | my $disks_report = { |
77 | title => 'info about disks', | |
78 | commands => \@disks, | |
79 | }; | |
80 | ||
81 | my $volumes_report = { | |
82 | title => 'info about volumes', | |
83 | commands => \@volumes, | |
84 | }; | |
85 | ||
86 | my @global_report = ($general_report, $storage_report, $volume_report, $net_report, | |
87 | $cluster_report, $bios_report, $disks_report, $volumes_report); | |
2f7faeed EK |
88 | |
89 | # output the content of all the files of a directory | |
90 | sub dir2text { | |
91 | my ($target_dir, $regexp) = @_; | |
92 | ||
93 | PVE::Tools::dir_glob_foreach($target_dir, $regexp, sub { | |
94 | my ($file) = @_; | |
95 | $report .= "# cat $target_dir$file\n"; | |
96 | $report .= PVE::Tools::file_get_contents($target_dir.$file)."\n"; | |
97 | }); | |
98 | } | |
99 | ||
100 | # execute commands and display their output as if they've been done on a interactive shell | |
101 | # so the local sysadmin can reproduce what we're doing | |
102 | sub do_execute { | |
103 | my ($command) = @_; | |
104 | $report .= "# $command \n"; | |
105 | open (COMMAND, "$command 2>&1 |"); | |
106 | while (<COMMAND>) { | |
107 | $report .= $_; | |
108 | } | |
109 | } | |
110 | ||
111 | sub generate { | |
112 | foreach my $subreport (@global_report) { | |
113 | my $title = $subreport->{'title'}; | |
114 | my @commands = @{$subreport->{'commands'}}; | |
115 | ||
116 | $report .= "\n==== $title ====\n"; | |
117 | foreach my $command (@commands) { | |
118 | if (ref $command eq 'CODE') { | |
119 | &$command; | |
120 | } else { | |
121 | do_execute($command); | |
122 | next; | |
123 | } | |
124 | } | |
125 | } | |
126 | return $report; | |
127 | } |