]>
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}" } ],
44 { name
=> "spamscores" },
49 __PACKAGE__-
>register_method ({
53 description
=> "General Mail Statistics.",
54 permissions
=> { check
=> [ 'admin', 'qmanager', 'audit'] },
56 additionalProperties
=> 0,
58 starttime
=> get_standard_option
('pmg-starttime'),
59 endtime
=> get_standard_option
('pmg-endtime'),
66 description
=> "Average mail processing time in seconds.",
70 description
=> "Incoming bounce mail count (sender = <>).",
74 description
=> "Outgoing bounce mail count (sender = <>).",
78 description
=> "Overall mail count (in and out).",
82 description
=> "Incoming mail count.",
86 description
=> "Outgoing mail count.",
90 description
=> "Number of greylisted mails.",
94 description
=> "Incoming junk mail count (viruscount_in + spamcount_in + glcount + spfcount).",
98 description
=> "Outgoing junk mail count (viruscount_out + spamcount_out).",
102 description
=> "Incoming spam mails.",
106 description
=> "Outgoing spam mails.",
110 description
=> "Mails rejected by SPF.",
114 description
=> "Incoming mail traffic (bytes).",
118 description
=> "Outgoing mail traffic (bytes).",
122 description
=> "Number of incoming virus mails.",
126 description
=> "Number of outgoing virus mails.",
134 my $restenv = PMG
::RESTEnvironment-
>get();
135 my $cinfo = $restenv->{cinfo
};
137 my $start = $param->{starttime
} // (time - 86400);
138 my $end = $param->{endtime
} // ($start + 86400);
140 my $stat = PMG
::Statistic-
>new($start, $end);
141 my $rdb = PMG
::RuleDB-
>new();
143 my $res = $stat->total_mail_stat($rdb);
148 __PACKAGE__-
>register_method ({
152 description
=> "Get Statistics about detected Viruses.",
153 permissions
=> { check
=> [ 'admin', 'qmanager', 'audit'] },
155 additionalProperties
=> 0,
157 starttime
=> get_standard_option
('pmg-starttime'),
158 endtime
=> get_standard_option
('pmg-endtime'),
167 description
=> 'Virus name.',
171 description
=> 'Detection count.',
180 my $restenv = PMG
::RESTEnvironment-
>get();
181 my $cinfo = $restenv->{cinfo
};
183 my $start = $param->{starttime
} // (time - 86400);
184 my $end = $param->{endtime
} // ($start + 86400);
186 my $stat = PMG
::Statistic-
>new($start, $end);
187 my $rdb = PMG
::RuleDB-
>new();
189 my $res = $stat->total_virus_stat($rdb);
194 __PACKAGE__-
>register_method ({
195 name
=> 'spamscores',
196 path
=> 'spamscores',
198 description
=> "Get the count of spam mails grouped by spam score. " .
199 "Count for score 10 includes mails with spam score > 10.",
200 permissions
=> { check
=> [ 'admin', 'qmanager', 'audit'] },
202 additionalProperties
=> 0,
204 starttime
=> get_standard_option
('pmg-starttime'),
205 endtime
=> get_standard_option
('pmg-endtime'),
214 description
=> 'Spam level.',
218 description
=> 'Detection count.',
222 description
=> 'Portion of overall mail count.',
231 my $restenv = PMG
::RESTEnvironment-
>get();
232 my $cinfo = $restenv->{cinfo
};
234 my $start = $param->{starttime
} // (time - 86400);
235 my $end = $param->{endtime
} // ($start + 86400);
237 my $stat = PMG
::Statistic-
>new($start, $end);
238 my $rdb = PMG
::RuleDB-
>new();
240 my $totalstat = $stat->total_mail_stat ($rdb);
241 my $spamstat = $stat->total_spam_stat($rdb);
245 my $count_in = $totalstat->{count_in
};
246 my $rest = $totalstat->{spamcount_in
};
249 foreach my $ref (@$spamstat) {
250 my $level = $ref->{spamlevel
} // 0;
251 next if $level >= 10 || $level < 1;
252 $rest -= $ref->{count
} if $level >= 3;
253 $levelcount->{$level} = $ref->{count
};
256 $levelcount->{0} = $totalstat->{count_in
} - $totalstat->{spamcount_in
};
257 $levelcount->{10} = $rest if $rest;
259 for (my $i = 0; $i <= 10; $i++) {
260 my $count = $levelcount->{$i} // 0;
261 my $ratio = $count_in ?
$count/$count_in : 0;
262 push @$res, { level
=> $i, count
=> $count, ratio
=> $ratio };