]>
git.proxmox.com Git - pmg-api.git/blob - PMG/Report.pm
6 use Mail
::SpamAssassin
::DnsResolver
;
8 $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
10 my $cmd_timeout = 10; # generous timeout
12 # NOTE: always add new sections to the report_order array!
15 title
=> 'general system info',
18 'pmgversion --verbose',
20 'cat /etc/resolv.conf',
21 'top -b -n 1 | head -n 15',
22 'pmgsubscription get',
23 sub { check_dns_resolution
() },
33 'ip -details -statistics address',
34 'cat /etc/network/interfaces',
44 sub { dir2text
('/etc/pmg/','(?:domains|mynetworks|tls_policy|transport)' ) },
45 sub { dir2text
('/etc/pmg/templates/', '[^.].*' ) },
50 my @report_order = ('general', 'storage', 'network', 'firewall', 'cluster', 'pmg');
54 # output the content of all the files of a directory
56 my ($target_dir, $regexp) = @_;
58 PVE
::Tools
::dir_glob_foreach
($target_dir, $regexp, sub {
60 $report .= "\n# cat $target_dir$file\n";
61 $report .= PVE
::Tools
::file_get_contents
($target_dir.$file)."\n";
65 # command -v is the posix equivalent of 'which'
66 sub cmd_exists
{ system("command -v '$_[0]' > /dev/null 2>&1") == 0 }
70 my $record_output = sub {
71 $report .= shift . "\n";
74 my $run_cmd_params = {
75 outfunc
=> $record_output,
76 errfunc
=> $record_output,
77 timeout
=> $cmd_timeout,
78 noerr
=> 1, # avoid checking programs exit code
81 foreach my $section (@report_order) {
82 my $s = $report_def->{$section};
84 my $title = "info about $section";
87 if (ref($s) eq 'HASH') {
88 $commands = $s->{cmds
};
89 $title = $s->{title
} if defined($s->{title
});
90 } elsif (ref($s) ne 'ARRAY') {
91 die "unknown report definition in section '$section'!";
94 $report .= "\n==== $title ====\n";
95 foreach my $command (@$commands) {
97 if (ref $command eq 'CODE') {
98 PVE
::Tools
::run_with_timeout
($cmd_timeout, $command);
100 $report .= "\n# $command\n";
101 PVE
::Tools
::run_command
($command, %$run_cmd_params);
104 $report .= "\nERROR: $@\n" if $@;
111 # using SpamAssassin's resolver, since the SA configuration can change which
112 # resolver is used and it uses only one resolver.
113 sub check_dns_resolution
{
115 my $sa = Mail
::SpamAssassin-
>new ({
117 local_tests_only
=> 0,
118 home_dir_for_helpers
=> '/root',
119 userstate_dir
=> '/root/.spamassassin',
120 dont_copy_prefs
=> 1,
121 stop_at_threshold
=> 0,
125 my $packet = $sa->{resolver
}->send('www.proxmox.com');
126 my $answer = $packet->{answer
}->[0];
127 my $answertext = defined($answer) ?
$answer->plain() : 'NXDOMAIN';
129 $report .= "\n# resolve www.proxmox.com\n";
130 $report .= $answertext . "\n";