]>
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 my $sa_awl_db = '/root/.spamassassin/auto-whitelist';
14 # NOTE: always add new sections to the report_order array!
17 title
=> 'general system info',
20 'pmgversion --verbose',
22 'cat /etc/resolv.conf',
23 'top -b -n 1 | head -n 15',
24 'pmgsubscription get',
25 sub { check_dns_resolution
() },
35 'ip -details -statistics address',
36 'cat /etc/network/interfaces',
46 sub { dir2text
('/etc/pmg/','(?:domains|mynetworks|tls_policy|transport)' ) },
47 sub { dir2text
('/etc/pmg/templates/', '[^.].*' ) },
49 "[ -f '$sa_awl_db' ] && sa-awl '$sa_awl_db'",
53 my @report_order = ('general', 'storage', 'network', 'firewall', 'cluster', 'pmg');
57 # output the content of all the files of a directory
59 my ($target_dir, $regexp) = @_;
61 PVE
::Tools
::dir_glob_foreach
($target_dir, $regexp, sub {
63 $report .= "\n# cat $target_dir$file\n";
64 $report .= PVE
::Tools
::file_get_contents
($target_dir.$file)."\n";
68 # command -v is the posix equivalent of 'which'
69 sub cmd_exists
{ system("command -v '$_[0]' > /dev/null 2>&1") == 0 }
73 my $record_output = sub {
74 $report .= shift . "\n";
77 my $run_cmd_params = {
78 outfunc
=> $record_output,
79 errfunc
=> $record_output,
80 timeout
=> $cmd_timeout,
81 noerr
=> 1, # avoid checking programs exit code
84 foreach my $section (@report_order) {
85 my $s = $report_def->{$section};
87 my $title = "info about $section";
90 if (ref($s) eq 'HASH') {
91 $commands = $s->{cmds
};
92 $title = $s->{title
} if defined($s->{title
});
93 } elsif (ref($s) ne 'ARRAY') {
94 die "unknown report definition in section '$section'!";
97 $report .= "\n==== $title ====\n";
98 foreach my $command (@$commands) {
100 if (ref $command eq 'CODE') {
101 PVE
::Tools
::run_with_timeout
($cmd_timeout, $command);
103 $report .= "\n# $command\n";
104 PVE
::Tools
::run_command
($command, %$run_cmd_params);
107 $report .= "\nERROR: $@\n" if $@;
114 # using SpamAssassin's resolver, since the SA configuration can change which
115 # resolver is used and it uses only one resolver.
116 sub check_dns_resolution
{
118 my $sa = Mail
::SpamAssassin-
>new ({
120 local_tests_only
=> 0,
121 home_dir_for_helpers
=> '/root',
122 userstate_dir
=> '/root/.spamassassin',
123 dont_copy_prefs
=> 1,
124 stop_at_threshold
=> 0,
128 my $packet = $sa->{resolver
}->send('www.proxmox.com');
129 my $answer = $packet->{answer
}->[0];
130 my $answertext = defined($answer) ?
$answer->plain() : 'NXDOMAIN';
132 $report .= "\n# resolve www.proxmox.com\n";
133 $report .= $answertext . "\n";