]>
Commit | Line | Data |
---|---|---|
2f7faeed EK |
1 | package PVE::Report; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
180a86d3 | 5 | |
2f7faeed EK |
6 | use PVE::Tools; |
7 | ||
470c3515 EK |
8 | $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin'; |
9 | ||
ee3a8989 TL |
10 | my $cmd_timeout = 10; # generous timeout |
11 | ||
01c8f6fe TL |
12 | my $init_report_cmds = sub { |
13 | # NOTE: always add new sections to the report_order array! | |
14 | my $report_def = { | |
15 | general => { | |
16 | title => 'general system info', | |
17 | cmds => [ | |
18 | 'hostname', | |
19 | 'pveversion --verbose', | |
20 | 'cat /etc/hosts', | |
21 | 'top -b -n 1 | head -n 15', | |
22 | 'pvesubscription get', | |
23 | 'lscpu', | |
24 | 'pvesh get /cluster/resources --type node --output-format=yaml', | |
25 | ], | |
26 | }, | |
27 | storage => [ | |
28 | 'cat /etc/pve/storage.cfg', | |
29 | 'pvesm status', | |
30 | 'cat /etc/fstab', | |
31 | 'findmnt --ascii', | |
32 | 'df --human', | |
2c4ef55e | 33 | ], |
01c8f6fe TL |
34 | 'virtual guests' => [ |
35 | 'qm list', | |
36 | sub { dir2text('/etc/pve/qemu-server/', '\d.*conf') }, | |
37 | 'pct list', | |
38 | sub { dir2text('/etc/pve/lxc/', '\d.*conf') }, | |
39 | ], | |
40 | network => [ | |
41 | 'ip -details -statistics address', | |
42 | 'ip -details -4 route show', | |
43 | 'ip -details -6 route show', | |
44 | 'cat /etc/network/interfaces', | |
45 | ], | |
46 | firewall => [ | |
47 | sub { dir2text('/etc/pve/firewall/', '.*fw') }, | |
48 | 'cat /etc/pve/local/host.fw', | |
49 | 'iptables-save', | |
50 | ], | |
51 | cluster => [ | |
52 | 'pvecm nodes', | |
53 | 'pvecm status', | |
54 | 'cat /etc/pve/corosync.conf 2>/dev/null' | |
55 | ], | |
56 | bios => [ | |
57 | 'dmidecode -t bios', | |
58 | ], | |
59 | pci => [ | |
60 | 'lspci -nnk', | |
61 | ], | |
62 | disks => [ | |
63 | 'lsblk --ascii', | |
64 | 'ls -l /dev/disk/by-*/', | |
65 | 'iscsiadm -m node', | |
66 | 'iscsiadm -m session', | |
67 | ], | |
68 | volumes => [ | |
69 | 'pvs', | |
70 | 'lvs', | |
71 | 'vgs', | |
72 | ], | |
73 | }; | |
1cf7db21 | 74 | |
01c8f6fe | 75 | push @{$report_def->{volumes}}, 'zpool status', 'zpool list -v', 'zfs list' if cmd_exists('zfs'); |
1cf7db21 | 76 | |
01c8f6fe TL |
77 | if (-e '/etc/ceph/ceph.conf') { |
78 | my $crbd = eval "`ceph osd pool ls | sed -e 's/^/echo /' | sed 'p;s/echo/rbd ls/g'`"; | |
79 | push @{$report_def->{volumes}}, 'ceph status', 'ceph osd status', 'ceph df', 'pveceph status', 'pveceph lspools', $crbd; | |
80 | } | |
2f7faeed | 81 | |
01c8f6fe | 82 | push @{$report_def->{disk}}, 'multipath -ll', 'multipath -v3' if cmd_exists('multipath'); |
2f7faeed | 83 | |
01c8f6fe TL |
84 | return $report_def; |
85 | }; | |
2f7faeed | 86 | |
01c8f6fe | 87 | my $report; |
2f7faeed EK |
88 | # output the content of all the files of a directory |
89 | sub dir2text { | |
90 | my ($target_dir, $regexp) = @_; | |
91 | ||
92 | PVE::Tools::dir_glob_foreach($target_dir, $regexp, sub { | |
93 | my ($file) = @_; | |
ee3a8989 | 94 | $report .= "\n# cat $target_dir$file\n"; |
2f7faeed EK |
95 | $report .= PVE::Tools::file_get_contents($target_dir.$file)."\n"; |
96 | }); | |
97 | } | |
98 | ||
2c4ef55e TL |
99 | # command -v is the posix equivalent of 'which' |
100 | sub cmd_exists { system("command -v '$_[0]' > /dev/null 2>&1") == 0 } | |
101 | ||
2f7faeed | 102 | sub generate { |
ee3a8989 | 103 | |
01c8f6fe TL |
104 | my $report_def = $init_report_cmds->(); |
105 | ||
106 | my @report_order = ('general', 'storage', 'virtual guests', 'network', | |
107 | 'firewall', 'cluster', 'bios', 'pci', 'disks', 'volumes'); | |
108 | ||
109 | $report = ''; | |
ee3a8989 TL |
110 | my $record_output = sub { |
111 | $report .= shift . "\n"; | |
112 | }; | |
113 | ||
114 | my $run_cmd_params = { | |
115 | outfunc => $record_output, | |
116 | errfunc => $record_output, | |
117 | timeout => $cmd_timeout, | |
118 | noerr => 1, # avoid checking programs exit code | |
119 | }; | |
120 | ||
2c4ef55e TL |
121 | foreach my $section (@report_order) { |
122 | my $s = $report_def->{$section}; | |
123 | ||
124 | my $title = "info about $section"; | |
125 | my $commands = $s; | |
126 | ||
127 | if (ref($s) eq 'HASH') { | |
128 | $commands = $s->{cmds}; | |
129 | $title = $s->{title} if defined($s->{title}); | |
130 | } elsif (ref($s) ne 'ARRAY') { | |
131 | die "unknown report definition in section '$section'!"; | |
132 | } | |
2f7faeed EK |
133 | |
134 | $report .= "\n==== $title ====\n"; | |
2c4ef55e | 135 | foreach my $command (@$commands) { |
ee3a8989 TL |
136 | eval { |
137 | if (ref $command eq 'CODE') { | |
138 | PVE::Tools::run_with_timeout($cmd_timeout, $command); | |
139 | } else { | |
01c8f6fe | 140 | print STDERR "Process ".$command."..."; |
ee3a8989 TL |
141 | $report .= "\n# $command\n"; |
142 | PVE::Tools::run_command($command, %$run_cmd_params); | |
143 | } | |
2bdf85f8 | 144 | print STDERR "OK"; |
ee3a8989 | 145 | }; |
2bdf85f8 | 146 | print STDERR "\n"; |
ee3a8989 | 147 | $report .= "\nERROR: $@\n" if $@; |
2f7faeed EK |
148 | } |
149 | } | |
ee3a8989 TL |
150 | |
151 | return $report; | |
2f7faeed | 152 | } |
2c4ef55e TL |
153 | |
154 | 1; |