]>
git.proxmox.com Git - pmg-api.git/blob - src/PMG/Report.pm
5 use Mail
::SpamAssassin
::DnsResolver
;
10 $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
12 my $cmd_timeout = 10; # generous timeout
14 # NOTE: always add new sections to the report_order array!
17 title
=> 'general system info',
21 'pmgversion --verbose',
23 'cat /etc/resolv.conf',
24 'top -b -n 1 | head -n 15',
25 'pmgsubscription get',
26 sub { check_dns_resolution
() },
27 'cat /etc/apt/sources.list',
28 sub { dir2text
('/etc/apt/sources.list.d/', '.*\.list' ) },
38 'ip -details -statistics address',
39 'cat /etc/network/interfaces',
49 sub { dir2text
('/etc/pmg/','(?:domains|mynetworks|tls_policy|transport)' ) },
50 'cat /etc/pmg/dkim/domains',
51 sub { dir2text
('/etc/postfix/','(?:clientaccess|senderaccess|rcptaccess)' ) },
52 sub { dump_templates
() },
57 my @report_order = ('general', 'storage', 'network', 'firewall', 'cluster', 'pmg');
61 # output the content of all the files of a directory
63 my ($target_dir, $regexp) = @_;
65 PVE
::Tools
::dir_glob_foreach
($target_dir, $regexp, sub {
67 $report .= "\n# cat $target_dir$file\n";
68 $report .= PVE
::Tools
::file_get_contents
($target_dir.$file)."\n";
72 # command -v is the posix equivalent of 'which'
73 sub cmd_exists
{ system("command -v '$_[0]' > /dev/null 2>&1") == 0 }
77 my $record_output = sub {
78 $report .= shift . "\n";
81 my $run_cmd_params = {
82 outfunc
=> $record_output,
83 errfunc
=> $record_output,
84 timeout
=> $cmd_timeout,
85 noerr
=> 1, # avoid checking programs exit code
88 foreach my $section (@report_order) {
89 my $s = $report_def->{$section};
91 my $title = "info about $section";
94 if (ref($s) eq 'HASH') {
95 $commands = $s->{cmds
};
96 $title = $s->{title
} if defined($s->{title
});
97 } elsif (ref($s) ne 'ARRAY') {
98 die "unknown report definition in section '$section'!";
101 $report .= "\n==== $title ====\n";
102 foreach my $command (@$commands) {
104 if (ref $command eq 'CODE') {
105 PVE
::Tools
::run_with_timeout
($cmd_timeout, $command);
107 $report .= "\n# $command\n";
108 PVE
::Tools
::run_command
($command, %$run_cmd_params);
111 $report .= "\nERROR: $@\n" if $@;
118 # using SpamAssassin's resolver, since the SA configuration can change which
119 # resolver is used and it uses only one resolver.
120 sub check_dns_resolution
{
122 my $sa = Mail
::SpamAssassin-
>new ({
124 local_tests_only
=> 0,
125 home_dir_for_helpers
=> '/root',
126 userstate_dir
=> '/root/.spamassassin',
127 dont_copy_prefs
=> 1,
128 stop_at_threshold
=> 0,
131 $sa->{resolver
}->load_resolver();
133 my $packet = $sa->{resolver
}->send('www.proxmox.com');
134 my $answer = $packet->{answer
}->[0];
135 my $answertext = defined($answer) ?
$answer->plain() : 'NXDOMAIN';
137 $report .= "\n# resolve www.proxmox.com\n";
138 $report .= $answertext . "\n";
142 my ($template_dir, $base_dir) = ('/etc/pmg/templates/', '/var/lib/pmg/templates');
143 PVE
::Tools
::dir_glob_foreach
($template_dir, '[^.].*', sub {
145 my $override_but_unmodified = 0;
146 if ($file =~ /.*\.(?:tt|in).*/ && -e
"$base_dir/$file") {
147 my $shipped = PVE
::Tools
::file_get_contents
("$base_dir/$file", 1024*1024);
148 my $override = PVE
::Tools
::file_get_contents
("$template_dir/$file", 1024*1024);
149 $override_but_unmodified = $shipped eq $override;
151 if ($file =~ /\.ucf-(?:dist|new|old)/) {
152 $report .= "\n# SKIP $file\n";
153 } elsif ($override_but_unmodified) {
154 $report .= "\n# NOTE, found a unmodified template-override: $file\n";
156 $report .= "\n# cat $template_dir$file\n";
157 $report .= PVE
::Tools
::file_get_contents
($template_dir.$file)."\n";