]>
git.proxmox.com Git - pmg-api.git/blob - src/PMG/Report.pm
4973dc528f9866e9d93e406a2f06c588c4c6d7cd
6 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 sub { dir2text
('/etc/postfix/','(?:clientaccess|senderaccess|rcptaccess)' ) },
51 sub { dump_templates
() },
56 my @report_order = ('general', 'storage', 'network', 'firewall', 'cluster', 'pmg');
60 # output the content of all the files of a directory
62 my ($target_dir, $regexp) = @_;
64 PVE
::Tools
::dir_glob_foreach
($target_dir, $regexp, sub {
66 $report .= "\n# cat $target_dir$file\n";
67 $report .= PVE
::Tools
::file_get_contents
($target_dir.$file)."\n";
71 # command -v is the posix equivalent of 'which'
72 sub cmd_exists
{ system("command -v '$_[0]' > /dev/null 2>&1") == 0 }
76 my $record_output = sub {
77 $report .= shift . "\n";
80 my $run_cmd_params = {
81 outfunc
=> $record_output,
82 errfunc
=> $record_output,
83 timeout
=> $cmd_timeout,
84 noerr
=> 1, # avoid checking programs exit code
87 foreach my $section (@report_order) {
88 my $s = $report_def->{$section};
90 my $title = "info about $section";
93 if (ref($s) eq 'HASH') {
94 $commands = $s->{cmds
};
95 $title = $s->{title
} if defined($s->{title
});
96 } elsif (ref($s) ne 'ARRAY') {
97 die "unknown report definition in section '$section'!";
100 $report .= "\n==== $title ====\n";
101 foreach my $command (@$commands) {
103 if (ref $command eq 'CODE') {
104 PVE
::Tools
::run_with_timeout
($cmd_timeout, $command);
106 $report .= "\n# $command\n";
107 PVE
::Tools
::run_command
($command, %$run_cmd_params);
110 $report .= "\nERROR: $@\n" if $@;
117 # using SpamAssassin's resolver, since the SA configuration can change which
118 # resolver is used and it uses only one resolver.
119 sub check_dns_resolution
{
121 my $sa = Mail
::SpamAssassin-
>new ({
123 local_tests_only
=> 0,
124 home_dir_for_helpers
=> '/root',
125 userstate_dir
=> '/root/.spamassassin',
126 dont_copy_prefs
=> 1,
127 stop_at_threshold
=> 0,
130 $sa->{resolver
}->load_resolver();
132 my $packet = $sa->{resolver
}->send('www.proxmox.com');
133 my $answer = $packet->{answer
}->[0];
134 my $answertext = defined($answer) ?
$answer->plain() : 'NXDOMAIN';
136 $report .= "\n# resolve www.proxmox.com\n";
137 $report .= $answertext . "\n";
141 my ($template_dir, $base_dir) = ('/etc/pmg/templates/', '/var/lib/pmg/templates');
142 PVE
::Tools
::dir_glob_foreach
($template_dir, '[^.].*', sub {
144 my $override_but_unmodified = 0;
145 if ($file =~ /.*\.(?:tt|in).*/ && -e
"$base_dir/$file") {
146 my $shipped = PVE
::Tools
::file_get_contents
("$base_dir/$file", 1024*1024);
147 my $override = PVE
::Tools
::file_get_contents
("$template_dir/$file", 1024*1024);
148 $override_but_unmodified = $shipped eq $override;
150 if ($file =~ /\.ucf-(?:dist|new|old)/) {
151 $report .= "\n# SKIP $file\n";
152 } elsif ($override_but_unmodified) {
153 $report .= "\n# NOTE, found a unmodified template-override: $file\n";
155 $report .= "\n# cat $template_dir$file\n";
156 $report .= PVE
::Tools
::file_get_contents
($template_dir.$file)."\n";