2015-11-03 18:42:16 +03:00
package PVE::Report ;
use strict ;
use warnings ;
pvecfg: adapt version and release semantic
Wit commit a74ba607d4b02c5734c5480de62700f52f96ac71 we switched over
to using the dpkg-dev provided helpers to set package version,
architecture and such in the buildsystem.
But unlike other repositories we used the version also for giving it
back over the API through the during build generated PVE::pvecfg
module, which wasn't fully updated to the new style.
This patch does that, and also cleans up semantics a bit, the
following two changed:
release is now the Debian release, instead of the "package release"
(i.e., the -X part of a full package version).
version is now simply the full (pve-manager) version, e.g., 6.0-1 or
the currently for testing used 6.0-0+1
This allows to do everything we used this information for even in a
slightly easier way (no string concat needed anymore), and fits also
with the terminology we often used in our public channels (mailing
lists, forum, website)
Remove some cruft as we touch things.
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2019-05-26 16:58:16 +03:00
2015-11-03 18:42:16 +03:00
use PVE::Tools ;
2021-05-11 15:28:46 +03:00
# output the content of all the files of a directory
my sub dir2text {
my ( $ target_dir , $ regexp ) = @ _ ;
2021-05-11 16:12:15 +03:00
print STDERR "dir2text '${target_dir}${regexp}'..." ;
2021-05-11 15:28:46 +03:00
my $ text = '' ;
PVE::Tools:: dir_glob_foreach ( $ target_dir , $ regexp , sub {
my ( $ file ) = @ _ ;
$ text . = "\n# cat $target_dir$file\n" ;
$ text . = PVE::Tools:: file_get_contents ( $ target_dir . $ file ) . "\n" ;
} ) ;
return $ text ;
}
# command -v is the posix equivalent of 'which'
my sub cmd_exists { system ( "command -v '$_[0]' > /dev/null 2>&1" ) == 0 }
2017-06-09 13:06:12 +03:00
2019-04-08 13:25:57 +03:00
my $ init_report_cmds = sub {
my $ report_def = {
general = > {
title = > 'general system info' ,
2021-05-11 15:58:15 +03:00
order = > 10 ,
2019-04-08 13:25:57 +03:00
cmds = > [
'hostname' ,
'pveversion --verbose' ,
'cat /etc/hosts' ,
'pvesubscription get' ,
2021-01-26 20:31:38 +03:00
'cat /etc/apt/sources.list' ,
sub { dir2text ( '/etc/apt/sources.list.d/' , '.*list' ) } ,
2021-01-27 13:43:20 +03:00
sub { dir2text ( '/etc/apt/sources.list.d/' , '.*sources' ) } ,
2019-04-08 13:25:57 +03:00
'lscpu' ,
'pvesh get /cluster/resources --type node --output-format=yaml' ,
] ,
} ,
2021-05-11 16:20:10 +03:00
'system-load' = > {
title = > 'overall system load info' ,
order = > 20 ,
cmds = > [
2021-05-11 16:57:58 +03:00
'top -b -c -w512 -n 1 -o TIME | head -n 30' ,
2021-05-11 16:20:10 +03:00
'head /proc/pressure/*' ,
] ,
} ,
2021-05-11 15:58:15 +03:00
storage = > {
order = > 30 ,
cmds = > [
'cat /etc/pve/storage.cfg' ,
'pvesm status' ,
'cat /etc/fstab' ,
'findmnt --ascii' ,
2022-03-30 16:24:23 +03:00
'df --human -T' ,
2022-09-12 16:37:37 +03:00
'proxmox-boot-tool status' ,
2021-05-11 15:58:15 +03:00
] ,
} ,
'virtual guests' = > {
order = > 40 ,
cmds = > [
'qm list' ,
sub { dir2text ( '/etc/pve/qemu-server/' , '\d.*conf' ) } ,
'pct list' ,
sub { dir2text ( '/etc/pve/lxc/' , '\d.*conf' ) } ,
] ,
} ,
network = > {
2022-09-12 16:37:38 +03:00
order = > 45 ,
2021-05-11 15:58:15 +03:00
cmds = > [
'ip -details -statistics address' ,
'ip -details -4 route show' ,
'ip -details -6 route show' ,
'cat /etc/network/interfaces' ,
] ,
} ,
firewall = > {
order = > 50 ,
cmds = > [
sub { dir2text ( '/etc/pve/firewall/' , '.*fw' ) } ,
'cat /etc/pve/local/host.fw' ,
'iptables-save' ,
] ,
} ,
cluster = > {
order = > 60 ,
cmds = > [
'pvecm nodes' ,
'pvecm status' ,
'cat /etc/pve/corosync.conf 2>/dev/null' ,
'ha-manager status' ,
] ,
} ,
2021-05-11 16:20:10 +03:00
hardware = > {
2021-05-11 15:58:15 +03:00
order = > 70 ,
cmds = > [
'dmidecode -t bios' ,
'lspci -nnk' ,
] ,
} ,
2021-05-11 16:20:10 +03:00
'block devices' = > {
2021-05-11 15:58:15 +03:00
order = > 80 ,
cmds = > [
2022-03-30 16:33:10 +03:00
'lsblk --ascii -M -o +HOTPLUG,ROTA,PHY-SEC,FSTYPE,MODEL,TRAN' ,
2021-05-11 15:58:15 +03:00
'ls -l /dev/disk/by-*/' ,
'iscsiadm -m node' ,
'iscsiadm -m session' ,
] ,
} ,
volumes = > {
order = > 90 ,
cmds = > [
'pvs' ,
'lvs' ,
'vgs' ,
] ,
} ,
2019-04-08 13:25:57 +03:00
} ;
2019-04-03 11:25:06 +03:00
2021-05-11 15:26:15 +03:00
if ( cmd_exists ( 'zfs' ) ) {
2021-05-11 15:58:15 +03:00
push @ { $ report_def - > { volumes } - > { cmds } } ,
2021-05-11 15:26:15 +03:00
'zpool status' ,
'zpool list -v' ,
'zfs list' ,
2022-10-18 15:11:05 +03:00
'arcstat' ,
2021-05-11 15:26:15 +03:00
;
}
2019-04-03 11:25:06 +03:00
2019-04-08 13:25:57 +03:00
if ( - e '/etc/ceph/ceph.conf' ) {
2021-05-11 15:58:15 +03:00
push @ { $ report_def - > { volumes } - > { cmds } } ,
2020-12-21 19:00:46 +03:00
'pveceph status' ,
'ceph osd status' ,
'ceph df' ,
'ceph osd df tree' ,
2022-05-31 15:44:30 +03:00
'ceph device ls' ,
2020-12-21 19:00:46 +03:00
'cat /etc/ceph/ceph.conf' ,
'ceph config dump' ,
'pveceph pool ls' ,
'ceph versions' ,
;
2019-04-08 13:25:57 +03:00
}
2015-11-03 18:42:16 +03:00
2021-04-16 16:15:54 +03:00
if ( cmd_exists ( 'multipath' ) ) {
2021-05-11 15:58:15 +03:00
push @ { $ report_def - > { disks } - > { cmds } } ,
2021-04-16 16:15:54 +03:00
'cat /etc/multipath.conf' ,
'cat /etc/multipath/wwids' ,
2021-05-11 15:26:15 +03:00
'multipath -ll' ,
;
2021-04-16 16:15:54 +03:00
}
2015-11-03 18:42:16 +03:00
2019-04-08 13:25:57 +03:00
return $ report_def ;
} ;
2015-11-03 18:42:16 +03:00
sub generate {
2021-05-11 15:58:15 +03:00
my $ def = $ init_report_cmds - > ( ) ;
2019-04-08 13:25:57 +03:00
2021-05-11 15:28:46 +03:00
my $ report = '' ;
2017-06-09 13:06:12 +03:00
my $ record_output = sub {
$ report . = shift . "\n" ;
} ;
2021-05-11 15:27:40 +03:00
local $ ENV { 'PATH' } = '/sbin:/bin:/usr/sbin:/usr/bin' ;
my $ cmd_timeout = 10 ; # generous timeout
2017-06-09 13:06:12 +03:00
my $ run_cmd_params = {
outfunc = > $ record_output ,
errfunc = > $ record_output ,
timeout = > $ cmd_timeout ,
noerr = > 1 , # avoid checking programs exit code
} ;
2021-05-11 15:58:15 +03:00
my $ sorter = sub { ( $ def - > { $ _ [ 0 ] } - > { order } // 1 << 30 ) <=> ( $ def - > { $ _ [ 1 ] } - > { order } // 1 << 30 ) } ;
2018-03-02 11:38:57 +03:00
2021-05-11 15:58:15 +03:00
for my $ section ( sort { $ sorter - > ( $ a , $ b ) } keys %$ def ) {
my $ s = $ def - > { $ section } ;
my $ title = $ s - > { title } // "info about $section" ;
2015-11-03 18:42:16 +03:00
$ report . = "\n==== $title ====\n" ;
2021-05-11 15:58:15 +03:00
for my $ command ( @ { $ s - > { cmds } } ) {
2017-06-09 13:06:12 +03:00
eval {
if ( ref $ command eq 'CODE' ) {
2021-05-11 15:28:46 +03:00
$ report . = PVE::Tools:: run_with_timeout ( $ cmd_timeout , $ command ) ;
2017-06-09 13:06:12 +03:00
} else {
2019-04-08 13:25:57 +03:00
print STDERR "Process " . $ command . "..." ;
2017-06-09 13:06:12 +03:00
$ report . = "\n# $command\n" ;
PVE::Tools:: run_command ( $ command , %$ run_cmd_params ) ;
}
2019-04-03 13:56:28 +03:00
print STDERR "OK" ;
2017-06-09 13:06:12 +03:00
} ;
2019-04-03 13:56:28 +03:00
print STDERR "\n" ;
2017-06-09 13:06:12 +03:00
$ report . = "\nERROR: $@\n" if $@ ;
2015-11-03 18:42:16 +03:00
}
}
2017-06-09 13:06:12 +03:00
return $ report ;
2015-11-03 18:42:16 +03:00
}
2018-03-02 11:38:57 +03:00
1 ;