| line | stmt | bran | cond | sub | pod | time | code | 
| 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 | 1 |  |  | 1 |  | 881 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 38 |  | 
| 10 | 1 |  |  | 1 |  | 5 | use warnings qw(all); | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 60 |  | 
| 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 | 1 |  |  | 1 |  | 5 | use base qw(Tail::Stat::Plugin); | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 90 |  | 
| 90 | 1 |  |  | 1 |  | 8 | use List::Util qw(sum); | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 375 |  | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  |  | 
| 93 | 0 |  |  | 0 | 1 |  | sub regex { qr{ | 
| 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 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 110 | 0 |  |  |  |  |  | my ($ref,$pub,$prv,$win) = @_; | 
| 111 |  |  |  |  |  |  |  | 
| 112 | 0 | 0 |  |  |  |  | my $status = $ref->[0] ? 'malware' : 'clean'; | 
| 113 |  |  |  |  |  |  |  | 
| 114 | 0 |  |  |  |  |  | $pub->{ $status }++; | 
| 115 |  |  |  |  |  |  | $pub->{ 'malware:' . $ref->[0] }++ | 
| 116 | 0 | 0 | 0 |  |  |  | if $self->{type} && $status eq 'malware'; | 
| 117 |  |  |  |  |  |  |  | 
| 118 | 0 |  |  |  |  |  | $win->{ $status }++; | 
| 119 |  |  |  |  |  |  |  | 
| 120 | 0 |  |  |  |  |  | return 1; | 
| 121 |  |  |  |  |  |  | } | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  |  | 
| 124 |  |  |  |  |  |  | sub process_window { | 
| 125 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 126 | 0 |  |  |  |  |  | my ($pub,$prv,$wins) = @_; | 
| 127 |  |  |  |  |  |  |  | 
| 128 | 0 |  |  |  |  |  | for my $m ( qw( clean malware ) ) { | 
| 129 | 0 |  | 0 |  |  |  | $pub->{'last_' . $m } = sum ( map { $_->{ $m } || 0 } @$wins ) || 0; | 
| 130 |  |  |  |  |  |  | } | 
| 131 |  |  |  |  |  |  | } | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | sub stats_zone { | 
| 135 | 0 |  |  | 0 | 1 |  | my ($self,$zone,$pub,$prv,$wins) = @_; | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | # required keys defaults | 
| 138 | 0 |  |  |  |  |  | my %out = ( clean => 0, malware => 0 ); | 
| 139 |  |  |  |  |  |  |  | 
| 140 |  |  |  |  |  |  | # copy values as is | 
| 141 | 0 |  |  |  |  |  | $out{$_} += $pub->{$_} for keys %$pub; | 
| 142 |  |  |  |  |  |  |  | 
| 143 | 0 |  |  |  |  |  | map { $_.': '.$out{$_} } sort keys %out; | 
|  | 0 |  |  |  |  |  |  | 
| 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 |  |  |  |  |  |  | 1; | 
| 163 |  |  |  |  |  |  |  |