]>
git.proxmox.com Git - pmg-api.git/blob - src/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',
19 'pmgversion --verbose',
21 'cat /etc/resolv.conf',
22 'top -b -n 1 | head -n 15',
23 'pmgsubscription get',
24 sub { check_dns_resolution
() },
25 'cat /etc/apt/sources.list',
26 sub { dir2text
('/etc/apt/sources.list.d/', '.*\.list' ) },
36 'ip -details -statistics address',
37 'cat /etc/network/interfaces',
47 sub { dir2text
('/etc/pmg/','(?:domains|mynetworks|tls_policy|transport)' ) },
48 sub { dir2text
('/etc/postfix/','(?:clientaccess|senderaccess|rcptaccess)' ) },
49 sub { dir2text
('/etc/pmg/templates/', '[^.].*' ) },
54 my @report_order = ('general', 'storage', 'network', 'firewall', 'cluster', 'pmg');
58 # output the content of all the files of a directory
60 my ($target_dir, $regexp) = @_;
62 PVE
::Tools
::dir_glob_foreach
($target_dir, $regexp, sub {
64 $report .= "\n# cat $target_dir$file\n";
65 $report .= PVE
::Tools
::file_get_contents
($target_dir.$file)."\n";
69 # command -v is the posix equivalent of 'which'
70 sub cmd_exists
{ system("command -v '$_[0]' > /dev/null 2>&1") == 0 }
74 my $record_output = sub {
75 $report .= shift . "\n";
78 my $run_cmd_params = {
79 outfunc
=> $record_output,
80 errfunc
=> $record_output,
81 timeout
=> $cmd_timeout,
82 noerr
=> 1, # avoid checking programs exit code
85 foreach my $section (@report_order) {
86 my $s = $report_def->{$section};
88 my $title = "info about $section";
91 if (ref($s) eq 'HASH') {
92 $commands = $s->{cmds
};
93 $title = $s->{title
} if defined($s->{title
});
94 } elsif (ref($s) ne 'ARRAY') {
95 die "unknown report definition in section '$section'!";
98 $report .= "\n==== $title ====\n";
99 foreach my $command (@$commands) {
101 if (ref $command eq 'CODE') {
102 PVE
::Tools
::run_with_timeout
($cmd_timeout, $command);
104 $report .= "\n# $command\n";
105 PVE
::Tools
::run_command
($command, %$run_cmd_params);
108 $report .= "\nERROR: $@\n" if $@;
115 # using SpamAssassin's resolver, since the SA configuration can change which
116 # resolver is used and it uses only one resolver.
117 sub check_dns_resolution
{
119 my $sa = Mail
::SpamAssassin-
>new ({
121 local_tests_only
=> 0,
122 home_dir_for_helpers
=> '/root',
123 userstate_dir
=> '/root/.spamassassin',
124 dont_copy_prefs
=> 1,
125 stop_at_threshold
=> 0,
129 my $packet = $sa->{resolver
}->send('www.proxmox.com');
130 my $answer = $packet->{answer
}->[0];
131 my $answertext = defined($answer) ?
$answer->plain() : 'NXDOMAIN';
133 $report .= "\n# resolve www.proxmox.com\n";
134 $report .= $answertext . "\n";