SpamDetector/SpamAssassin.pm untested

filter: Statementstmt 0.0% 0 / 38 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 69 CC 6 SCAR 24.7
CC
6
Cov
0%
parse_logs
30.0
preconfig
6.0
config_prefix
2.0
CRAP 11.9
1  
2 package SyslogScan::Daemon::SpamDetector::SpamAssassin;
3  
4 use strict;
5 use warnings;
6 use SyslogScan::Daemon::SpamDetector::Plugin;
7 use Plugins::SimpleConfig;
8 our(@ISA) = qw(SyslogScan::Daemon::SpamDetector::Plugin);
9  
10 my %defaults = (
11 rx_extra => '.',
12 rx_month => '(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)',
13 rx_date => '',
14 logfile => '/var/log/syslog',
15 debug => 0,
16 );
17  
18 sub config_prefix { 'sdspamassassin_' }
19  
20 sub parse_config_line { simple_config_line(\%defaults, @_); }
21  
22 sub new { simple_new(\%defaults, @_); }
23  
24 our $Mon;
25 our $Date;
26 our $iprx;
27  
28 sub preconfig
29 {
30 my $self = shift;
31 $self->{Mon} = qr/$self->{rx_month}/;
32 $self->{Date} = $self->{rx_date} ? qr/$self->{rx_date}/ : qr/$self->{Mon} [ 1-3][0-9] \d\d:\d\d:\d\d/;
33 $self->{Extra} = qr/$self->{rx_extra}/;
34 }
35  
36 sub get_logs
37 {
38 my $self = shift;
39 my $Date = $self->{Date};
40 return (
41 $self->{logfile} => [
42 # Oct 24 06:53:43 eatspam1.idiom.com spamd[301]: spamd: result: Y 22 - DATE_IN_FUTURE_96_XX,DIGEST_MULTIPLE,DNS_FROM_RFC_ABUSE,DNS_FROM_RFC_POST,HELO_DYNAMIC_HOME_NL,PYZOR_CHECK,RAZOR2_CF_RANGE_51_100,RAZOR2_CF_RANGE_E8_51_100,RAZOR2_CHECK,RCVD_IN_NJABL_DUL,RCVD_IN_SORBS_DUL,URIBL_JP_SURBL,URIBL_SBL,URIBL_SC_SURBL scantime=5.7,size=1565,user=3djodel@mindsync.com,uid=103,required_score=5.0,rhost=internetmailservice.net,raddr=216.240.47.49,rport=55299,mid=<01c6f773$cf7e04c0$6c822ecf@delvynn>,autolearn=disabled
43 # Oct 24 06:53:38 outbound1.internet-mail-service.net spamd[410]: spamd: result: . 4 - MIME_BASE64_TEXT scantime=10.7,size=1085,user=ediekuik@mindsync.com,uid=110,required_score=5.0,rhost=internetmailservice.net,raddr=216.240.47.49,rport=56012,mid=<6B82E08B.734B402@yahoo.fr>,autolearn=disabled
44 qr{^$Date \S+ spamd\[\d+\]: spamd: result: (\.|Y) ([\d\.]+) .*?mid=<(.*?)>},
45 ],
46 );
47 }
48  
49 sub parse_logs
50 {
51 my ($self, $logfile, $rx) = @_;
52 my $debug = $self->{debug};
53 my $logline = $_;
54 my ($spammy, $score, $id) = ($1, $2, $3);
55 return () if $self->{Extra} && ! /$self->{Extra}/;
56 if ($spammy eq 'Y') {
57 print "SPAMDETECT SPAM $id\n" if $self->{debug};
58 return (
59 status => 'spam',
60 id => $id,
61 logline => $_,
62 match => 'SpamAssassin',
63 score => $score,
64 );
65 } else {
66 print "SPAMDETECT HAM $id\n" if $self->{debug};
67 return (
68 status => 'ham',
69 id => $id,
70 logline => $_,
71 match => 'SpamAssassin',
72 score => $score,
73 );
74 }
75 }
76  
77 1;
78  
79 =head1 NAME
80  
81 SyslogScan::Daemon::SpamDetector::SpamAssassin - notice messages deemed spam by SpamAsssassin
82  
83 =head1 SYNOPSIS
84  
85 plugin SyslogScan::Daemon::SpamDetector as sd_
86  
87 sd_plugin SyslogScan::Daemon::SpamDetector::SpamAssassin
88 debug 0
89 logfile /var/log/mail.info
90  
91 =head1 DESCRIPTION
92  
93 Watch the system log files for output from spamd.
94  
95 Please note that legitimate mail servers send mail that will be
96 caught by spamassassin. The primary reason for this is forwarded
97 mail. One way to work around this problem is to use the
98 L<SyslogScan::Daemon::SpamDetector::Filter> module to only record
99 information from hosts with suspicious hostnames.
100  
101 =head1 CONFIGURATION PARAMETERS
102  
103 The following configuration parameters are supported:
104  
105 =over 4
106  
107 =item debug
108  
109 Debugging on (1) or off (0).
110  
111 =item logfile
112  
113 Which logfile to watch (default: C</var/log/syslog>).
114  
115 =back
116  
117 =head1 SEE ALSO
118  
119 L<SyslogScan::Daemon::SpamDetector>
120  
121 =head1 THANK THE AUTHOR
122  
123 If you need high-speed internet services (T1, T3, OC3 etc), please
124 send me your request-for-quote. I have access to very good pricing:
125 you'll save money and get a great service.
126  
127 =head1 LICENSE
128  
129 Copyright(C) 2006 David Muir Sharnoff <muir@idiom.com>.
130 This module may be used and distributed on the same terms
131 as Perl itself.
132