| 1 | package Tail::Stat::Plugin::clamd; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | Tail::Stat::Plugin::clamd - Statistics collector for ClamAV clamd | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =cut | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use warnings qw(all); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | tstatd -o type clamd clamd.log | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =head1 LOG FORMATS | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | Plugin search clamd logs for records of two types: | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =over | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | =item C<clean> | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | clamd: /var/spool/exim/scan/1PLMRr-000MyJ-Kg/1PLMRr-000MyJ-Kg.eml: OK | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | =item C<malware> | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | clamd: /var/spool/exim/scan/1PLRje-0008yP-U3/1PLRje-0008yP-U3.eml: Exploit.HTML.IFrame-8 FOUND | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =back | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | =head1 OPTIONS | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =over | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | =item C<type> | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | Turn on collecting per-malware statistics. | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | =back | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =head1 STATISTICS | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =head2 Overall statistics | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =over | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =item C<clean_messages> | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | Total number of messages identified as clean. | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =item C<malware_messages> | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | Total number of messages identified as malware. | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =back | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =head2 Last statistics | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =over | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | =item C<last_clean_messages> | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | Total number of last messages identified as clean. | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | =item C<last_malware_messages> | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | Total number of last messages identified as malware. | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | =item C<last_clean_rate> | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | Total rate of last messages identified as clean. | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =item C<last_malware_rate> | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | Total rate of last messages identified as malware. | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =back | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | =cut | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 3 | ▶ | use base qw(Tail::Stat::Plugin); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 90 | 3 | ▶ | use List::Util qw(sum); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 2 | ▶ | sub regex { qr{ | ||||||||||||||||||||||||||
|
Subroutine
regex: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | :\s+ | ||||||||||||||||||||||||||||
| 96 | (?: | ||||||||||||||||||||||||||||
| 97 | (\S+) # 'malware' [0] | ||||||||||||||||||||||||||||
| 98 | \s+ | ||||||||||||||||||||||||||||
| 99 | FOUND | ||||||||||||||||||||||||||||
| 100 | | | ||||||||||||||||||||||||||||
| 101 | OK | ||||||||||||||||||||||||||||
| 102 | ) | ||||||||||||||||||||||||||||
| 103 | $ | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | }x } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | sub process_data { | ||||||||||||||||||||||||||||
| 109 | 2430 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
process_data: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 110 | 2430 | my ($ref,$pub,$prv,$win) = @_; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 2430 | ▶ | my $status = $ref->[0] ? 'malware' : 'clean'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 2430 | $pub->{ $status }++; | |||||||||||||||||||||||||||
| 115 | $pub->{ 'malware:' . $ref->[0] }++ | ||||||||||||||||||||||||||||
| 116 | 2430 | ▶ | if $self->{type} && $status eq 'malware'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"type"} and $status eq "malware"
MC/DC100%2/2
$self->{"type"} and $status eq "malware"
$self->{"type"}
$status eq "malware"
Truth table100%3/3
A and B
A= $self->{"type"}B= $status eq "malware"
| |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 2430 | $win->{ $status }++; | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 2430 | return 1; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | sub process_window { | ||||||||||||||||||||||||||||
| 125 | 6 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
process_window: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 126 | 6 | my ($pub,$prv,$wins) = @_; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 6 | for my $m ( qw( clean malware ) ) { | |||||||||||||||||||||||||||
| 129 | 12 | ▶ | $pub->{'last_' . $m } = sum ( map { $_->{ $m } || 0 } @$wins ) || 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
&sum(map({$_->{$m} or 0;} @$wins)) || 0
MC/DC100%1/1
&sum(map({$_->{$m} or 0;} @$wins)) || 0
&sum(map({$_->{$m} or 0;} @$wins))
Truth table100%2/2
A
A= &sum(map({$_->{$m} or 0;} @$wins))
| |||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | sub stats_zone { | ||||||||||||||||||||||||||||
| 135 | 2 | ▶ | my ($self,$zone,$pub,$prv,$wins) = @_; | ||||||||||||||||||||||||||
|
Subroutine
stats_zone: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | # required keys defaults | ||||||||||||||||||||||||||||
| 138 | 2 | my %out = ( clean => 0, malware => 0 ); | |||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | # copy values as is | ||||||||||||||||||||||||||||
| 141 | 2 | $out{$_} += $pub->{$_} for keys %$pub; | |||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 2 | map { $_.': '.$out{$_} } sort keys %out; | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | Oleg A. Mamontov, C<< <oleg@mamontov.net> >> | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 155 | under the terms of either: the GNU General Public License as published | ||||||||||||||||||||||||||||
| 156 | by the Free Software Foundation; or the Artistic License. | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | See http://dev.perl.org/licenses/ for more information. | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | =cut | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 3 | 1; | |||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||