]>
git.proxmox.com Git - pmg-api.git/blob - PMG/API2/Statistics.pm
1 package PMG
::API2
::Statistics
;
10 use PVE
::Exception
qw(raise_param_exc);
12 use PMG
::RESTEnvironment
;
13 use PVE
::JSONSchema
qw(get_standard_option);
19 use base
qw(PVE::RESTHandler);
21 __PACKAGE__-
>register_method ({
25 description
=> "Directory index.",
26 permissions
=> { check
=> [ 'admin', 'qmanager', 'audit'] },
28 additionalProperties
=> 0,
37 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
43 { name
=> "domains" },
45 { name
=> "mailcount" },
46 { name
=> "maildistribution" },
47 { name
=> "spamscores" },
52 __PACKAGE__-
>register_method ({
56 description
=> "Mail Domains Statistics.",
57 permissions
=> { check
=> [ 'admin', 'qmanager', 'audit'] },
59 additionalProperties
=> 0,
61 starttime
=> get_standard_option
('pmg-starttime'),
62 endtime
=> get_standard_option
('pmg-endtime'),
71 description
=> "Domain name.",
75 description
=> "Incoming mail count.",
79 description
=> "Outgoing mail count.",
83 description
=> "Incoming spam mails.",
87 description
=> "Outgoing spam mails.",
91 description
=> "Incoming mail traffic (Mebibytes).",
95 description
=> "Outgoing mail traffic (Mebibytes).",
99 description
=> "Number of incoming virus mails.",
103 description
=> "Number of outgoing virus mails.",
112 my $restenv = PMG
::RESTEnvironment-
>get();
113 my $cinfo = $restenv->{cinfo
};
115 my $start = $param->{starttime
} // (time - 86400);
116 my $end = $param->{endtime
} // ($start + 86400);
118 my $stat = PMG
::Statistic-
>new($start, $end);
119 my $rdb = PMG
::RuleDB-
>new();
121 #PMG::Statistic::update_stats_domainstat_in($rdb->{dbh}, $cinfo);
122 #PMG::Statistic::update_stats_domainstat_out($rdb->{dbh}, $cinfo);
124 my $res = $stat->total_domain_stat($rdb);
130 __PACKAGE__-
>register_method ({
134 description
=> "General Mail Statistics.",
135 permissions
=> { check
=> [ 'admin', 'qmanager', 'audit'] },
137 additionalProperties
=> 0,
139 starttime
=> get_standard_option
('pmg-starttime'),
140 endtime
=> get_standard_option
('pmg-endtime'),
147 description
=> "Average mail processing time in seconds.",
151 description
=> "Incoming bounce mail count (sender = <>).",
155 description
=> "Outgoing bounce mail count (sender = <>).",
159 description
=> "Overall mail count (in and out).",
163 description
=> "Incoming mail count.",
167 description
=> "Outgoing mail count.",
171 description
=> "Number of greylisted mails.",
175 description
=> "Incoming junk mail count (viruscount_in + spamcount_in + glcount + spfcount).",
179 description
=> "Outgoing junk mail count (viruscount_out + spamcount_out).",
183 description
=> "Incoming spam mails.",
187 description
=> "Outgoing spam mails.",
191 description
=> "Mails rejected by SPF.",
195 description
=> "Incoming mail traffic (bytes).",
199 description
=> "Outgoing mail traffic (bytes).",
203 description
=> "Number of incoming virus mails.",
207 description
=> "Number of outgoing virus mails.",
215 my $restenv = PMG
::RESTEnvironment-
>get();
216 my $cinfo = $restenv->{cinfo
};
218 my $start = $param->{starttime
} // (time - 86400);
219 my $end = $param->{endtime
} // ($start + 86400);
221 my $stat = PMG
::Statistic-
>new($start, $end);
222 my $rdb = PMG
::RuleDB-
>new();
224 my $res = $stat->total_mail_stat($rdb);
229 __PACKAGE__-
>register_method ({
233 description
=> "Mail Count Statistics.",
234 permissions
=> { check
=> [ 'admin', 'qmanager', 'audit'] },
236 additionalProperties
=> 0,
238 starttime
=> get_standard_option
('pmg-starttime'),
239 endtime
=> get_standard_option
('pmg-endtime'),
241 description
=> "Return Mails/<timespan>, when <timespan> is specified in seconds.",
244 maximum
=> 366*86400,
256 description
=> "Time index.",
260 description
=> "Time (Unix epoch).",
264 description
=> "Overall mail count (in and out).",
268 description
=> "Incoming mail count.",
272 description
=> "Outgoing mail count.",
276 description
=> "Incoming spam mails (spamcount_in + glcount + spfcount).",
280 description
=> "Outgoing spam mails.",
284 description
=> "Number of incoming virus mails.",
288 description
=> "Number of outgoing virus mails.",
292 description
=> "Incoming bounce mail count (sender = <>).",
296 description
=> "Outgoing bounce mail count (sender = <>).",
305 my $restenv = PMG
::RESTEnvironment-
>get();
306 my $cinfo = $restenv->{cinfo
};
308 my $start = $param->{starttime
} // (time - 86400);
309 my $end = $param->{endtime
} // ($start + 86400);
311 my $span = $param->{timespan
} // 3600;
313 my $count = ($end - $start)/$span;
315 die "too many entries - try to increase parameter 'span'\n" if $count > 5000;
317 my $stat = PMG
::Statistic-
>new($start, $end);
318 my $rdb = PMG
::RuleDB-
>new();
320 #PMG::Statistic::update_stats_dailystat($rdb->{dbh}, $cinfo);
322 my $res = $stat->traffic_stat_graph ($rdb, $span);
327 __PACKAGE__-
>register_method ({
331 description
=> "Get Statistics about detected Viruses.",
332 permissions
=> { check
=> [ 'admin', 'qmanager', 'audit'] },
334 additionalProperties
=> 0,
336 starttime
=> get_standard_option
('pmg-starttime'),
337 endtime
=> get_standard_option
('pmg-endtime'),
346 description
=> 'Virus name.',
350 description
=> 'Detection count.',
359 my $restenv = PMG
::RESTEnvironment-
>get();
360 my $cinfo = $restenv->{cinfo
};
362 my $start = $param->{starttime
} // (time - 86400);
363 my $end = $param->{endtime
} // ($start + 86400);
365 my $stat = PMG
::Statistic-
>new($start, $end);
366 my $rdb = PMG
::RuleDB-
>new();
368 my $res = $stat->total_virus_stat($rdb);
373 __PACKAGE__-
>register_method ({
374 name
=> 'spamscores',
375 path
=> 'spamscores',
377 description
=> "Get the count of spam mails grouped by spam score. " .
378 "Count for score 10 includes mails with spam score > 10.",
379 permissions
=> { check
=> [ 'admin', 'qmanager', 'audit'] },
381 additionalProperties
=> 0,
383 starttime
=> get_standard_option
('pmg-starttime'),
384 endtime
=> get_standard_option
('pmg-endtime'),
393 description
=> 'Spam level.',
397 description
=> 'Detection count.',
401 description
=> 'Portion of overall mail count.',
410 my $restenv = PMG
::RESTEnvironment-
>get();
411 my $cinfo = $restenv->{cinfo
};
413 my $start = $param->{starttime
} // (time - 86400);
414 my $end = $param->{endtime
} // ($start + 86400);
416 my $stat = PMG
::Statistic-
>new($start, $end);
417 my $rdb = PMG
::RuleDB-
>new();
419 my $totalstat = $stat->total_mail_stat ($rdb);
420 my $spamstat = $stat->total_spam_stat($rdb);
424 my $count_in = $totalstat->{count_in
};
425 my $rest = $totalstat->{spamcount_in
};
428 foreach my $ref (@$spamstat) {
429 my $level = $ref->{spamlevel
} // 0;
430 next if $level >= 10 || $level < 1;
431 $rest -= $ref->{count
} if $level >= 3;
432 $levelcount->{$level} = $ref->{count
};
435 $levelcount->{0} = $totalstat->{count_in
} - $totalstat->{spamcount_in
};
436 $levelcount->{10} = $rest if $rest;
438 for (my $i = 0; $i <= 10; $i++) {
439 my $count = $levelcount->{$i} // 0;
440 my $ratio = $count_in ?
$count/$count_in : 0;
441 push @$res, { level
=> $i, count
=> $count, ratio
=> $ratio };
447 __PACKAGE__-
>register_method ({
448 name
=> 'maildistribution',
449 path
=> 'maildistribution',
451 description
=> "Get the count of spam mails grouped by spam score. " .
452 "Count for score 10 includes mails with spam score > 10.",
453 permissions
=> { check
=> [ 'admin', 'qmanager', 'audit'] },
455 additionalProperties
=> 0,
457 starttime
=> get_standard_option
('pmg-starttime'),
458 endtime
=> get_standard_option
('pmg-endtime'),
467 description
=> "Hour (0-23).",
471 description
=> "Overall mail count (in and out).",
475 description
=> "Incoming mail count.",
479 description
=> "Outgoing mail count.",
483 description
=> "Incoming spam mails (spamcount_in + glcount + spfcount).",
487 description
=> "Outgoing spam mails.",
491 description
=> "Number of incoming virus mails.",
495 description
=> "Number of outgoing virus mails.",
499 description
=> "Incoming bounce mail count (sender = <>).",
503 description
=> "Outgoing bounce mail count (sender = <>).",
512 my $restenv = PMG
::RESTEnvironment-
>get();
513 my $cinfo = $restenv->{cinfo
};
515 my $start = $param->{starttime
} // (time - 86400);
516 my $end = $param->{endtime
} // ($start + 86400);
518 my $stat = PMG
::Statistic-
>new($start, $end);
519 my $rdb = PMG
::RuleDB-
>new();
521 #PMG::Statistic::update_stats_dailystat($rdb->{dbh}, $cinfo);
523 my $res = $stat->traffic_stat_day_dist ($rdb);