]> git.proxmox.com Git - pve-manager.git/blame - PVE/Report.pm
REST/RPCEnvironment's check_worker is a method now
[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
2f7faeed
EK
10my $report;
11
12my @general = ('hostname', 'pveversion --verbose', 'cat /etc/hosts', 'top -b -n 1 | head -n 15',
13 'pvesubscription get', 'lscpu');
14
15my @storage = ('cat /etc/pve/storage.cfg', 'pvesm status', 'cat /etc/fstab', 'mount', 'df --human');
16
470c3515
EK
17my @volumes = ('lvs', 'vgs');
18# command -v is the posix equivalent of 'which'
19if (system('command -v zfs > /dev/null 2>&1') == 0) {
20 push @volumes, 'zpool status', 'zfs list'
21}
8c9e7b5a 22
5e3fd48d 23my @disks = ('lsblk --ascii');
470c3515
EK
24if (system('command -v multipath > /dev/null 2>&1') == 0) {
25 push @disks, 'multipath -ll', 'multipath -v3'
26}
2f7faeed
EK
27
28my @machines = ('qm list', sub { dir2text('/etc/pve/qemu-server/', '\d.*conf') });
29
30my @net = ('ifconfig', 'cat /etc/network/interfaces', sub { dir2text('/etc/pve/firewall/', '.*fw') },
31 'iptables-save');
32
33my @cluster = ('pvecm nodes', 'pvecm status');
34
35my @bios = ('dmidecode -t bios');
36
37if (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
46my $general_report = {
47 title => 'general system info',
48 commands => \@general,
49};
50
51my $storage_report = {
52 title => 'info about storage (lvm and zfs)',
53 commands => \@storage,
54};
55
56my $volume_report = {
57 title => 'info about virtual machines',
58 commands => \@machines,
59};
60
61my $net_report = {
62 title => 'info about network and firewall',
63 commands => \@net,
64};
65
66my $cluster_report = {
67 title => 'info about clustering',
68 commands => \@cluster,
69};
70
71my $bios_report = {
72 title => 'info about bios',
73 commands => \@bios,
74};
75
8c9e7b5a
WL
76my $disks_report = {
77 title => 'info about disks',
78 commands => \@disks,
79};
80
81my $volumes_report = {
82 title => 'info about volumes',
83 commands => \@volumes,
84};
85
86my @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
90sub 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
102sub do_execute {
103 my ($command) = @_;
104 $report .= "# $command \n";
105 open (COMMAND, "$command 2>&1 |");
106 while (<COMMAND>) {
107 $report .= $_;
108 }
109}
110
111sub 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 }
126return $report;
127}