]> git.proxmox.com Git - pmg-api.git/commitdiff
pmgreport: add quarantine data
authorDietmar Maurer <dietmar@proxmox.com>
Wed, 23 Aug 2017 06:24:57 +0000 (08:24 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 23 Aug 2017 06:24:57 +0000 (08:24 +0200)
PMG/CLI/pmgreport.pm
templates/pmgreport.tt

index a55ba9cd8f5c7c3cdb69a31142b4ecc3525e44c1..d29059132b1217e54d8e023697277f69fb642c9f 100644 (file)
@@ -185,6 +185,54 @@ my $get_virus_table_data = sub {
     return $data;
 };
 
+my $get_quarantine_table_data = sub {
+    my ($dbh, $qtype) = @_;
+
+    # Note;: We try to estimate used disk space - each mail
+    # is stored in an extra file ...
+
+    my $bs = 4096;
+
+    my $sth = $dbh->prepare(
+       "SELECT count(ID) as count,  sum (ceil((Bytes+$bs-1)/$bs)*$bs) / (1024*1024) as mbytes, " .
+       "avg(Bytes) as avgbytes, avg(Spamlevel) as avgspam " .
+       "FROM CMailStore WHERE QType = ?");
+
+    $sth->execute($qtype);
+
+    my $ref = $sth->fetchrow_hashref();
+
+    $sth->finish;
+
+    return undef if !($ref && $ref->{count});
+
+    my $data = [];
+
+    push @$data, {
+       text => "Quarantine Size (MBytes)",
+       value => int($ref->{mbytes}),
+    };
+
+    push @$data, {
+       text => "Number of Mails",
+       value => $ref->{count},
+    };
+
+    push @$data, {
+       text => "Average Size (Bytes)",
+       value => int($ref->{avgbytes}),
+    };
+
+    if ($qtype eq 'S') {
+       push @$data, {
+           text => "Average Spam Level",
+           value => int($ref->{avgspam}),
+       };
+    }
+
+    return $data;
+};
+
 __PACKAGE__->register_method ({
     name => 'pmgreport',
     path => 'pmgreport',
@@ -266,6 +314,14 @@ __PACKAGE__->register_method ({
            $vars->{virusstat} = $data;
        }
 
+       if (my $data = $get_quarantine_table_data->($rdb->{dbh}, 'V')) {
+           $vars->{virusquar} = $data;
+       }
+
+       if (my $data = $get_quarantine_table_data->($rdb->{dbh}, 'S')) {
+           $vars->{spamquar} = $data;
+       }
+
        my $tt = PMG::Config::get_template_toolkit();
 
        my $cfg = PMG::Config->new();
index 50fb7c449fd5c7d3db017684dc45a90b909ca5cf..fc37726a70dbf5967ab64f9ce72c757598ab501e 100644 (file)
@@ -20,7 +20,7 @@ table, th, td {
 border: 1px solid black;
 border-collapse: collapse;
 }
-  
+
 </style>
 </head>
 <body>
@@ -57,7 +57,7 @@ border-collapse: collapse;
     [% FOREACH item IN system %]
     <tr>
       <td>[% item.text %]</td>
-      <td>[% item.value %]</td>
+      <td style="width:150px;">[% item.value %]</td>
     </tr>
     [% END %]
   </table>
@@ -103,5 +103,29 @@ border-collapse: collapse;
   </table>
   [% END %]
 
+  [% IF virusquar %]
+  <h2>Virus Quarantine</h2>
+  <table>
+    [% FOREACH item IN virusquar %]
+    <tr>
+      <td>[% item.text %]</td>
+      <td style="width:150px;">[% item.value %]</td>
+    </tr>
+    [% END %]
+  </table>
+  [% END %]
+
+  [% IF spamquar %]
+  <h2>Spam Quarantine</h2>
+  <table>
+    [% FOREACH item IN spamquar %]
+    <tr>
+      <td>[% item.text %]</td>
+      <td style="width:150px;">[% item.value %]</td>
+    </tr>
+    [% END %]
+  </table>
+  [% END %]
+
 </body>
 </html>