]> git.proxmox.com Git - pve-manager.git/blob - PVE/Report.pm
Fix warning in Browser console due to missing meta entry
[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 my $report;
9
10 my @general = ('hostname', 'pveversion --verbose', 'cat /etc/hosts', 'top -b -n 1 | head -n 15',
11 'pvesubscription get', 'lscpu');
12
13 my @storage = ('cat /etc/pve/storage.cfg', 'pvesm status', 'cat /etc/fstab', 'mount', 'df --human');
14
15 my @volumes = ('lvdisplay', 'vgdisplay', 'zpool status', 'zfs list');
16
17 my @machines = ('qm list', sub { dir2text('/etc/pve/qemu-server/', '\d.*conf') });
18
19 my @net = ('ifconfig', 'cat /etc/network/interfaces', sub { dir2text('/etc/pve/firewall/', '.*fw') },
20 'iptables-save');
21
22 my @cluster = ('pvecm nodes', 'pvecm status');
23
24 my @bios = ('dmidecode -t bios');
25
26 if (PVE::pvecfg::version() >= 4.0) {
27 push @cluster, 'cat /etc/pve/corosync.conf 2> /dev/null' ;
28 push @machines, sub { dir2text('/etc/pve/lxc/', '\d.*conf') };
29 } else {
30 push @general, 'grep --max-count=1 "model name" /proc/cpuinfo';
31 push @machines, sub { dir2text('/etc/pve/openvz/', '\d.*conf') };
32 push @cluster, 'clustat', 'cat /etc/cluster.conf 2> /dev/null';
33 }
34
35 my $general_report = {
36 title => 'general system info',
37 commands => \@general,
38 };
39
40 my $storage_report = {
41 title => 'info about storage (lvm and zfs)',
42 commands => \@storage,
43 };
44
45 my $volume_report = {
46 title => 'info about virtual machines',
47 commands => \@machines,
48 };
49
50 my $net_report = {
51 title => 'info about network and firewall',
52 commands => \@net,
53 };
54
55 my $cluster_report = {
56 title => 'info about clustering',
57 commands => \@cluster,
58 };
59
60 my $bios_report = {
61 title => 'info about bios',
62 commands => \@bios,
63 };
64
65 my @global_report = ($general_report, $storage_report, $volume_report, $net_report, $cluster_report, $bios_report);
66
67 # output the content of all the files of a directory
68 sub dir2text {
69 my ($target_dir, $regexp) = @_;
70
71 PVE::Tools::dir_glob_foreach($target_dir, $regexp, sub {
72 my ($file) = @_;
73 $report .= "# cat $target_dir$file\n";
74 $report .= PVE::Tools::file_get_contents($target_dir.$file)."\n";
75 });
76 }
77
78 # execute commands and display their output as if they've been done on a interactive shell
79 # so the local sysadmin can reproduce what we're doing
80 sub do_execute {
81 my ($command) = @_;
82 $report .= "# $command \n";
83 open (COMMAND, "$command 2>&1 |");
84 while (<COMMAND>) {
85 $report .= $_;
86 }
87 }
88
89 sub generate {
90 foreach my $subreport (@global_report) {
91 my $title = $subreport->{'title'};
92 my @commands = @{$subreport->{'commands'}};
93
94 $report .= "\n==== $title ====\n";
95 foreach my $command (@commands) {
96 if (ref $command eq 'CODE') {
97 &$command;
98 } else {
99 do_execute($command);
100 next;
101 }
102 }
103 }
104 return $report;
105 }